QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#166823 | #5530. No Zero-Sum Subsegment | qzez | AC ✓ | 88ms | 35200kb | C++14 | 1002b | 2023-09-06 19:00:24 | 2023-09-06 19:00:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=4e6+10,mod=998244353;
int fac[N],ifac[N];
ll qpow(ll x,ll y=mod-2){
ll ans=1;
for(;y;(x*=x)%=mod,y>>=1)if(y&1)(ans*=x)%=mod;
return ans;
}
void init(int n=4e6){
for(int i=fac[0]=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
ifac[n]=qpow(fac[n]);
for(int i=n;i>=1;i--)ifac[i-1]=1ll*ifac[i]*i%mod;
}
int C(int n,int m){
if(0>m||m>n)return 0;
return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int T,a,b,c,d;
int C(int a,int b,int c){
return 1ll*C(a+b+c,a)*C(b+c,b)%mod;
}
int calc(int b,int c,int d){
return C(d-b*2,b,c);
}
void get(){
scanf("%d%d%d%d",&a,&b,&c,&d);
int sum=0-2*a-b+c+2*d;
if(sum<0)swap(a,d),swap(b,c);
printf("%d\n",int((
0ll
+!a*calc(b,c,d)
+(a-1ll)*(a>1)*calc(b,c-2,d-a)
+(a+1ll)*calc(b-2,c,d-a-2)
+2*!!a*calc(b,c-1,d-a)
+2*calc(b-1,c,d-a-1)
+2ll*a*!!a*calc(b-1,c-1,d-a-1)
)%mod));
}
int main(){
for(init(),scanf("%d",&T);T--;)get();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 24ms
memory: 35200kb
input:
5 69 0 0 0 1 1 1 1 0 0 3 3 6 1 0 6 10000 10000 1000000 1000000
output:
1 0 20 2 480402900
result:
ok 5 number(s): "1 0 20 2 480402900"
Test #2:
score: 0
Accepted
time: 53ms
memory: 35152kb
input:
83520 13 1 6 8 13 9 3 14 1 16 13 0 8 12 7 16 10 5 9 15 16 16 15 1 5 11 0 4 12 4 11 15 16 7 1 10 2 6 3 3 15 14 12 0 0 8 12 12 3 0 6 7 16 2 16 15 16 16 16 13 8 13 2 14 7 9 7 0 9 8 4 6 13 16 4 11 11 1 12 4 7 9 4 16 12 13 0 4 5 0 9 1 11 11 0 3 1 11 14 3 3 3 7 3 8 5 4 4 6 7 12 14 2 11 5 6 15 4 9 14 15 11...
output:
0 0 0 0 0 0 52 0 26784 0 0 0 392 0 0 0 0 0 0 0 0 478686 0 136136 0 0 0 0 0 0 0 1680 0 821 0 24024 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8994258 0 0 0 0 0 293930 0 0 156637 166 0 0 0 0 0 0 0 0 0 54 0 0 1248 126 0 0 0 344 0 9867 10880 544 0 0 0 0 0 216580 0 0 4620 0 0 0 0 0 57915 0 0 0 10 0 72442440 0 1085473...
result:
ok 83520 numbers
Test #3:
score: 0
Accepted
time: 75ms
memory: 35076kb
input:
100000 27617 154585 61225 74297 699481 42306 265668 389057 94916 26621 153453 31500 425780 600614 439472 658406 180214 69209 369042 30297 67467 59798 156985 18873 501987 67164 156713 837634 534254 516732 831502 270708 671302 293648 947387 500010 32836 656676 169292 276528 98106 103776 160535 69726 3...
output:
0 0 0 0 0 0 194764989 0 0 0 0 0 0 0 763382948 0 0 0 949015107 0 0 0 0 0 0 0 0 0 805190744 0 0 0 166921450 0 0 0 0 0 0 0 0 774134257 0 0 780255367 0 497969058 0 0 0 0 0 0 0 0 0 0 0 856165384 0 0 0 868431198 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 320724406 0 ...
result:
ok 100000 numbers
Test #4:
score: 0
Accepted
time: 71ms
memory: 35136kb
input:
100000 58719 33026 48164 51150 25256 185757 125140 55564 194661 121907 44771 233229 249060 852053 865334 314598 832924 377083 60810 845556 934913 292101 320197 894291 20989 83322 14558 55371 327550 75392 525839 102326 71525 503165 407510 119352 459874 622834 707026 106953 65849 107929 217910 10858 3...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 634674089 0 0 0 0 764104266 0 0 508267610 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 539222878 48702106 0 0 0 0 0 0 0 0 0 0 577550206 0 0 0 0 0 0 397715714 0 0 0 0 0 72760701 0 0 0 0 0 0 0 0 0 537517797 0 0 0 215174626 0 0 0 6864...
result:
ok 100000 numbers
Test #5:
score: 0
Accepted
time: 77ms
memory: 35008kb
input:
100000 5941 50819 38713 11994 274893 953821 48620 299319 45893 620324 16146 347982 204327 130053 153409 412334 272720 311527 416630 220168 765136 923124 339636 50583 129807 128630 10087 189078 257217 186497 354108 331226 282100 450244 255282 457422 226101 459570 444613 233579 164614 52871 205583 882...
output:
0 0 0 0 0 296933342 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 453176305 0 0 0 918517169 0 0 539376401 136577774 0 0 0 0 651578421 88133489 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 928783827 0 0 0 807979336 757750507 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 976196304 0 0 0 0 244588581 0 0 273331158 0 0...
result:
ok 100000 numbers
Test #6:
score: 0
Accepted
time: 57ms
memory: 35068kb
input:
100000 534 2278 170 1588 102592 337232 162666 189875 16311 546946 612313 314374 631285 469456 954538 251956 661532 653089 412221 882885 318859 13038 578574 36091 110058 269015 880401 772505 93119 17290 196137 3695 29463 170087 27777 100618 579473 947503 512979 645501 159386 586361 667265 118934 1340...
output:
0 0 0 0 0 0 700113238 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 914382015 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 183215844 0 0 0 284197109 0 0 0 0 0 0 106261876 0 0 0 662481442 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 172392525 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 100000 numbers
Test #7:
score: 0
Accepted
time: 82ms
memory: 35148kb
input:
100000 325053 265475 836899 39341 924988 903018 868573 209581 43791 148596 1309 117434 50578 55578 35992 60371 273882 90561 144728 246798 61592 40977 1948 81106 111333 127340 343730 3138 845096 890886 54864 856263 317746 621671 4580 606840 451833 95133 623582 697492 77516 970744 564976 805729 185351...
output:
0 0 0 0 0 0 0 0 0 80008605 0 0 0 0 0 0 0 0 0 0 0 0 0 0 487687301 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 274341937 0 0 53719296 0 0 651208403 0 0 0 0 0 0 0 0 283939399 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 884940662 0 0 0 0 0 0 0 0 0 0 0 406288474 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 numbers
Test #8:
score: 0
Accepted
time: 85ms
memory: 35144kb
input:
100000 405340 73956 449424 217606 231193 396458 723050 146212 546227 309438 887926 456734 998896 594477 5883 297830 60845 132814 93952 80276 816876 397265 482463 350090 28168 225945 247709 17286 325924 63501 185639 264855 291479 185137 309966 374697 166038 366583 525794 86432 109137 630664 440578 95...
output:
0 0 0 478509240 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 140469630 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 813086393 0 292600864 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 233789292 0 0 0 507043898 92815206 0 0 0 0 0 0 0...
result:
ok 100000 numbers
Test #9:
score: 0
Accepted
time: 80ms
memory: 35012kb
input:
100000 106964 647397 790509 35408 267794 26686 246321 157976 89466 726792 171693 367015 31825 134371 76934 60543 883191 886308 162544 23692 44352 454191 371920 85487 20591 32265 67994 2726 122425 84266 52610 138253 435637 341266 762584 615378 945758 409244 51772 864059 234380 34699 266207 118626 150...
output:
0 0 0 0 267245054 0 0 0 0 0 0 0 0 0 304250109 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 612476766 0 0 0 0 0 0 0 0 0 0 0 780075770 0 0 0 301587910 0 0 0 0 0 0 0 0 0 0 0 0 729409111 0 0 0 0 0 0 922949166 0 0 0 0 0 183235011 0 0 0 0 0 0 0 0 0 0 962264540 43224724 0 0 0 0 660839839 726233625 0 0 0 0 0 0 0...
result:
ok 100000 numbers
Test #10:
score: 0
Accepted
time: 72ms
memory: 35056kb
input:
100000 360056 53450 539202 117180 844290 345656 543001 56474 3899 7910 13300 1204 176226 196961 10481 269466 26148 40882 29684 31747 872067 916938 4922 398458 296183 142128 10734 887862 639652 879410 678098 797185 939277 341734 617863 369108 540138 325715 903344 105198 799039 822644 788701 306950 72...
output:
0 0 0 0 0 630686956 535701968 0 0 0 0 0 0 0 0 0 0 512404147 0 0 942490429 0 0 0 0 0 0 0 66530161 0 0 0 0 0 443077747 0 0 0 0 0 840748258 0 0 0 0 0 0 0 0 985290976 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 431882255 0 0 0 0 0 718135492 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 851634074 0 0 0...
result:
ok 100000 numbers
Test #11:
score: 0
Accepted
time: 75ms
memory: 35140kb
input:
100000 143908 426391 112547 300830 169742 564981 141015 381725 66134 759661 55891 418019 436830 653021 793055 109541 100262 447678 653655 422411 710162 635945 491894 989027 168987 714835 927240 437034 117686 205098 319591 60439 31647 289646 315579 18680 8411 179218 547227 986647 181740 128415 433806...
output:
0 0 0 0 0 0 0 0 0 725486585 0 0 0 0 0 90030904 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 278510837 0 0 0 47498401 0 0 0 0 0 0 0 182146479 0 0 0 0 473290179 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 898660231 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 680575188 0 0 0 0 0 0 0 0 0 0 577031...
result:
ok 100000 numbers
Test #12:
score: 0
Accepted
time: 80ms
memory: 35068kb
input:
100000 638116 228467 661257 945105 327393 444074 957303 507360 241912 908074 519608 454903 266748 447591 31641 474723 361303 47755 734205 508264 182843 324481 56746 316710 78198 149575 281105 12433 6217 67236 69752 4959 56105 635927 606410 70863 180226 720416 390092 601546 552164 666620 561081 16594...
output:
0 0 0 0 247220605 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 49831911 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 679414444 0 0 0 0 0 0 403465667 353455409 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 588457023 0 0 0 0 0 0 666736930 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 716920878 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 96847723 0 0 0 982346557 ...
result:
ok 100000 numbers
Test #13:
score: 0
Accepted
time: 88ms
memory: 35056kb
input:
100000 629934 261413 92819 190792 783150 372549 967933 676695 590475 158192 858868 844177 200525 475740 468445 204172 138943 812932 537341 301488 617109 517186 83399 188966 503862 827895 207332 651450 1221 53013 55409 23 692886 430232 658888 396495 647165 826312 690558 732308 164416 37553 170370 980...
output:
77756970 0 0 0 0 652119663 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 984675528 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 826842297 0 0 0 360229622 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 432835395 682101384 0 0 0 0 0 0 0 0 0 147975049 0 0 0 0 0 0 0 0 0 0 0 0 0 0 895977155 0 0 0 0 0 0 0 745...
result:
ok 100000 numbers
Test #14:
score: 0
Accepted
time: 60ms
memory: 35160kb
input:
100000 622436 293675 524382 361796 37455 298495 330355 21525 639291 864354 445310 123444 21761 256090 277788 10912 90160 374988 369375 92966 131711 73100 636548 673479 178826 519046 542555 945590 967834 110094 858966 43876 138105 37107 232459 40429 997892 833802 767466 131644 797996 943147 958372 26...
output:
0 0 0 0 0 863893295 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 415222323 0 0 0 0 0 0 0 0 947781761 0 0 0 0 0 0 0 0 0 0 0 0 0 916701521 0 0 0 0 0 0 0 459722047 0 0 753551061 0 0 0 0 0 0 0 981515997 929496314 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 636954397 0 0 0 0 374918592 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 numbers
Test #15:
score: 0
Accepted
time: 81ms
memory: 35156kb
input:
100000 651937 326622 993628 607484 87930 89179 7414 128812 620774 249915 769427 462704 842878 902390 590020 762378 30804 217048 259960 9348 126874 677375 230703 350210 168001 186148 507250 100969 149839 505112 612279 96255 815274 300222 38466 387644 32237 133996 156858 20806 967345 900683 614995 891...
output:
0 0 0 0 0 0 0 0 851525494 0 0 30932531 309075476 0 0 0 0 0 0 0 0 0 0 0 0 0 0 840922290 0 0 0 0 0 0 0 0 0 0 0 0 0 957708392 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 783899548 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 178945821 0...
result:
ok 100000 numbers
Test #16:
score: 0
Accepted
time: 75ms
memory: 35192kb
input:
100000 718438 358883 462189 853171 225788 46977 814826 295697 78433 232351 102174 143521 70598 703518 429643 387855 25962 32672 12233 36181 77855 161483 274445 21374 157862 852565 546628 218664 18249 38407 45261 14822 49134 730010 178328 324975 154453 33037 94670 123636 26256 446243 458270 20242 787...
output:
0 0 0 0 0 0 0 0 0 0 0 548561933 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32014039 688145245 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 966062326 0 0 590546194 0 0 0 0 0 0 0 0 0 0 0 0 657898935 0 0 0 0 0 0 0 0 0 0 0 343956036 0 0 639735506 0 0 0 0 0 0 0 0 0 0 0 0 0 493518296 0 0 810848708 0 0 0 0 0 3983944...
result:
ok 100000 numbers
Test #17:
score: 0
Accepted
time: 82ms
memory: 35056kb
input:
100000 710940 391830 893751 61174 718545 901455 751458 539030 40466 46365 105433 10932 54275 753244 778315 41739 250544 162987 228097 217989 586068 929854 731176 142358 59562 584051 464159 119508 165722 54579 302796 41613 737432 426072 419820 420360 609165 952131 424340 979690 172572 201264 457729 4...
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 188573774 0 332357131 21169505 0 0 0 113477332 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 611892393 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 100000 numbers
Test #18:
score: 0
Accepted
time: 75ms
memory: 35008kb
input:
100000 740441 387093 362312 306861 174301 829930 688089 745364 264516 307937 286775 275097 11663 75756 78192 10445 266730 139508 785437 293346 523877 750615 298651 968501 223766 550016 454740 552083 298400 214982 404922 203430 216443 215876 524378 62192 9194 3012 2048 9676 13582 42279 67012 1215 399...
output:
0 0 0 0 0 0 0 0 0 0 0 0 671304061 0 0 0 0 0 0 0 0 0 0 0 0 0 386265540 0 0 0 0 0 0 15837296 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 867706883 0 0 0 0 0 43154124 0 0 0 0 0 0 0 0 0 0 388839390 0 0 0 0 0 0 0 0 0 0 0 0 0 408368551 0 0 0 0 502189878 0 0 0 0 0 0 0 0 0 0 0 0 0 266324571 0 0 0 0 0 0 0 4948457 0 ...
result:
ok 100000 numbers
Test #19:
score: 0
Accepted
time: 63ms
memory: 35140kb
input:
100000 695260 419354 831559 515550 184198 277450 65682 290082 768703 532483 917214 707377 939442 182268 60191 227285 954148 587612 984801 209515 150411 610872 26790 442452 927868 589395 647118 487905 22697 383677 257103 85984 575731 728256 302467 565804 830366 108611 732994 483234 341442 550772 1323...
output:
0 0 0 530126166 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 91652759 635305438 0 0 0 0 0 0 787159523 400596533 0 0 0 0 0 0 0 0 969012946 0 0 0 0 0 0 0 0 0 310915259 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 426562793 0 0 0 0 0 0 0 0 0 0 0 0 0 915252724 0 0 0 0 0 0 0 0 181099002...
result:
ok 100000 numbers
Test #20:
score: 0
Accepted
time: 71ms
memory: 35092kb
input:
100000 724761 452301 300119 723554 173734 161603 229636 139717 131367 246550 354543 77370 231321 880 310904 76309 367062 11250 306136 219619 750938 77422 748923 788806 878280 226930 631968 554090 97703 194000 217160 86123 430302 397768 154028 401046 17685 58004 85604 3885 122954 219291 183015 141092...
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 131360519 0 0 0 210454999 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 704661460 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 65294898 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 229380092 0 0 0 0 0 0 0 0 0 0 0 0 617...
result:
ok 100000 numbers
Test #21:
score: 0
Accepted
time: 73ms
memory: 35072kb
input:
100000 791262 447564 694683 6239 616940 504358 534983 364366 229607 491450 311214 72102 896206 814120 441239 730744 117278 554075 907647 379945 730531 869826 216790 336068 883194 173869 293511 956692 982260 721667 769326 73151 17044 2338 24521 5952 33029 892661 756255 101232 8257 130824 7259 70039 8...
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 805895957 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 761960313 0 0 0 0 922099421 0 0 0 0 104505549 0 0 0 0 0 0 0 0 0 0 0 225356198 0 297728612 0 0 0 0 ...
result:
ok 100000 numbers
Test #22:
score: 0
Accepted
time: 70ms
memory: 35192kb
input:
100000 136652 504767 94536 341767 862104 320598 556926 907196 182189 634900 490197 254540 960650 674764 8114 880285 136661 214030 301252 711257 326716 165398 707588 840821 685434 933940 168331 443975 29005 323365 569727 831989 391175 17069 209723 294848 563502 458570 560586 339795 376112 524133 5784...
output:
0 0 0 431554119 925171693 333803883 0 365980493 0 0 0 0 0 0 0 0 0 0 0 0 69653793 302244044 0 0 0 0 0 0 0 0 0 0 0 9913509 0 128584403 0 0 810889218 695398518 0 0 0 0 87750433 0 409120786 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 946710902 0 0 0 0 468859584 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 numbers