Artifact Content
Not logged in

Artifact 2ee42b04a811c9f231725b3698b621034cfa42de


#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;

static const 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 ShortBugPaths { public:
	int count(int N, vector <int> D, int J)
	{
		if (N <= 200) {
			vector<vector<int>> c(N, vector<int>(N, 1));
			vector<vector<int>> c2(N, vector<int>(N, 1));
			for (int _ = 0; _ < J; ++_) {
				for (int y = 0; y < N; ++y)
				for (int x = 0; x < N; ++x) {
					LL sum = 0;
					for (int DD : D) {
						int yy = y - DD, xx = x;
						for (int d = 0; d < DD; ++d) {
							if (0 <= yy&&yy<N && 0 <= xx&&xx<N) sum += c[yy][xx];
							yy++, xx++;
						}
						for (int d = 0; d < DD; ++d) {
							if (0 <= yy&&yy<N && 0 <= xx&&xx<N) sum += c[yy][xx];
							yy++, xx--;
						}
						for (int d = 0; d < DD; ++d) {
							if (0 <= yy&&yy<N && 0 <= xx&&xx<N) sum += c[yy][xx];
							yy--, xx--;
						}
						for (int d = 0; d < DD; ++d) {
							if (0 <= yy&&yy<N && 0 <= xx&&xx<N) sum += c[yy][xx];
							yy--, xx++;
						}
						if (DD == 0)
							sum += c[y][x];
					}
					c2[y][x] = sum % MODVAL;
				}
				c.swap(c2);
			}
			mint ans = 0;
			for (int y = 0; y < N; ++y)
				for (int x = 0; x < N; ++x)
					ans += c[y][x];
			return ans.val;
		}
		else {
			vector<vector<int>> c(201, vector<int>(201, 1));
			vector<vector<int>> c2(201, vector<int>(201, 1));
			for (int _ = 0; _ < J; ++_) {
				for (int y = 0; y < 101; ++y)
					for (int x = 0; x < 101; ++x) {
						LL sum = 0;
						for (int DD : D) {
							int yy = y - DD, xx = x;

							if (y == 100 && x == 100) {
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[100][100];
									yy++, xx++;
								}
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[100][100];
									yy++, xx--;
								}
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[100][100];
									yy--, xx--;
								}
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[100][100];
									yy--, xx++;
								}
							}
							else if (y == 100) {
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[100][min(100,xx)];
									yy++, xx++;
								}
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[100][min(100, xx)];
									yy++, xx--;
								}
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[100][min(100, xx)];
									yy--, xx--;
								}
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[100][min(100, xx)];
									yy--, xx++;
								}
							}
							else if (x == 100) {
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[min(100, yy)][100];
									yy++, xx++;
								}
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[min(100, yy)][100];
									yy++, xx--;
								}
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[min(100, yy)][100];
									yy--, xx--;
								}
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[min(100, yy)][100];
									yy--, xx++;
								}
							}
							else {
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[min(100, yy)][min(100, xx)];
									yy++, xx++;
								}
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[min(100, yy)][min(100, xx)];
									yy++, xx--;
								}
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[min(100, yy)][min(100, xx)];
									yy--, xx--;
								}
								for (int d = 0; d < DD; ++d) {
									if (0 <= yy&&yy < N && 0 <= xx&&xx < N) sum += c[min(100, yy)][min(100, xx)];
									yy--, xx++;
								}
							}

							if (DD == 0)
								sum += c[y][x];
						}
						c2[y][x] = sum % MODVAL;
					}
				for (int y = 0; y < 201; ++y)
					for (int x = 0; x < 201; ++x)
						c2[y][x] = c2[y>100 ? 200-y : y][x>100 ? 200-x : x];
				c.swap(c2);
			}
			mint ans = 0;
			for (int y = 0; y < 201; ++y)
				for (int x = 0; x < 201; ++x)
					if (y == 100 && x == 100)
						ans += mint(c[y][x]) * (N - 200) * (N - 200);
					else if (y == 100 || x == 100)
						ans += mint(c[y][x]) * (N - 200);
					else
						ans += c[y][x];
			return ans.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(_, ShortBugPaths().count(N, D, J));}
int main(){

CASE(0)
	int N = 3; 
	int D_[] = {1};
	  vector <int> D(D_, D_+sizeof(D_)/sizeof(*D_)); 
	int J = 1; 
	int _ = 24; 
END
CASE(1)
	int N = 123456789; 
	int D_[] = {0};
	  vector <int> D(D_, D_+sizeof(D_)/sizeof(*D_)); 
	int J = 3; 
	int _ = 643499475; 
END
CASE(2)
	int N = 5; 
	int D_[] = {0, 10, 2};
	  vector <int> D(D_, D_+sizeof(D_)/sizeof(*D_)); 
	int J = 4; 
	int _ = 38281; 
END
CASE(3)
	int N = 1000; 
	int D_[] = {0,1};
	  vector <int> D(D_, D_+sizeof(D_)/sizeof(*D_)); 
	int J = 1; 
	int _ = 4996000; 
END
CASE(4)
	int N = 47; 
	int D_[] = {3};
	  vector <int> D(D_, D_+sizeof(D_)/sizeof(*D_)); 
	int J = 6; 
	int _ = 195354165; 
END
CASE(5)
	int N = 200; 
	int D_[] = { 0,1,2,3,4,5,6,7,8,9,10 };
	  vector <int> D(D_, D_+sizeof(D_)/sizeof(*D_)); 
	int J = 10; 
	int _ = 316860289;
END
CASE(6)
	int N = 1000000000; 
	int D_[] = { 0,1,2,3,4,5,6,7,8,9,10 };
	vector <int> D(D_, D_+sizeof(D_)/sizeof(*D_));
	int J = 10;
	int _ = -100;
END
}
// END CUT HERE