QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506565#6168. 异构序列码性态问题DaiRuiChen0070 498ms23692kbC++17735b2024-08-05 19:28:512024-08-05 19:28:52

Judging History

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

  • [2024-08-05 19:28:52]
  • 评测
  • 测评结果:0
  • 用时:498ms
  • 内存:23692kb
  • [2024-08-05 19:28:51]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,MOD;
ll ksm(ll a,ll b=MOD-2,ll p=MOD) {
	ll ret=1;
	for(;b;a=a*a%p,b>>=1) if(b&1) ret=ret*a%p;
	return ret;
}
const int MAXN=1e7+5;
ll fac[MAXN],ifac[MAXN];
ll C(int x,int y) { return fac[x]*ifac[y]%MOD*ifac[x-y]%MOD; }
void solve() {
	if(n<=2) return puts("0"),void();
	for(int i=fac[0]=1;i<=2*n;++i) fac[i]=fac[i-1]*i%MOD;
	ifac[2*n]=ksm(fac[2*n]);
	for(int i=2*n;i;--i) ifac[i-1]=ifac[i]*i%MOD;
	ll ans=0,pw=2;
	for(int i=0;i<=n;++i) {
		ans=(ans+((n-i)%2?-1:1)*pw*C(n+i,n-i)%MOD*(i?C(2*i,i)-C(2*i,i-1):1))%MOD;
		pw=pw*2%MOD;
	}
	printf("%lld\n",(ans+MOD)%MOD);
}
signed main() {
	while(~scanf("%d%d",&n,&MOD)) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 5976kb

input:

1329 281979259
3946 347158051
3102 613279651
4193 175275013
494 674092373
549 240448331
3924 588857561
1719 782159639
1781 270936499
672 589936439

output:

93482265
158523988
487448650
43195761
141397665
55021909
389258948
361010885
126742558
376030744

result:

wrong answer 1st numbers differ - expected: '9022243', found: '93482265'

Test #2:

score: 0
Wrong Answer
time: 2ms
memory: 5932kb

input:

2013 239960621
2839 377547413
4864 996482101
3196 204395311
1568 653611141
753 104807119
3006 755688737
3047 697114861
2943 384316589
2413 512454407

output:

13329099
356319367
809994192
132774547
181650945
44483224
392233601
80662235
41502075
341274952

result:

wrong answer 1st numbers differ - expected: '127514501', found: '13329099'

Test #3:

score: 0
Wrong Answer
time: 2ms
memory: 5872kb

input:

4542 497374921
4375 144420547
3310 175379389
1159 776452463
642 401409289
1214 754051891
1956 962928761
3925 282058753
2664 215149997
2050 912416861

output:

37491891
44580595
55635702
259973396
128302939
581643149
192766210
275357787
94504712
513891764

result:

wrong answer 1st numbers differ - expected: '234466993', found: '37491891'

Test #4:

score: 0
Wrong Answer
time: 2ms
memory: 8108kb

input:

4808 349909687
4602 991037059
108 14516431
3384 974151743
1250 726146471
4891 585626857
3617 211451333
358 425997931
2891 654329051
4814 64701121

output:

168436887
527603937
12161862
393921914
25595563
252803256
61812774
144853208
162997182
25885455

result:

wrong answer 1st numbers differ - expected: '334429486', found: '168436887'

Test #5:

score: 0
Wrong Answer
time: 0ms
memory: 6060kb

input:

1107 524640323
1847 933584471
3406 582135349
4007 51397727
80 570372863
4186 193850947
1773 505708747
59 753490921
4244 207441401
723 3432577

output:

513055219
145829559
217989916
4348491
527789206
119651172
203064339
10593501
184959918
1452975

result:

wrong answer 1st numbers differ - expected: '28404629', found: '513055219'

Test #6:

score: 0
Wrong Answer
time: 157ms
memory: 20460kb

input:

350598 149719567
5656 639718861
182032 562484129
321578 733607449
396666 977259137
289217 738297893
94787 357806747
130763 912856261
129615 332700631
439091 653900939
228198 805737671
421386 35411809

output:

81666725
606192341
447878773
213643328
210130743
422128422
248854912
440951907
260548838
350481683
648499624
35128380

result:

wrong answer 1st numbers differ - expected: '17579808', found: '81666725'

Test #7:

score: 0
Wrong Answer
time: 215ms
memory: 23636kb

input:

71980 730430429
365591 519176123
421874 939796883
442008 891121537
196686 57507407
481211 220812971
351047 410650543
262764 313392899
434798 192402149
113530 421210637
359403 379486343
396967 813975307
193616 995122811

output:

107843900
358619265
591355142
49636252
40558185
141995466
36020907
52067686
133298264
150543151
104441792
787512486
912235967

result:

wrong answer 1st numbers differ - expected: '327860411', found: '107843900'

Test #8:

score: 0
Wrong Answer
time: 265ms
memory: 23692kb

input:

412065 473565137
427460 278321429
481215 341626709
248825 235725317
391371 550178417
166694 541821383
3035 184388593
166130 370451243
342592 79808159
98863 640391243
416610 96090131
479715 456938333
407065 630349243
289928 807773149
486842 415008521
300760 618573047

output:

186596569
125911240
75641677
49936741
345568618
114375852
46551934
131796038
62820971
375756204
23577486
185717685
117882993
78955770
67101507
85845727

result:

wrong answer 1st numbers differ - expected: '227856800', found: '186596569'

Test #9:

score: 0
Wrong Answer
time: 488ms
memory: 23236kb

input:

401210 376894061
112020 976190981
76624 418721741
308217 29130763
275157 939661747
35829 250363831
178538 424627327
456973 351281803
88075 992733541
281595 311233067
104622 151994753
271593 41245261
319132 947462657
186811 961154149
227249 86441119
165977 701025443
471204 999330173
296567 685415303
...

output:

65428197
379093319
2054256
3254469
532170586
42177799
269012035
225560635
738398591
28859120
126743861
36378480
776514983
204872141
71924355
133355601
338694876
510912277
136798295
255090376
228194305
283976968
383386670
129333687
11378665
7456462
82948097
270083363
89510049
746848053
375924556
2629...

result:

wrong answer 1st numbers differ - expected: '137731023', found: '65428197'

Test #10:

score: 0
Wrong Answer
time: 498ms
memory: 23540kb

input:

372965 157601299
239698 272457617
40399 596646311
315339 562161443
166279 292784099
224605 629707601
14534 7015139
478528 718703087
129027 957763397
44039 880925107
420271 933815867
323410 164444393
160117 572839451
344095 28487981
473223 648555881
469070 150428897
447149 993828707
214989 982422577
...

output:

93465935
13851267
519370389
141768024
202732093
287254225
3779237
358500151
745001894
481516383
298466889
3662946
185972780
25514432
17081432
7823349
318620920
674313767
11445006
44543351
293641898
217822584
154446556
164137019
219442270
102731677
66893151
88789770
3003122
150782165
442928538
275048...

result:

wrong answer 1st numbers differ - expected: '109121987', found: '93465935'