結果

問題 No.569 3 x N グリッドのパスの数
ユーザー ryoissyryoissy
提出日時 2017-09-08 23:31:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,493 bytes
コンパイル時間 1,309 ms
コンパイル使用メモリ 165,096 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 21:44:02
合計ジャッジ時間 2,893 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 3 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 2 ms
5,376 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 2 ms
5,376 KB
testcase_58 AC 2 ms
5,376 KB
testcase_59 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:64:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   64 |         scanf("%lld",&n);
      |         ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n;
/*
bool flag[5][101];
int cnt=0;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

void dfs(int y,int x){
	if(y==3 && x==n){
		cnt++;
		return;
	}
	flag[y][x]=true;
	for(int i=0;i<4;i++){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(nx>=0 && nx<=n && ny>=0 && ny<=3){
			if(!flag[ny][nx]){
				dfs(ny,nx);
			}
		}
	}
	flag[y][x]=false;
}
*/

typedef vector<ll> vec;
typedef vector<vec> mat;

mat mul(mat &A,mat &B){
	mat C(A.size(),vec(B[0].size()));
	for(int i=0;i<A.size();i++){
		for(int k=0;k<B.size();k++){
			for(int j=0;j<B[0].size();j++){
				C[i][j]=(C[i][j]+(A[i][k]*B[k][j]%MOD)+MOD)%MOD;
			}
		}
	}
	return C;
}

mat pow(mat A,ll n){
	mat B(A.size(),vec(A.size()));
	for(int i=0;i<A.size();i++){
		B[i][i]=1;
	}
	while(n>0){
		if(n&1)B=mul(B,A);
		A=mul(A,A);
		n>>=1;
	}
	return B;
}

ll res[12]={1,8,38,184,976,5382,29739,163496,896476,4913258,26932712,147657866};

int main(void){
	scanf("%lld",&n);
	if(n<=11){
		printf("%lld\n",res[n]);
		return 0;
	}
	mat B(12,vec(12));
	B[0][0]=12;
	B[0][1]=-54;
	B[0][2]=124;
	B[0][3]=-133;
	B[0][4]=-16;
	B[0][5]=175;
	B[0][6]=-94;
	B[0][7]=-69;
	B[0][8]=40;
	B[0][9]=12;
	B[0][10]=-4;
	B[0][11]=-1;
	for(int i=1;i<=11;i++){
		for(int j=0;j<=11;j++){
			B[i][j]=0;
		}
		B[i][i-1]=1;
	}
	B=pow(B,n-11);
	ll ans=0;
	for(int i=0;i<=11;i++){
		ans=(ans+B[0][i]*res[11-i]%MOD+MOD)%MOD;
	}
	printf("%lld\n",ans);
	return 0;
}
0