Artifact Content
Not logged in

Artifact 5157fbd0866d284ead02a7e745c0e87c41ca37ec


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

unsigned MODVAL = 1000000007;
struct mint
{
	unsigned val;
	mint():val(0){}
	mint(int      x):val(x%MODVAL) {}
	mint(unsigned x):val(x%MODVAL) {}
	mint(LL       x):val(x%MODVAL) {}
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint operator+(mint x, mint y) { return x+=y; }
mint operator-(mint x, mint y) { return x-=y; }
mint operator*(mint x, mint y) { return x*=y; }

class PatternLock { public:
	int solve(int N, int MOD)
	{
		MODVAL = MOD;
		memo.resize(N+1, vector<int>(N+1, -1));
		return (rec(N,N)*2) % MOD;
	}

	vector<vector<int>> memo;
	int rec(int A, int B)
	{
		if(memo[A][B] != -1)
			return memo[A][B];
		mint total;
		for(int a=0; a<A; ++a)
			total += rec(A, B, a);
		return memo[A][B] = total.val;
	}
	int rec(int A, int B, int a)
	{
		if(A==1 && B==0)
			return 1;

		mint total;
		if(B) total += rec(B, A-1);
		if(a>0) total += rec(A-1, B, a-1);
		if(a!=A-1) total += rec(A-1, B, a);
		return total.val;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, PatternLock().solve(N, MOD));}
int main(){
/*
CASE(0)
	int N = 1; 
	int MOD = 12345667; 
	int _ = 2; 
END
*/
CASE(1)
	int N = 2; 
	int MOD = 324124124; 
	int _ = 24; 
END
CASE(2)
	int N = 3; 
	int MOD = 5325352; 
	int _ = 504; 
END
CASE(3)
	int N = 500; 
	int MOD = 1000000007; 
	int _ = 286169049; 
END
/*
CASE(4)
	int N = ; 
	int MOD = ; 
	int _ = ; 
END
CASE(5)
	int N = ; 
	int MOD = ; 
	int _ = ; 
END
*/
}
// END CUT HERE