結果

問題 No.621 3 x N グリッド上のドミノの置き方の数
ユーザー 👑 kmjpkmjp
提出日時 2017-12-21 00:15:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 41 ms / 3,000 ms
コード長 2,355 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 162,736 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-09 16:47:31
合計ジャッジ時間 4,723 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 8 ms
5,376 KB
testcase_15 AC 10 ms
5,376 KB
testcase_16 AC 12 ms
5,376 KB
testcase_17 AC 12 ms
5,376 KB
testcase_18 AC 15 ms
5,376 KB
testcase_19 AC 16 ms
5,376 KB
testcase_20 AC 17 ms
5,376 KB
testcase_21 AC 17 ms
5,376 KB
testcase_22 AC 20 ms
5,376 KB
testcase_23 AC 22 ms
5,376 KB
testcase_24 AC 23 ms
5,376 KB
testcase_25 AC 26 ms
5,376 KB
testcase_26 AC 25 ms
5,376 KB
testcase_27 AC 29 ms
5,376 KB
testcase_28 AC 30 ms
5,376 KB
testcase_29 AC 32 ms
5,376 KB
testcase_30 AC 31 ms
5,376 KB
testcase_31 AC 29 ms
5,376 KB
testcase_32 AC 26 ms
5,376 KB
testcase_33 AC 31 ms
5,376 KB
testcase_34 AC 30 ms
5,376 KB
testcase_35 AC 29 ms
5,376 KB
testcase_36 AC 29 ms
5,376 KB
testcase_37 AC 31 ms
5,376 KB
testcase_38 AC 32 ms
5,376 KB
testcase_39 AC 33 ms
5,376 KB
testcase_40 AC 33 ms
5,376 KB
testcase_41 AC 35 ms
5,376 KB
testcase_42 AC 32 ms
5,376 KB
testcase_43 AC 32 ms
5,376 KB
testcase_44 AC 31 ms
5,376 KB
testcase_45 AC 32 ms
5,376 KB
testcase_46 AC 33 ms
5,376 KB
testcase_47 AC 33 ms
5,376 KB
testcase_48 AC 32 ms
5,376 KB
testcase_49 AC 34 ms
5,376 KB
testcase_50 AC 33 ms
5,376 KB
testcase_51 AC 33 ms
5,376 KB
testcase_52 AC 34 ms
5,376 KB
testcase_53 AC 34 ms
5,376 KB
testcase_54 AC 34 ms
5,376 KB
testcase_55 AC 33 ms
5,376 KB
testcase_56 AC 35 ms
5,376 KB
testcase_57 AC 35 ms
5,376 KB
testcase_58 AC 29 ms
5,376 KB
testcase_59 AC 40 ms
5,376 KB
testcase_60 AC 40 ms
5,376 KB
testcase_61 AC 40 ms
5,376 KB
testcase_62 AC 41 ms
5,376 KB
testcase_63 AC 22 ms
5,376 KB
testcase_64 AC 23 ms
5,376 KB
testcase_65 AC 22 ms
5,376 KB
testcase_66 AC 23 ms
5,376 KB
testcase_67 AC 21 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll mo=1000000007;

const int MAT=64;
struct Mat { ll v[MAT][MAT]; };
Mat mulmat(Mat& a,Mat& b,int n=MAT) {
	ll mo2=4*mo*mo;
	int x,y,z; Mat r;
	FOR(x,n) FOR(y,n) r.v[x][y]=0;
	FOR(x,n) FOR(z,n) FOR(y,n) {
		r.v[x][y] += a.v[x][z]*b.v[z][y];
		if(r.v[x][y]>mo2) r.v[x][y] -= mo2;
	}
	FOR(x,n) FOR(y,n) r.v[x][y]%=mo;
	return r;
}

Mat powmat(ll p,Mat a,int n=MAT) {
	int i,x,y; Mat r;
	FOR(x,n) FOR(y,n) r.v[x][y]=0;
	FOR(i,n) r.v[i][i]=1;
	while(p) {
		if(p%2) r=mulmat(r,a,n);
		a=mulmat(a,a,n);
		p>>=1;
	}
	return r;
}

ll modpow(ll a, ll n = mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

ll N;
Mat A,B;

void dfs(int id,int cmask,int row) {
	if(row==0) {
		if((cmask&((1<<3)|(1<<6)))==0) dfs(id,cmask|(1<<3)|(1<<6),1);
		dfs(id,cmask|(1<<6)|(1<<7),2);
		dfs(id,cmask,1);
	}
	if(row==1) {
		if((cmask&((1<<4)|(1<<7)))==0) dfs(id,cmask|(1<<4)|(1<<7),2);
		dfs(id,cmask|(1<<7)|(1<<8),3);
		dfs(id,cmask,2);
	}
	if(row==2) {
		if((cmask&((1<<5)|(1<<8)))==0) dfs(id,cmask|(1<<5)|(1<<8),3);
		dfs(id,cmask,3);
	}
	if(row==3) {
		if((cmask&9)==0) return;
		if((cmask&18)==0) return;
		if((cmask&36)==0) return;
		if((cmask&24)==0) return;
		if((cmask&48)==0) return;
		A.v[cmask>>3][id]++;
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	
	FOR(i,64) {
		if((i&3)==0) continue;
		if((i&6)==0) continue;
		dfs(i,i,0);
		//FOR(j,64) cout<<A.v[i][j]<<" ";
		//cout<<endl;
	}
	B=powmat(N,A);
	ll ret=0;
	FOR(i,64) {
		if((i&3)==0) continue;
		if((i&6)==0) continue;
		if((i&24)==0) continue;
		if((i&48)==0) continue;
		if((i&9)==0) continue;
		if((i&18)==0) continue;
		if((i&36)==0) continue;
		ret+=B.v[i][63];
	}
	cout<<ret%mo<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0