QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67840 | #5194. 游戏 | alpha1022 | AC ✓ | 7ms | 7464kb | C++23 | 2.2kb | 2022-12-12 15:58:55 | 2022-12-12 15:58:58 |
Judging History
answer
#include<bits/stdc++.h>
#define gc getchar()
#define pc putchar
#define li long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define md int mid = l + r >> 1
#define ls q << 1
#define rs q << 1 | 1
#define ln ls,l,mid
#define rn rs,mid + 1,r
using namespace std;
const int mo = 998244353;
inline li read(){
li x = 0;
int y = 0,c = gc;
while(c < '0' || c > '9') y = c,c = gc;
while(c >= '0' && c <= '9') x = x * 10 + c - '0',c = gc;
return y == '-' ? -x : x;
}
inline void prt(li x){
if(x >= 10) prt(x / 10);
pc(x % 10 + '0');
}
inline void print(li x){
if(x < 0) pc('-'),x = -x;
prt(x);
}
li n,m,a[12],f[62][1030][12],p,c[15][15],wei[1030],ni[15],nj[15];
inline li zh(li q,li w){
if(w > q || w < 0) return 0;
q %= mo;
li ans = 1;
for(li i = q;i > q - w;--i) (ans *= i % mo) %= mo;
return ans * nj[w] % mo;
}
inline li wk(){
li ans = 0;
for(int i = 0;i < p;++i){
li w = n;
for(int j = 1;j <= m;++j) if(i & (1 << j - 1)) w -= a[j] + 1;
li q = zh(w + m - 1,m - 1);
if(wei[i] & 1) ans = (ans - q + mo) % mo;
else (ans += q) %= mo;
}
return ans;
}
int main(){
int i,j,k,l,g,h;
n = read();m = read();p = 1 << m;
ni[1] = 1;for(i = 2;i <= m;++i) ni[i] = (mo - mo / i * ni[mo % i] % mo) % mo;
nj[0] = 1;for(i = 1;i <= m;++i) nj[i] = nj[i - 1] * ni[i] % mo;
for(i = 1;i < p;++i) wei[i] = wei[i >> 1] + (i & 1);
for(i = 1;i <= m;++i) a[i] = min(n,read());
c[0][0] = 1;
for(i = 1;i <= m;++i){
c[i][0] = 1;
for(j = 1;j <= i;++j) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
}
f[60][p - 1][0] = 1;
for(i = 60;i;--i){
for(j = 0;j < p;++j){
int q = 0,r = m - wei[j];
for(k = 1;k <= m;++k) if((j & (1 << k - 1))){
if((a[k] >> i - 1) & 1) q |= (1 << k - 1);
}
for(k = 0;k < m;++k) if(f[i][j][k]){
f[i][j][k] %= mo;
for(g = q;;g = (g - 1) & q){
l = k * 2 + ((n >> i - 1) & 1) - wei[g];
for(h = wei[g] & 1;h <= r && h <= l;h += 2){
if(l - h >= m) continue;
(f[i - 1][j ^ q ^ g][l - h] += f[i][j][k] * c[r][h]) %= mo;
}
if(!g) break;
}
}
}
}
li ans = 0;
for(i = 0;i < p;++i) (ans += f[0][i][0]) %= mo;
print((wk() - ans + mo) % mo);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 5464kb
input:
808985772338861653 10 537054254993504239 107875284824094719 720567109909741567 986287218882476031 279223142536838655 971506415346581503 285977871954444286 716072332153569279 138484571847983087 144097595331969007
output:
671774665
result:
ok single line: '671774665'
Test #2:
score: 0
Accepted
time: 6ms
memory: 7464kb
input:
924657546927630854 10 287632223299934207 432344464715411455 143338657837637567 144115179483823999 252060831913606015 283726774108127229 144112834433773567 684406266285438419 288089634636788215 274067497483763199
output:
47065446
result:
ok single line: '47065446'
Test #3:
score: 0
Accepted
time: 3ms
memory: 4928kb
input:
970108760864057432 10 863564677651603455 414014502074306519 558446353771886063 285943113865494525 539306051081580498 720522476592824249 574208952337432491 215855916606554111 351280212588100607 144115151568625599
output:
866044075
result:
ok single line: '866044075'
Test #4:
score: 0
Accepted
time: 6ms
memory: 3812kb
input:
896148723147205162 10 684547143291109369 576443105893399743 431782545487489263 720575940374036479 144115188036009946 862439328372883455 936712300825395198 718324140028590975 494833008923016191 576458466038644731
output:
611302889
result:
ok single line: '611302889'
Test #5:
score: 0
Accepted
time: 3ms
memory: 4060kb
input:
982107138086928565 10 720294224850714111 968256327597424637 864673398830135789 53902457499025406 238690780250241021 567417269143990271 719450040472436479 432046496930594815 576320003792437241 864691127381262319
output:
737473983
result:
ok single line: '737473983'
Test #6:
score: 0
Accepted
time: 5ms
memory: 3968kb
input:
910372358545407379 10 711564300111576831 432345564227567579 702419567430791163 539860174878274431 108086248248827766 287944503128489983 719448940692340215 855683929200393979 576459498172968951 837669529616381935
output:
485453553
result:
ok single line: '485453553'
Test #7:
score: 0
Accepted
time: 3ms
memory: 5160kb
input:
899526777818223481 10 134825414177579007 828660132278663166 143833713081580791 570822422315392991 711005791171117047 288220134802128895 394908292810799039 283726226231394303 575897784096354283 287103307946622943
output:
607472884
result:
ok single line: '607472884'
Test #8:
score: 0
Accepted
time: 3ms
memory: 3640kb
input:
606648262149377254 10 861278233489833975 864691128454987771 999799117242694015 414260758317104623 720574840867630751 431219660025753599 963770320257277695 846622852735041535 864655907542171134 396316179871825783
output:
30181115
result:
ok single line: '30181115'
Test #9:
score: 0
Accepted
time: 6ms
memory: 3908kb
input:
741554235168879019 10 143829293577797631 432345563153821695 144115188075855869 864128109781712759 358027371187517439 142989288168873951 431773818181123709 864620759710956543 567453553048607743 576460734586683391
output:
882763144
result:
ok single line: '882763144'
Test #10:
score: 0
Accepted
time: 0ms
memory: 4524kb
input:
859967918750172344 10 860187528825135071 274433635359063807 682295334805659647 711564343075921871 575330454214762495 125537839277400799 701717116939664887 287667151051948026 864620754879118847 426434555088470001
output:
236845469
result:
ok single line: '236845469'
Test #11:
score: 0
Accepted
time: 6ms
memory: 4060kb
input:
305713306654480092 10 702561541865471999 702508765311663581 288195174595559103 142989146435092475 144114500847499263 990721549267894271 571957151602179455 968132014089632767 360285496212971455 117092486437895679
output:
394703245
result:
ok single line: '394703245'
Test #12:
score: 0
Accepted
time: 3ms
memory: 4212kb
input:
867723840588034951 10 139584925291511807 430023326412832757 142980491002117375 864514588118347775 432064087103240191 972777518429896703 576446181626601471 144110702519386111 863969848156209023 720496766952126463
output:
712654450
result:
ok single line: '712654450'
Test #13:
score: 0
Accepted
time: 4ms
memory: 6112kb
input:
875320854870799524 10 270213769894518719 576460751229419487 846667658970529725 718324121238101995 567383124174897151 123829195313757183 288230307363026943 288225973810233343 144115119356379133 860178595161571295
output:
587505439
result:
ok single line: '587505439'
Test #14:
score: 0
Accepted
time: 3ms
memory: 4512kb
input:
649397410983667284 10 864655944083045339 142910123330748415 260852193022640127 431764463742348031 144114912107429887 432341166180005595 716071241240227711 241353793117618175 128352589354891261 684265664087588863
output:
436583059
result:
ok single line: '436583059'
Test #15:
score: 0
Accepted
time: 5ms
memory: 3620kb
input:
234851007055776066 10 180106597404245503 575888937537502013 144110789861571583 972777510922092351 962063878177423353 288080840420753398 576144092954623935 125817098319429375 574771765004206063 719865647254593535
output:
138730012
result:
ok single line: '138730012'
Test #16:
score: 0
Accepted
time: 5ms
memory: 3872kb
input:
556849612770284042 10 432343261856661247 432275056431718397 288224740617747419 283726767934405631 863564129036664799 575334573138629627 143763339925520319 556190121003318271 999797742614085614 288230376151710971
output:
268348136
result:
ok single line: '268348136'
Test #17:
score: 0
Accepted
time: 0ms
memory: 4692kb
input:
695465586724717083 10 720465984921534335 432341028741054367 556190155933745142 144113126223114239 288212781817626622 576319426251453951 288194057907187583 684193098460298239 575897801813064637 256705178759069695
output:
132744040
result:
ok single line: '132744040'
Test #18:
score: 0
Accepted
time: 2ms
memory: 3888kb
input:
620351445735575934 10 972707148620365823 243051305926377471 990789710399930333 576458484560691167 144044801883373567 265694785828782079 720574565989548031 720575940358307837 431976119730434047 936673955563929305
output:
673908976
result:
ok single line: '673908976'
Test #19:
score: 0
Accepted
time: 5ms
memory: 3924kb
input:
407985466109363151 10 851004407442030463 576381587432669151 864128178484936703 706497793496645374 423232811856035199 576460202010738679 144097594816068093 999763640779276287 998672083498041343 575845025791868893
output:
620827119
result:
ok single line: '620827119'
Test #20:
score: 0
Accepted
time: 6ms
memory: 3788kb
input:
607326936971725833 10 576425566857559031 720153693554466711 720571542332765631 862420631707123695 252201508800561151 123844179389317118 574208917844787199 720425013080944639 864690509979836411 576460683500060671
output:
414355310
result:
ok single line: '414355310'
Test #21:
score: 0
Accepted
time: 3ms
memory: 4256kb
input:
713852164734758460 10 432345527719559135 144115153716116667 72057559099375487 216168384000155615 144115183780888303 846346872128765950 124411389883054079 575334852395532247 828569971922550783 998673183009667071
output:
287975185
result:
ok single line: '287975185'
Test #22:
score: 0
Accepted
time: 6ms
memory: 4116kb
input:
293663230801159679 10 418482783915080063 576315612473065215 144105841924702201 252060807007825911 287939966569242494 143411499559812863 540361414724747135 142989279579062207 284852637709368027 432064054891113469
output:
626942160
result:
ok single line: '626942160'
Test #23:
score: 0
Accepted
time: 6ms
memory: 4516kb
input:
938417294416767636 10 999790321179033591 143550854067126271 557742666352164863 576460752303419391 864549832620506877 360002028421766654 251849709633667071 501586208333750271 141722650737770495 716072340750696447
output:
4656943
result:
ok single line: '4656943'
Test #24:
score: 0
Accepted
time: 3ms
memory: 5064kb
input:
981322818410627273 10 141300438270738431 720575390606678015 432204826604961279 566323255095312103 846676581224021887 144114084259708859 576161680811884415 430093762090106367 432064089242206191 855648744826189822
output:
848987447
result:
ok single line: '848987447'
Test #25:
score: 0
Accepted
time: 6ms
memory: 4576kb
input:
954038748613086779 10 575897802350002159 566820233277210623 857724622512062463 135107988819016694 143549695501792479 859906033986564095 270215977104834541 648518342046366719 863494845778296831 396176029715922943
output:
875944523
result:
ok single line: '875944523'
Test #26:
score: 0
Accepted
time: 6ms
memory: 3528kb
input:
147482595591949776 10 144115188075855487 287948901164515327 141705058578399231 900293280468008414 717190526897389567 564075853328115583 432046445525007871 576460752303423487 287667425661271415 504400954947235703
output:
7571069
result:
ok single line: '7571069'
Test #27:
score: 0
Accepted
time: 3ms
memory: 4212kb
input:
951036547963012560 10 700855064390006783 718244838280241151 431217190419558383 911974320068853755 720540752785965055 432344464699158527 538180155391073791 143816110108572637 711563243566379007 684547066042515423
output:
878954197
result:
ok single line: '878954197'
Test #28:
score: 0
Accepted
time: 7ms
memory: 6816kb
input:
835688570839325946 10 141863388194537470 144114911050465277 819655132181405597 558270431916720111 270215977105358847 108081992993603583 864405253148041215 683878631700659711 72057594037927935 144114603893186429
output:
217414194
result:
ok single line: '217414194'
Test #29:
score: 0
Accepted
time: 7ms
memory: 5148kb
input:
916039546837021081 10 288212783428796159 288230371784392431 709879066622164991 576460752169205723 431773817979762667 928867416702713855 144112937504341951 720564945221042167 414251717278826495 288229688956927963
output:
599122964
result:
ok single line: '599122964'
Test #30:
score: 0
Accepted
time: 5ms
memory: 3784kb
input:
103123584726792230 10 141858988068102141 720557794008236029 126083163020459007 643996274050850559 395118298997387166 716034953866379135 702561541869797111 414287185252974591 863420093013344247 135107713943207927
output:
330034265
result:
ok single line: '330034265'
Test #31:
score: 0
Accepted
time: 6ms
memory: 4296kb
input:
806509523783117696 10 720575923056802814 432270711537467391 864691042530619391 423332866206662639 142426200776638387 198158375014359039 864691128455134143 558445528556208127 864128156439673851 288230307398660091
output:
98026139
result:
ok single line: '98026139'
Test #32:
score: 0
Accepted
time: 6ms
memory: 4200kb
input:
951496385974800100 10 828099377185406655 249386829231407099 124112563305643007 863776197341872111 720012989351853055 431782614273622015 720575797080850427 612485151275737086 864691058627833829 139607050815537103
output:
119243704
result:
ok single line: '119243704'
Test #33:
score: 0
Accepted
time: 5ms
memory: 3956kb
input:
304721681710213099 10 414326765524090877 468374359099047935 142971103277203135 576443160117346303 571816140309266431 718323865549271023 144106391896719231 715790848582746111 287104476236480511 864672983828594559
output:
445062459
result:
ok single line: '445062459'
Test #34:
score: 0
Accepted
time: 7ms
memory: 4884kb
input:
933643869014326370 10 423265659765391063 539869004222693335 215888556205924287 576460750155939375 422194529072709307 431923350688759743 989666018097883135 72048797944905727 720575785760456663 432345272169267166
output:
512270961
result:
ok single line: '512270961'
Test #35:
score: 0
Accepted
time: 5ms
memory: 3644kb
input:
469306929526673045 10 846676177362878463 540291204911185907 144110789890883519 540427539919666943 432187216232447487 276971299234889727 858498129211686911 431078102198517759 711426904124289007 414190376555904511
output:
569375280
result:
ok single line: '569375280'
Test #36:
score: 0
Accepted
time: 6ms
memory: 4156kb
input:
980976240632989497 10 412070534914232319 684406405402132215 549157403609759677 864681232850485247 716072306121637885 288229542928051967 576460477154981823 711567632342351871 575334778156350975 277956529699553279
output:
790120349
result:
ok single line: '790120349'
Test #37:
score: 0
Accepted
time: 6ms
memory: 4076kb
input:
924103083796142298 10 864691128455133183 432334431571673087 144115179485659135 573927475607699447 648518037103689599 864128109782228991 287525967147039735 864620750919172093 863142466327412734 566327375915122671
output:
434786762
result:
ok single line: '434786762'
Test #38:
score: 0
Accepted
time: 6ms
memory: 4508kb
input:
964264507448995512 10 36020000891076479 567383184304488447 864691051145723901 864603098259127295 576460752302374903 684538347267288703 711557740903784190 720575115711938303 143411500633017339 432310377640877023
output:
881045449
result:
ok single line: '881045449'
Test #39:
score: 0
Accepted
time: 2ms
memory: 4404kb
input:
964264507448995512 10 36020000891076479 567383184304488447 864691051145723901 864603098259127295 576460752302374903 684538347267288703 711557740903784190 720575115711938303 143411500633017339 432310377640877023
output:
881045449
result:
ok single line: '881045449'
Test #40:
score: 0
Accepted
time: 5ms
memory: 3532kb
input:
310532155123276873 10 701857854422646527 432336768121960447 485544231736164351 863565056714997759 990791918013054975 432309821509730043 864691111006796799 864682332361588735 711568687437184991 566327575697948671
output:
25063641
result:
ok single line: '25063641'
Test #41:
score: 0
Accepted
time: 6ms
memory: 4960kb
input:
879732870392342279 10 288195123059883999 432345564227362815 143552237853999103 432310053404401403 504394356803464703 716063407219900407 288195189631481851 432345014433918975 350997023346392573 574206751302221551
output:
145845189
result:
ok single line: '145845189'
Test #42:
score: 0
Accepted
time: 5ms
memory: 3716kb
input:
976814225185438104 10 711285066856136185 34902896976849855 693272583633106687 540431944269692907 576308931639375870 999658239663996415 863283751155661303 767863598725701375 576460752303422462 864690577558140927
output:
738959157
result:
ok single line: '738959157'
Test #43:
score: 0
Accepted
time: 3ms
memory: 4792kb
input:
980529855612510079 10 720293639158235133 683974843112095487 432336630556131327 126091993473318911 414322368551255935 564919587772954079 430938189343997935 862404075549359839 576425567926747135 396314567581097631
output:
267834235
result:
ok single line: '267834235'
Test #44:
score: 0
Accepted
time: 0ms
memory: 5624kb
input:
731387326627617555 10 576424466272204767 567380976288127999 720505562491500543 988258565921439739 709316666432421247 144114908613558207 126098590543118335 648515541727575551 270213778551715583 144077804679725049
output:
371627183
result:
ok single line: '371627183'
Test #45:
score: 0
Accepted
time: 4ms
memory: 6456kb
input:
995159452232910067 10 213916375945576415 432345563657125611 557319766558105599 288230238670782415 936713503760711167 285978575935368959 144115188059059199 123558716535254233 562668477236116991 144114912929513471
output:
246439225
result:
ok single line: '246439225'
Test #46:
score: 0
Accepted
time: 3ms
memory: 3788kb
input:
532418565171229182 10 285837838849539839 720575940245061631 864686721281814525 864673501909213183 711568740587558903 504332514643279535 288221580058423295 108084123311407103 719399325498564607 432345546913464310
output:
762239757
result:
ok single line: '762239757'
Test #47:
score: 0
Accepted
time: 3ms
memory: 4492kb
input:
991794541064181104 10 269087328922689527 699166249946447871 287667425795637247 90070343168802815 990791917883097087 863565228279852783 288087431050166271 716072334307885051 720505566266376055 144115084996607987
output:
528893053
result:
ok single line: '528893053'
Test #48:
score: 0
Accepted
time: 6ms
memory: 3652kb
input:
648365292795555962 10 855683920602071023 720575647784624126 702559342792015767 990774308651401199 144097046117218301 863489362245409279 647891624713519095 432200428423016447 575897527466819547 432345546980589559
output:
106481983
result:
ok single line: '106481983'
Test #49:
score: 0
Accepted
time: 2ms
memory: 5164kb
input:
997651518570963253 10 576460679087635167 270074825689527283 716051956702898175 432345555637633023 576354649162841855 567453518420508399 144106391972343611 396279383276388351 576460752284483325 432343360909344767
output:
722471127
result:
ok single line: '722471127'
Test #50:
score: 0
Accepted
time: 2ms
memory: 3592kb
input:
6 3 2 3 4
output:
4
result:
ok single line: '4'