QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#662803#6637. Perfect StringshuaxiamengjinTL 1499ms5724kbC++14826b2024-10-21 10:39:342024-10-21 10:39:37

Judging History

你现在查看的是最新测评结果

  • [2024-10-21 10:39:37]
  • 评测
  • 测评结果:TL
  • 用时:1499ms
  • 内存:5724kb
  • [2024-10-21 10:39:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int NN=1e9+7;
int n,c,f[100100];
int p[100100],ni[100100];
int cc(int x){
    return p[2*x]*ni[x+1]%NN*ni[x]%NN;
}
int mi(int x,int y){
    int sum=1;
    for (;y;y>>=1,x=x*x%NN)
    if(y&1)sum=sum*x%NN;
    return sum;
}
int pp[100100];
void solve(){
    cin>>n>>c;//n*=2;
    p[0]=1;
    for (int i=1;i<=2*n;i++)
    p[i]=p[i-1]*i%NN;
    ni[2*n]=mi(p[2*n],NN-2);
    for (int i=2*n;i;i--)
    ni[i-1]=ni[i]*i%NN;
    f[0]=1;
    pp[0]=1;
    for (int i=1;i<=n;i++)
    pp[i]=pp[i-1]*(c-1)%NN;
    for (int i=1;i<=n;i++){
        f[i]=0;
        for (int j=0;j<i;j++)
        f[i]=(f[i]+f[j]*cc(i-j-1)%NN*pp[i-j-1]%NN*c)%NN;
    }
    cout<<f[n]<<"\n";
}
signed main(){
    int T;cin>>T;
    while(T--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5708kb

input:

2
3 1
2 2

output:

1
6

result:

ok 2 number(s): "1 6"

Test #2:

score: 0
Accepted
time: 75ms
memory: 5724kb

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: 1499ms
memory: 3756kb

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
Time Limit Exceeded

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...

output:

461108227
93969714
967535558
286996770
439955818
513651814
367718117
70089455
537505709
989455211
600861203
892954232
899899624
825588888
536671357
118059202
325888233
146830823
953101687
974677182
364272875
482192182
565890497
657497852
297995102
797194699
322320804
744121644
399550079
576261681
42...

result: