QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#118485#2603. Disbalancesolemntee#WA 70ms19424kbC++201.3kb2023-07-03 16:35:252023-07-03 16:35:26

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-03 16:35:26]
  • 评测
  • 测评结果:WA
  • 用时:70ms
  • 内存:19424kb
  • [2023-07-03 16:35:25]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const int mod=998244353;
const int N=1000000;
int fac[N+10],rev[N+10];
int powmod(int x,int y){
    int re=1;
    while(y){
        if(y&1) re=1ll*re*x%mod;
        y>>=1;
        x=1ll*x*x%mod;
    }
    return re;
}
int C(int x,int y){
    return 1ll*fac[x]*rev[x-y]%mod*rev[y]%mod;
}
int n,k;
void solve(){
    scanf("%lld%lld",&n,&k);
    ll ans=0;
    if(n==1){
        for(int i=n+1;i<=n+k;i++){
            ans+=i;
        }
        ans=ans%mod;
        printf("%lld\n",ans);
        return ;
    }
    for(int p=2*(n-1);p<=n+k;p++){
        ans=(ans+1ll*(n-1)*fac[p-n]%mod*rev[p-1]%mod*p%mod*fac[n-2]%mod*C((int)(p/2),n-1)%mod)%mod;
        ans=(mod+ans-2ll*(n-1)*fac[p-n]%mod*rev[p-1]%mod*fac[n-1]%mod*C((int)(p/2)+1,n)%mod)%mod;
//        cout<<p<<" "<<ans<<endl;
    }
    printf("%lld\n",ans*n%mod);
}
signed main(){
    fac[0]=1;
    for(int i=1;i<=N;i++){
        fac[i]=1ll*fac[i-1]*i%mod;
    }
    rev[N]=powmod(fac[N],mod-2);
    for(int i=N;i>0;i--){
        rev[i-1]=1ll*rev[i]*i%mod;
    }
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
/*
8
1 1
1 2
2 1
2 2
3 1
3 2
3 3
4 3


666
*/

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 19252kb

input:

8
1 1
1 2
2 1
2 2
3 1
3 2
3 3
4 3

output:

2
5
1
332748120
0
499122177
299473307
598946612

result:

ok 8 numbers

Test #2:

score: 0
Accepted
time: 4ms
memory: 19184kb

input:

20
9 12
2 6
9 14
3 7
1 2
1 2
10 11
6 7
10 13
7 4
1 3
4 4
2 2
1 5
10 9
6 10
7 5
7 4
10 7
4 3

output:

601023541
104577993
588440629
323241035
5
5
537116365
615800088
583321633
0
9
570425345
332748120
20
334869712
974144215
0
0
0
598946612

result:

ok 20 numbers

Test #3:

score: 0
Accepted
time: 7ms
memory: 19136kb

input:

20
7 12
8 12
1 1
1 6
2 11
5 4
6 13
7 13
6 8
1 5
7 13
2 8
3 10
8 9
5 3
1 2
5 6
10 8
4 3
3 3

output:

269558826
522207092
2
27
245743886
926941185
375649298
628061442
401724376
20
628061442
880990276
368615785
683801260
0
5
126761188
0
598946612
299473307

result:

ok 20 numbers

Test #4:

score: 0
Accepted
time: 8ms
memory: 19188kb

input:

20
1 5
2 5
10 12
10 12
3 3
9 11
6 7
1 8
8 8
1 3
9 5
9 9
3 6
2 4
10 13
10 9
3 9
5 7
7 6
6 8

output:

20
532396998
374710197
374710197
299473307
973433586
615800088
44
278918935
9
0
347599278
655989151
532396995
583321633
334869712
867737959
671258108
688183607
401724376

result:

ok 20 numbers

Test #5:

score: 0
Accepted
time: 8ms
memory: 19424kb

input:

20
2 6
8 10
7 4
3 5
9 9
10 6
2 4
9 13
4 3
8 14
10 13
3 11
5 10
2 11
4 9
5 7
6 8
1 6
8 9
6 13

output:

104577993
760178656
0
156866973
347599278
0
532396995
543627802
598946612
180187355
583321633
522191842
831814893
245743886
907494870
671258108
401724376
27
683801260
375649298

result:

ok 20 numbers

Test #6:

score: 0
Accepted
time: 8ms
memory: 19192kb

input:

20
1 2
4 5
5 10
8 11
5 11
8 14
6 9
8 7
4 12
9 9
7 5
7 8
3 6
10 15
1 8
2 4
4 6
3 2
8 6
4 6

output:

5
142606337
831814893
900203882
627046821
180187355
485493133
134960775
7
347599278
0
877826765
655989151
295767061
44
532396995
332748119
499122177
0
332748119

result:

ok 20 numbers

Test #7:

score: 0
Accepted
time: 3ms
memory: 19188kb

input:

20
6 6
2 8
4 10
8 14
9 6
9 6
9 12
3 2
7 6
4 11
7 4
6 5
9 13
4 10
1 9
2 2
7 7
6 10
7 11
6 4

output:

101552997
880990276
691092249
180187355
0
0
601023541
499122177
688183607
614304223
0
308980395
543627802
691092249
54
332748120
661424143
974144215
328279082
0

result:

ok 20 numbers

Test #8:

score: 0
Accepted
time: 8ms
memory: 19180kb

input:

20
4 11
2 11
8 11
7 9
3 3
9 14
4 11
8 14
3 5
1 6
8 12
8 8
3 11
1 5
3 11
3 9
6 4
6 7
6 13
3 9

output:

614304223
245743886
900203882
176961499
299473307
588440629
614304223
180187355
156866973
27
522207092
278918935
522191842
20
522191842
867737959
0
615800088
375649298
867737959

result:

ok 20 numbers

Test #9:

score: 0
Accepted
time: 2ms
memory: 19416kb

input:

20
1 9
5 10
3 10
8 13
4 4
9 9
2 4
7 9
5 12
2 3
4 3
9 7
7 7
1 3
5 8
3 2
9 13
1 1
7 12
6 6

output:

54
831814893
368615785
448034137
570425345
347599278
532396995
176961499
127924645
332748122
598946612
0
661424143
9
489759135
499122177
543627802
2
269558826
101552997

result:

ok 20 numbers

Test #10:

score: 0
Accepted
time: 11ms
memory: 19192kb

input:

20
8 10
3 9
3 7
8 7
2 7
7 7
2 2
7 7
5 3
7 6
9 14
3 2
10 15
5 7
10 10
5 8
5 3
9 14
4 3
10 9

output:

760178656
867737959
323241035
134960775
104577997
661424143
332748120
661424143
0
688183607
588440629
499122177
295767061
671258108
56894028
489759135
0
588440629
598946612
334869712

result:

ok 20 numbers

Test #11:

score: 0
Accepted
time: 11ms
memory: 19200kb

input:

20
2 11
1 8
4 10
2 2
8 12
3 2
6 8
5 8
9 10
9 6
9 7
9 14
3 5
2 9
1 2
6 10
1 6
4 3
4 7
1 7

output:

245743886
44
691092249
332748120
522207092
499122177
401724376
489759135
38188698
0
0
588440629
156866973
880990281
5
974144215
27
598946612
2
35

result:

ok 20 numbers

Test #12:

score: 0
Accepted
time: 7ms
memory: 19236kb

input:

20
4 6
3 9
4 9
10 9
9 5
5 6
3 7
10 7
3 9
9 13
3 11
3 6
8 13
8 6
9 11
10 11
3 11
8 5
9 5
3 4

output:

332748119
867737959
907494870
334869712
0
126761188
323241035
0
867737959
543627802
522191842
655989151
448034137
0
973433586
537116365
522191842
0
0
299473308

result:

ok 20 numbers

Test #13:

score: 0
Accepted
time: 8ms
memory: 19152kb

input:

20
9 7
5 9
9 11
7 13
5 11
8 11
1 7
5 9
3 11
6 6
4 6
9 13
7 13
6 11
2 6
6 13
6 8
5 7
2 6
5 11

output:

0
524662784
973433586
628061442
627046821
900203882
35
524662784
522191842
101552997
332748119
543627802
628061442
897356188
104577993
375649298
401724376
671258108
104577993
627046821

result:

ok 20 numbers

Test #14:

score: 0
Accepted
time: 9ms
memory: 19232kb

input:

20
6 12
5 7
10 13
3 6
3 4
3 5
7 9
1 2
4 5
2 4
4 9
10 6
3 10
5 11
8 6
3 3
2 4
6 13
2 6
8 8

output:

581170194
671258108
583321633
655989151
299473308
156866973
176961499
5
142606337
532396995
907494870
0
368615785
627046821
0
299473307
532396995
375649298
104577993
278918935

result:

ok 20 numbers

Test #15:

score: 0
Accepted
time: 41ms
memory: 19236kb

input:

300000
1 5
1 6
1 6
1 6
1 6
1 6
1 6
1 6
1 5
1 6
1 6
1 6
1 6
1 5
1 6
1 6
1 5
1 6
1 6
1 6
1 6
1 6
1 5
1 6
1 6
1 6
1 5
1 6
1 5
1 6
1 6
1 6
1 6
1 5
1 5
1 5
1 5
1 6
1 6
1 6
1 5
1 6
1 6
1 6
1 6
1 6
1 6
1 6
1 6
1 6
1 5
1 6
1 5
1 6
1 6
1 6
1 6
1 5
1 6
1 6
1 6
1 6
1 6
1 6
1 6
1 5
1 6
1 6
1 6
1 6
1 5
1 6
1 5
1...

output:

20
27
27
27
27
27
27
27
20
27
27
27
27
20
27
27
20
27
27
27
27
27
20
27
27
27
20
27
20
27
27
27
27
20
20
20
20
27
27
27
20
27
27
27
27
27
27
27
27
27
20
27
20
27
27
27
27
20
27
27
27
27
27
27
27
20
27
27
27
27
20
27
20
27
20
27
20
20
27
20
20
27
27
27
27
27
20
20
20
27
20
27
27
20
20
27
20
27
27
27
...

result:

ok 300000 numbers

Test #16:

score: 0
Accepted
time: 38ms
memory: 19388kb

input:

300000
6 1
5 1
6 1
6 1
6 1
6 1
6 1
5 1
6 1
5 1
6 1
6 1
6 1
6 1
5 1
6 1
6 1
5 1
6 1
6 1
6 1
5 1
5 1
6 1
6 1
5 1
6 1
5 1
5 1
5 1
6 1
6 1
5 1
5 1
5 1
6 1
5 1
5 1
5 1
6 1
6 1
5 1
6 1
5 1
6 1
5 1
5 1
6 1
6 1
6 1
6 1
6 1
6 1
6 1
6 1
6 1
6 1
6 1
5 1
5 1
6 1
6 1
5 1
6 1
5 1
5 1
6 1
5 1
6 1
5 1
6 1
6 1
6 1
5...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 300000 numbers

Test #17:

score: 0
Accepted
time: 70ms
memory: 19384kb

input:

300000
3 3
2 5
1 6
5 2
1 6
1 6
5 2
6 1
1 6
2 5
5 2
5 1
2 5
1 6
1 6
1 5
3 4
4 3
1 6
6 1
4 3
1 5
5 2
5 2
1 6
4 3
5 2
1 6
6 1
2 5
1 6
4 3
2 4
2 5
5 2
4 3
2 5
2 5
1 6
4 3
1 6
2 4
3 3
3 4
2 4
4 3
3 3
4 3
1 6
5 2
4 2
3 4
1 5
3 3
4 2
1 6
3 4
3 4
3 3
2 5
2 4
2 5
3 4
2 4
1 6
4 2
2 5
5 2
1 6
4 2
1 6
5 2
6 1
4...

output:

299473307
532396998
27
0
27
27
0
0
27
532396998
0
0
532396998
27
27
20
299473308
598946612
27
0
598946612
20
0
0
27
598946612
0
27
0
532396998
27
598946612
532396995
532396998
0
598946612
532396998
532396998
27
598946612
27
532396995
299473307
299473308
532396995
598946612
299473307
598946612
27
0
0...

result:

ok 300000 numbers

Test #18:

score: -100
Wrong Answer
time: 6ms
memory: 19196kb

input:

1
1000000 1000000

output:

65062452

result:

wrong answer 1st numbers differ - expected: '509847430', found: '65062452'