# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
987509 | 2024-05-22T22:33:00 Z | activedeltorre | Semafor (COI20_semafor) | C++14 | 666 ms | 1364 KB |
#include <iostream> using namespace std; long long nr1[2300]; long long nr2[2300]; long long biti=5; long long nmax=9; long long cif(long long val) { if(val==1) { return 1; } else if(val==2) { return 6; } else if(val==3) { return 21; } else if(val==4) { return 9; } else if(val==5) { return 28; } else if(val==6) { return 18; } else if(val==7) { return 5; } else if(val==8) { return 30; } else if(val==9) { return 29; } else return 3; } long long getid(long long val) { if(biti==5) return cif(val/10)*0+cif(val%10); else return cif(val/10)*32+cif(val%10); } long long mod=1e9+7; struct kuk { long long mat[105][105]; }m1,m2,m3; kuk mini; kuk mini2; kuk base1,base2; kuk rasp; void multi(kuk a,kuk b) { long long i,z,j; for(i=0;i<=nmax;i++) { for(j=0;j<=nmax;j++) { rasp.mat[i][j]=0; } } for(i=0;i<=nmax;i++) { for(j=0;j<=nmax;j++) { for(z=0;z<=nmax;z++) { rasp.mat[i][j]+=(a.mat[i][z]*b.mat[z][j])%mod; } } } for(i=0;i<=nmax;i++) { for(j=0;j<=nmax;j++) { rasp.mat[i][j]%=mod; } } } long long invs(long long a,long long exp) { long long prod=1; while(exp) { if(exp%2==1) { prod=(prod*a)%mod; } exp=exp/2; a=(a*a)%mod; } return prod; } long long differ(long long a,long long b) { return __builtin_popcount(getid(a)^getid(b)); } long long invsc[25][25]; void precalc() { long long i,j,z; for(i=1;i<=20;i++) { for(j=0;j<=i;j++) { long long prod=1; for(z=1;z<=i;z++) { prod=(prod*invs(z,mod-2))%mod; } for(z=1;z<=j;z++) { prod=(prod*z)%mod; } for(z=1;z<=i-j;z++) { prod=(prod*z)%mod; } invsc[i][j]=prod; } } } long long anticomb(long long x) { return invsc[biti][x]; } kuk base; kuk afis; kuk bigmat; kuk bigmat2; void calcbigger() { for(long long i=0;i<=nmax;i++) { for(long long j=0;j<=nmax;j++) { bigmat.mat[i][j]=(base.mat[0][differ(i,j)]*anticomb(differ(j,i))%mod); } } } signed main() { long long n,i,j,k,l,m,st,val,z; cin>>m>>n>>k>>st; if(m==2) { nmax=99; biti=10; } else { nmax=9; biti=5; } precalc(); val=getid(st); nr1[val]=1; base.mat[0][0]=1; base2.mat[0][0]=1; for(i=0;i<=biti;i++) { if(i<biti) mini.mat[i][i+1]=(biti-i); if(i>=1) mini.mat[i][i-1]=i; } mini2=mini; long long k2=k; while(k) { if(k%2==1) { multi(base,mini); base=rasp; } multi(mini,mini); mini=rasp; k=k/2; } long long operbig=n/k2; long long opersmall=n%k2; while(opersmall) { if(opersmall%2==1) { multi(base2,mini2); base2=rasp; } multi(mini2,mini2); mini2=rasp; opersmall=opersmall/2; } for(i=0;i<=nmax;i++) { for(j=0;j<=nmax;j++) { bigmat2.mat[i][j]=(base2.mat[0][differ(i,j)]*anticomb(differ(i,j))%mod); } } afis.mat[st][st]=1; calcbigger(); while(operbig) { if(operbig%2==1) { multi(afis,bigmat); afis=rasp; } operbig=operbig/2; multi(bigmat,bigmat); bigmat=rasp; } multi(afis,bigmat2); afis=rasp; for(i=0;i<=nmax;i++) { cout<<afis.mat[st][i]<<'\n'; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 856 KB | Output is correct |
2 | Correct | 3 ms | 860 KB | Output is correct |
3 | Correct | 2 ms | 956 KB | Output is correct |
4 | Correct | 2 ms | 860 KB | Output is correct |
5 | Correct | 2 ms | 1112 KB | Output is correct |
6 | Correct | 2 ms | 860 KB | Output is correct |
7 | Correct | 2 ms | 1116 KB | Output is correct |
8 | Correct | 3 ms | 860 KB | Output is correct |
9 | Correct | 3 ms | 1116 KB | Output is correct |
10 | Correct | 2 ms | 856 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 856 KB | Output is correct |
2 | Correct | 3 ms | 860 KB | Output is correct |
3 | Correct | 2 ms | 956 KB | Output is correct |
4 | Correct | 2 ms | 860 KB | Output is correct |
5 | Correct | 2 ms | 1112 KB | Output is correct |
6 | Correct | 2 ms | 860 KB | Output is correct |
7 | Correct | 2 ms | 1116 KB | Output is correct |
8 | Correct | 3 ms | 860 KB | Output is correct |
9 | Correct | 3 ms | 1116 KB | Output is correct |
10 | Correct | 2 ms | 856 KB | Output is correct |
11 | Correct | 3 ms | 1112 KB | Output is correct |
12 | Correct | 3 ms | 1116 KB | Output is correct |
13 | Correct | 3 ms | 1116 KB | Output is correct |
14 | Correct | 4 ms | 1116 KB | Output is correct |
15 | Correct | 5 ms | 1116 KB | Output is correct |
16 | Correct | 4 ms | 1116 KB | Output is correct |
17 | Correct | 4 ms | 1112 KB | Output is correct |
18 | Correct | 3 ms | 860 KB | Output is correct |
19 | Correct | 3 ms | 1116 KB | Output is correct |
20 | Correct | 4 ms | 1116 KB | Output is correct |
21 | Correct | 3 ms | 1116 KB | Output is correct |
22 | Correct | 3 ms | 856 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 1108 KB | Output is correct |
2 | Correct | 60 ms | 964 KB | Output is correct |
3 | Correct | 86 ms | 960 KB | Output is correct |
4 | Correct | 90 ms | 1108 KB | Output is correct |
5 | Correct | 81 ms | 1204 KB | Output is correct |
6 | Correct | 95 ms | 960 KB | Output is correct |
7 | Correct | 96 ms | 1208 KB | Output is correct |
8 | Correct | 95 ms | 1200 KB | Output is correct |
9 | Correct | 81 ms | 1108 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 122 ms | 1360 KB | Output is correct |
2 | Correct | 210 ms | 1112 KB | Output is correct |
3 | Correct | 325 ms | 1284 KB | Output is correct |
4 | Correct | 441 ms | 1204 KB | Output is correct |
5 | Correct | 384 ms | 1280 KB | Output is correct |
6 | Correct | 412 ms | 1284 KB | Output is correct |
7 | Correct | 418 ms | 1284 KB | Output is correct |
8 | Correct | 331 ms | 1124 KB | Output is correct |
9 | Correct | 331 ms | 1136 KB | Output is correct |
10 | Correct | 414 ms | 1104 KB | Output is correct |
11 | Correct | 50 ms | 1112 KB | Output is correct |
12 | Correct | 28 ms | 1116 KB | Output is correct |
13 | Correct | 399 ms | 1288 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 122 ms | 1360 KB | Output is correct |
2 | Correct | 210 ms | 1112 KB | Output is correct |
3 | Correct | 325 ms | 1284 KB | Output is correct |
4 | Correct | 441 ms | 1204 KB | Output is correct |
5 | Correct | 384 ms | 1280 KB | Output is correct |
6 | Correct | 412 ms | 1284 KB | Output is correct |
7 | Correct | 418 ms | 1284 KB | Output is correct |
8 | Correct | 331 ms | 1124 KB | Output is correct |
9 | Correct | 331 ms | 1136 KB | Output is correct |
10 | Correct | 414 ms | 1104 KB | Output is correct |
11 | Correct | 50 ms | 1112 KB | Output is correct |
12 | Correct | 28 ms | 1116 KB | Output is correct |
13 | Correct | 399 ms | 1288 KB | Output is correct |
14 | Correct | 150 ms | 1208 KB | Output is correct |
15 | Correct | 285 ms | 1208 KB | Output is correct |
16 | Correct | 365 ms | 1284 KB | Output is correct |
17 | Correct | 420 ms | 1092 KB | Output is correct |
18 | Correct | 443 ms | 1200 KB | Output is correct |
19 | Correct | 409 ms | 1280 KB | Output is correct |
20 | Correct | 440 ms | 1288 KB | Output is correct |
21 | Correct | 332 ms | 1360 KB | Output is correct |
22 | Correct | 414 ms | 1284 KB | Output is correct |
23 | Correct | 428 ms | 1288 KB | Output is correct |
24 | Correct | 449 ms | 1108 KB | Output is correct |
25 | Correct | 454 ms | 1284 KB | Output is correct |
26 | Correct | 50 ms | 1104 KB | Output is correct |
27 | Correct | 76 ms | 1216 KB | Output is correct |
28 | Correct | 370 ms | 1276 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 1108 KB | Output is correct |
2 | Correct | 60 ms | 964 KB | Output is correct |
3 | Correct | 86 ms | 960 KB | Output is correct |
4 | Correct | 90 ms | 1108 KB | Output is correct |
5 | Correct | 81 ms | 1204 KB | Output is correct |
6 | Correct | 95 ms | 960 KB | Output is correct |
7 | Correct | 96 ms | 1208 KB | Output is correct |
8 | Correct | 95 ms | 1200 KB | Output is correct |
9 | Correct | 81 ms | 1108 KB | Output is correct |
10 | Correct | 122 ms | 1360 KB | Output is correct |
11 | Correct | 210 ms | 1112 KB | Output is correct |
12 | Correct | 325 ms | 1284 KB | Output is correct |
13 | Correct | 441 ms | 1204 KB | Output is correct |
14 | Correct | 384 ms | 1280 KB | Output is correct |
15 | Correct | 412 ms | 1284 KB | Output is correct |
16 | Correct | 418 ms | 1284 KB | Output is correct |
17 | Correct | 331 ms | 1124 KB | Output is correct |
18 | Correct | 331 ms | 1136 KB | Output is correct |
19 | Correct | 414 ms | 1104 KB | Output is correct |
20 | Correct | 50 ms | 1112 KB | Output is correct |
21 | Correct | 28 ms | 1116 KB | Output is correct |
22 | Correct | 399 ms | 1288 KB | Output is correct |
23 | Correct | 150 ms | 1208 KB | Output is correct |
24 | Correct | 285 ms | 1208 KB | Output is correct |
25 | Correct | 365 ms | 1284 KB | Output is correct |
26 | Correct | 420 ms | 1092 KB | Output is correct |
27 | Correct | 443 ms | 1200 KB | Output is correct |
28 | Correct | 409 ms | 1280 KB | Output is correct |
29 | Correct | 440 ms | 1288 KB | Output is correct |
30 | Correct | 332 ms | 1360 KB | Output is correct |
31 | Correct | 414 ms | 1284 KB | Output is correct |
32 | Correct | 428 ms | 1288 KB | Output is correct |
33 | Correct | 449 ms | 1108 KB | Output is correct |
34 | Correct | 454 ms | 1284 KB | Output is correct |
35 | Correct | 50 ms | 1104 KB | Output is correct |
36 | Correct | 76 ms | 1216 KB | Output is correct |
37 | Correct | 370 ms | 1276 KB | Output is correct |
38 | Correct | 173 ms | 1292 KB | Output is correct |
39 | Correct | 358 ms | 1284 KB | Output is correct |
40 | Correct | 480 ms | 1200 KB | Output is correct |
41 | Correct | 654 ms | 1288 KB | Output is correct |
42 | Correct | 604 ms | 1288 KB | Output is correct |
43 | Correct | 666 ms | 1364 KB | Output is correct |
44 | Correct | 652 ms | 1292 KB | Output is correct |
45 | Correct | 331 ms | 1204 KB | Output is correct |
46 | Correct | 371 ms | 1200 KB | Output is correct |
47 | Correct | 639 ms | 1200 KB | Output is correct |
48 | Correct | 398 ms | 1208 KB | Output is correct |
49 | Correct | 323 ms | 1204 KB | Output is correct |
50 | Correct | 42 ms | 1104 KB | Output is correct |
51 | Correct | 96 ms | 1220 KB | Output is correct |
52 | Correct | 607 ms | 1284 KB | Output is correct |