QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506658 | #6168. 异构序列码性态问题 | neilliu | 0 | 728ms | 29188kb | C++98 | 1.6kb | 2024-08-05 20:30:35 | 2024-08-05 20:30:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
long long ksm(long long a,long long b,long long p){
long long ans = 1;
for(; b; b >>= 1){
if(b & 1) ans = ans * a % p;
a = a * a % p;
}
return ans;
}
long long fac[10000005],infac[10000005],Ca[5000005];
void init(long long n,long long p){
fac[0] = infac[0] = fac[1] = infac[1] = 1;
for(int i = 2; i <= n; i++) fac[i] = fac[i-1] * i % p;
infac[n] = ksm(fac[n],p-2,p);
for(int i = n-1; i >= 2; i--) infac[i] = infac[i+1] * i % p;
}
long long C(int x,int y,long long p){
return fac[x] * infac[y] % p * infac[x-y] % p;
}
void Catalan(int n,long long p){
Ca[0] = Ca[1] = 1;
for(int i = 2; i <= n; i++) Ca[i] = Ca[i-1] * (4 * i - 2) % p * ksm((i+1),p-2,p) % p;
}
int main()
{
int n; long long p;
while(cin >> n >> p){
if(n <= 3){
printf("0\n");
continue;
}
init(2*n,p);
Catalan(n,p);
long long ans = 0;
n = n-1;
long long mici = 1;
for(int i = 0; i <= n; i++){
long long sum = 1;
sum = sum * mici % p; mici = mici + mici; if(mici >= p) mici -= p;
sum = sum * C(n+i,n-i,p) % p;
sum = sum * (i == 0 ? 1 : Ca[i]) % p;
if((n-i) & 1) sum = -sum;
ans = ans + sum;
if(ans < 0) ans = ans + p;
if(ans >= p) ans = ans - p;
if(ans >= p) ans = ans - p;
if(ans >= p) ans = ans - p;
}
printf("%lld\n",(fac[n+1] - ans - ans + p + p) % p);
}
return 0;
}
详细
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 7932kb
input:
1329 281979259 3946 347158051 3102 613279651 4193 175275013 494 674092373 549 240448331 3924 588857561 1719 782159639 1781 270936499 672 589936439
output:
87535551 271791847 380467093 165260832 285251389 118358712 445864549 541929787 19384184 31162590
result:
wrong answer 1st numbers differ - expected: '9022243', found: '87535551'
Test #2:
score: 0
Wrong Answer
time: 8ms
memory: 7932kb
input:
2013 239960621 2839 377547413 4864 996482101 3196 204395311 1568 653611141 753 104807119 3006 755688737 3047 697114861 2943 384316589 2413 512454407
output:
139347506 318377658 116115367 13847106 479289883 7388308 256643185 113653821 306894566 403596421
result:
wrong answer 1st numbers differ - expected: '127514501', found: '139347506'
Test #3:
score: 0
Wrong Answer
time: 3ms
memory: 7876kb
input:
4542 497374921 4375 144420547 3310 175379389 1159 776452463 642 401409289 1214 754051891 1956 962928761 3925 282058753 2664 215149997 2050 912416861
output:
330410844 2408084 157542177 261820155 8743569 249670946 603102419 119278891 75615020 279260053
result:
wrong answer 1st numbers differ - expected: '234466993', found: '330410844'
Test #4:
score: 0
Wrong Answer
time: 8ms
memory: 7880kb
input:
4808 349909687 4602 991037059 108 14516431 3384 974151743 1250 726146471 4891 585626857 3617 211451333 358 425997931 2891 654329051 4814 64701121
output:
348569940 409682299 12419151 74918406 241698811 525942510 185053829 296642443 45936313 53967598
result:
wrong answer 1st numbers differ - expected: '334429486', found: '348569940'
Test #5:
score: 0
Wrong Answer
time: 6ms
memory: 9980kb
input:
1107 524640323 1847 933584471 3406 582135349 4007 51397727 80 570372863 4186 193850947 1773 505708747 59 753490921 4244 207441401 723 3432577
output:
271299297 922120028 504408375 46993372 165391452 172049160 239167348 127115811 39327639 2347962
result:
wrong answer 1st numbers differ - expected: '28404629', found: '271299297'
Test #6:
score: 0
Wrong Answer
time: 728ms
memory: 29188kb
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:
49372277 218705600 171819508 550619135 112572016 209924449 299834531 535438251 200299821 367947924 202575865 26695901
result:
wrong answer 1st numbers differ - expected: '17579808', found: '49372277'
Test #7:
score: 0
Time Limit Exceeded
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:
48505677 302605212 634163168 653014633 50971902 12034234 409457602 223276754 135417379 238019848 205485116 737511137 263506709
result:
Test #8:
score: 0
Time Limit Exceeded
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:
384990215 125432430 2146564 64924601 144639879 70658300 162136074 67197541 37185643 239964493 9536379 435029721 558980982 742385384
result:
Test #9:
score: 0
Time Limit Exceeded
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:
364298975 759953347 168202484 4904535 739831196 158905095 144522363 143548523 484453466 218382530 23133413 5287367 469325067 917237341 37765729 666483884 241390276 60727480 469073707
result:
Test #10:
score: 0
Time Limit Exceeded
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:
34104871 230826956 218358827 240329060 238942429 199877153 4358325 432760151 776272645 803148674 367377539 591234 280666304 3861373 161604738 74288737