QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217424 | #6637. Perfect Strings | EastKing | RE | 1840ms | 3912kb | C++17 | 640b | 2023-10-16 20:54:27 | 2023-10-16 20:54:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int M=1e3+5,P=1e9+7;
int dp[2][M];
int main(){
int cas;
scanf("%d",&cas);
while(cas--){
int n,c;
scanf("%d %d",&n,&c);
int cur=0;
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=1;i<=2*n;i++){
int pre=cur;
cur^=1;
for(int j=0;j<=i;j++){
dp[cur][j]=0;
dp[cur][j]=(dp[cur][j]+dp[pre][j+1])%P;
if(j>0){
if(j>1)dp[cur][j]=(dp[cur][j]+1ll*dp[pre][j-1]*(c-1))%P;
else dp[cur][j]=(dp[cur][j]+1ll*dp[pre][j-1]*c)%P;
}
//printf("dp[%d][%d]=%d\n",i,j,dp[cur][j]);
}
}
printf("%d\n",dp[cur][0]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
input:
2 3 1 2 2
output:
1 6
result:
ok 2 number(s): "1 6"
Test #2:
score: 0
Accepted
time: 25ms
memory: 3912kb
input:
100000 1 1 4 1 5 5 3 5 1 2 5 3 1 1 3 3 5 2 2 1 4 1 5 5 2 3 4 1 3 3 2 5 3 2 4 3 4 4 3 5 3 1 5 2 2 2 4 2 5 4 1 2 3 1 4 5 2 5 5 3 1 5 5 2 3 2 5 2 4 1 1 3 3 2 4 5 2 1 4 1 2 2 1 1 3 5 4 5 2 3 3 5 2 5 2 4 5 4 2 3 1 1 2 1 4 4 1 5 5 4 1 3 5 4 4 5 1 3 1 1 3 3 2 4 2 4 2 1 5 5 1 3 2 3 4 1 4 3 2 4 2 4 4 2 1 1 1...
output:
1 1 71445 485 2 3543 1 87 252 1 1 71445 15 1 87 45 20 543 2092 485 1 252 6 70 19864 2 1 5725 45 3543 5 252 20 252 1 3 20 5725 1 1 6 1 485 5725 15 485 45 28 19864 15 1 1 2092 5 19864 3 19864 5725 3 1 87 28 28 1 71445 3 15 1 543 28 28 70 1 1 71445 15 2092 3 1 2 15 87 2092 19864 71445 6 252 2092 252 15...
result:
ok 100000 numbers
Test #3:
score: 0
Accepted
time: 1840ms
memory: 3904kb
input:
100000 94 7867320 84 1294950 35 8570570 72 7050952 23 3907221 95 7482398 58 2363048 44 2234552 50 8809524 37 1061961 19 884367 38 3261675 59 1563189 61 7603994 83 3131714 19 6207284 64 5662457 2 6845951 84 4688192 13 7552675 38 3119650 84 6311084 10 5040332 53 5981961 46 7308176 43 679952 30 2922213...
output:
89775996 781446171 477730749 425095995 683480274 139962614 676040688 83128356 609223622 595772607 273248526 319532567 917638183 692265001 864029162 41269371 365591107 82686713 397805948 799200818 123574040 576607518 6430981 978266206 446712393 201799413 709622262 325465125 319418065 850111422 513285...
result:
ok 100000 numbers
Test #4:
score: -100
Runtime Error
input:
18170 339 1623650 128 3200275 965 1829351 997 1547816 435 9138202 974 1806376 560 1011936 345 3813921 938 2229395 994 2411734 163 6603389 837 1133885 494 1068385 197 9254017 617 9553650 136 5850880 376 8616282 456 5759693 302 515509 293 2633903 703 7929747 205 5091361 303 5968505 740 872272 246 4106...