Submission #71772

#TimeUsernameProblemLanguageResultExecution timeMemory
71772tamref_official_fanclub (#119)Cross on the Grid (FXCUP3_cross)C++17
100 / 100
5 ms656 KiB
#include <stdio.h> const int mod=1e9+7;struct mat{int x[16][16];mat operator*(const mat&p)const{mat ret;for(int i=0;i<16;++i){for(int j=0;j<16;++j){ret.x[i][j]=0;for(int k = 0;k<16;++k){ret.x[i][j]+=(long long)x[i][k]*p.x[k][j]%mod;ret.x[i][j]%=mod;}}}return ret;}}it;const int gox[5]={0,1,0,-1,0};const int goy[5]={0,0,1,0,-1};int collapse(int a,int b,int y){if(a==0||b==0)return 0;for(int i=0;i<5;++i){for(int j=0;j<5;++j){if(a+gox[i]!=b+gox[j])continue;if(goy[i]!=y+goy[j])continue;return 1;}}return 0;}mat pw(mat x,int p){mat ret=it;while(p){if(p&1)ret=ret*x;x=x*x;p>>=1;}return ret;}int main(){int n;scanf("%d",&n);mat x;for(int i=0;i<16;++i){for(int j=0;j<16;++j){x.x[i][j]=0;if((i>>2)==(j&3)){if(collapse(j>>2,i&3,2))continue;if(collapse(j&3,i&3,1))continue;x.x[i][j]=1;}}}for(int i=0;i<16;++i)it.x[i][i]=1;x=pw(x,n-3);int ans=0;for(int i=0;i<16;++i)for(int j=0;j<4;++j)ans=(ans+x.x[i][j])%mod;printf("%d\n",ans);return 0;}

Compilation message (stderr)

cross.cpp: In function 'int main()':
cross.cpp:2:592: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 const int mod=1e9+7;struct mat{int x[16][16];mat operator*(const mat&p)const{mat ret;for(int i=0;i<16;++i){for(int j=0;j<16;++j){ret.x[i][j]=0;for(int k = 0;k<16;++k){ret.x[i][j]+=(long long)x[i][k]*p.x[k][j]%mod;ret.x[i][j]%=mod;}}}return ret;}}it;const int gox[5]={0,1,0,-1,0};const int goy[5]={0,0,1,0,-1};int collapse(int a,int b,int y){if(a==0||b==0)return 0;for(int i=0;i<5;++i){for(int j=0;j<5;++j){if(a+gox[i]!=b+gox[j])continue;if(goy[i]!=y+goy[j])continue;return 1;}}return 0;}mat pw(mat x,int p){mat ret=it;while(p){if(p&1)ret=ret*x;x=x*x;p>>=1;}return ret;}int main(){int n;scanf("%d",&n);mat x;for(int i=0;i<16;++i){for(int j=0;j<16;++j){x.x[i][j]=0;if((i>>2)==(j&3)){if(collapse(j>>2,i&3,2))continue;if(collapse(j&3,i&3,1))continue;x.x[i][j]=1;}}}for(int i=0;i<16;++i)it.x[i][i]=1;x=pw(x,n-3);int ans=0;for(int i=0;i<16;++i)for(int j=0;j<4;++j)ans=(ans+x.x[i][j])%mod;printf("%d\n",ans);return 0;}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...