QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212647#5826. 错排kkkgjyismine41 952ms7004kbC++14921b2023-10-13 18:58:052023-10-13 18:58:05

Judging History

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

  • [2023-10-13 18:58:05]
  • 评测
  • 测评结果:1
  • 用时:952ms
  • 内存:7004kb
  • [2023-10-13 18:58:05]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const ll mod=998244353;
ll fac[200005],ifac[200005];
void add(ll &x,const ll y){if((x+=y)>=mod)x-=mod;}
void sub(ll &x,const ll y){if((x+=(mod-y))>=mod)x-=mod;}
ll qpow(ll a,ll b){
	ll res=1ll;
	while(b){if(b&1ll)res=res*a%mod;a=a*a%mod;b>>=1;}
	return res;
}
void init(){
	fac[0]=ifac[0]=1ll;
	for(int i=1;i<=200000;++i)fac[i]=fac[i-1]*1ll*i%mod,ifac[i]=qpow(fac[i],mod-2);
}
ll comb(int N,int M){
	return fac[N]*ifac[M]%mod*ifac[N-M]%mod;
}
ll A(int N,int M){
	return fac[N]*ifac[N-M]%mod;
}
ll solve(int N,int M){
	if(2*M>N)return 0ll;
	ll res=0ll;
	for(int i=0;i<=N-M&&N-M-i>=M;++i)
	 if(i&1)sub(res,A(N-M-i,M)*ifac[i]%mod);
	 else add(res,A(N-M-i,M)*ifac[i]%mod);
	return res;
}
int main() {
	init(); 
	int t;cin>>t;
	while(t--){
		int N,M;
		scanf("%d%d",&N,&M);
		printf("%lld\n",solve(N,M));
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 19ms
memory: 6756kb

input:

0

output:


result:

ok 0 number(s): ""

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 23ms
memory: 6936kb

input:

10
8 6
5 1
4 2
6 3
8 1
3 1
6 2
3 1
4 1
6 2

output:

0
831870296
2
6
633607877
1
7
1
499122178
7

result:

wrong answer 2nd numbers differ - expected: '44', found: '831870296'

Subtask #3:

score: 0
Time Limit Exceeded

Test #7:

score: 0
Time Limit Exceeded

input:

200000
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0
25 0
26 0
27 0
28 0
29 0
30 0
31 0
32 0
33 0
34 0
35 0
36 0
37 0
38 0
39 0
40 0
41 0
42 0
43 0
44 0
45 0
46 0
47 0
48 0
49 0
50 0
51 0
52 0
53 0
54 0
55 0
56 0
57 0
58 0
59 0
60 0
61...

output:

0
499122177
332748118
623902721
765320671
409002895
32086426
453542617
739462269
111923692
804219060
81031544
674177543
988325812
834283347
781520729
373582620
8039711
972983988
375702380
736892479
402851544
981600132
458363431
798731092
977610096
120628647
828615224
425557484
438992742
760573654
25...

result:


Subtask #4:

score: 0
Wrong Answer

Test #8:

score: 0
Wrong Answer
time: 952ms
memory: 7004kb

input:

200000
4303 1473
1276 72
967 234
3619 984
1316 384
2679 50
4426 1744
3782 1179
4919 4
805 63
3933 158
1574 528
1277 435
3826 915
2739 68
2286 349
3017 527
3036 476
4280 1764
1504 686
4584 917
1379 145
4764 2178
1881 45
4808 1565
3663 165
4730 2209
2258 103
4181 1687
1636 770
4339 1173
2355 777
3201 ...

output:

48424500
690597016
278381057
471778688
526185958
723164498
455853835
316314021
597014852
531310165
276400693
162147085
841765568
395744182
376450695
453409330
916009305
369808641
949352590
245891804
310139599
314560153
322340764
305182701
174527704
928989129
81694956
309639842
49809913
216589918
494...

result:

wrong answer 1st numbers differ - expected: '855518783', found: '48424500'

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%