QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#148433#6647. 老虎机275307894aAC ✓1307ms173124kbC++142.0kb2023-08-23 16:09:072023-08-23 20:22:18

Judging History

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

  • [2023-08-23 20:22:18]
  • 评测
  • 测评结果:AC
  • 用时:1307ms
  • 内存:173124kb
  • [2023-08-23 16:09:07]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=15+5,M=(1<<15)+5,K=14348907+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,k,m,Po[N];ll p[N],f[M],ans[M],S1[M],S2[M];char s[N];
ll mpow(ll x,int y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
const int inv=mpow(10000);
int tg[K],g[K],lob[K];
void Solve(){
	int i,j,h;scanf("%d%d",&k,&n);m=1<<k;
	for(i=0;i<k;i++) scanf("%lld",&p[i]),p[i]=p[i]*inv%mod;
	for(i=0;i<m;i++) {
		S1[i]=1;
		for(j=0;j<k;j++) if(i>>j&1) S1[i]=S1[i]*p[j]%mod;
		S2[i]=1;
		for(j=0;j<k;j++) if(i>>j&1) S2[i]=S2[i]*(mod+1-p[j])%mod;
	}
	Me(f,0);Me(tg,0);
	f[0]=1;
	ll tot=0;
	for(i=0;i<m-1;i++){
		ll q=1;for(j=0;j<k;j++) if(!(i>>j&1)) q=q*(mod+1-p[j])%mod;
		f[i]=f[i]*mpow(mod+1-q)%mod;tot+=f[i];
		int x=(m-1)^i;
		for(j=x;j;j=(j-1)&x){
			f[i|j]=(f[i|j]+f[i]*S1[j]%mod*S2[x^j])%mod;
		}
	}
	for(Po[0]=i=1;i<=k;i++) Po[i]=Po[i-1]*3;
	for(i=1;i<=n;i++) {
		scanf("%s",s);int x=0;
		for(j=0;j<k;j++) if(s[j]=='1') x+=Po[j];
		tg[x]=i;
	}
	Me(ans,0);
	for(i=0;i<Po[k];i++){
		if(!g[i]) continue;
		int p=lob[i],a=tg[i-Po[p]],b=tg[i-Po[p]*2];
		if(a==-1||b==-1||(a&&b)) tg[i]=-1;
		else{
			tg[i]=a+b;
			if(tg[i]) ans[tg[i]]-=f[(m-1)^g[i]];
		}
	}
	for(i=1;i<=n;i++) printf("%lld\n",(ans[i]+tot)%mod);
}
void init(){
	for(int i=0;i<14348907;i++) g[i]=g[i/3]<<1|(i%3==2),lob[i]=(i%3==2?0:lob[i/3]+1);
}
int main(){
	int t;init();
	scanf("%d",&t);
	// t=1;                                                                                       
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 1192ms
memory: 173016kb

input:

10
15 662
5038 7472 8988 9724 4995 8209 3006 2436 5397 5524 3147 6106 5676 4188 475
001000000000000
001100100000000
001001100000000
111101010000000
001000110000000
110100110000000
001010110000000
000011110000000
010100001000000
010101001000000
010100101000000
000100011000000
101010011000000
11110101...

output:

518515975
441489874
976886960
416444928
595227104
46012178
797449033
961302534
914464702
434861836
617605937
914318450
405151330
474718515
488261669
811373697
670339755
553323392
396910827
471815519
942209546
218470235
616195895
142386446
915907545
897988389
960289896
710396188
53012859
616397693
45...

result:

ok 8048 numbers

Test #2:

score: 0
Accepted
time: 1240ms
memory: 173016kb

input:

10
15 945
4533 2777 9280 7591 8666 8332 3817 3563 188 5629 223 8614 9945 169 4126
000000000000000
100010000000000
010101000000000
010011000000000
000100100000000
011010100000000
000101010000000
000110110000000
010100001000000
100100101000000
011100101000000
100010101000000
101101101000000
1001001110...

output:

468895036
488499485
73155183
313099907
570399196
746114537
473592009
843050096
943627902
809971121
279997919
119911965
166020976
162545224
6714491
237472254
399402567
415389488
803509893
195386997
971333619
959307063
754151523
715671390
306832155
247766942
983377648
770074292
977962086
199103029
657...

result:

ok 11154 numbers

Test #3:

score: 0
Accepted
time: 1307ms
memory: 173016kb

input:

10
15 1610
7476 5694 8655 3700 2498 9364 9388 8720 867 9409 9266 1180 4651 9826 8521
000101000000000
111111000000000
001100100000000
101010100000000
100010010000000
011010010000000
001001010000000
100101010000000
010101010000000
100011010000000
010010110000000
111110110000000
110101110000000
0000000...

output:

695847883
866666833
151680745
254702835
278731520
282495318
461916297
414498398
551452590
312657262
690845761
956152086
339467568
250278827
566153019
629324598
540139262
845078604
404786324
88283686
947860436
523007492
462852108
371674549
165046694
308261943
220452328
186951433
309185219
755395796
8...

result:

ok 17780 numbers

Test #4:

score: 0
Accepted
time: 1238ms
memory: 173012kb

input:

10
15 3332
4589 9436 3291 400 1522 7087 2090 6055 5423 2021 6736 9127 6459 7907 9469
010010000000000
001101000000000
100011000000000
000111000000000
110111000000000
111000100000000
000100100000000
010110100000000
001001100000000
101001100000000
011101100000000
000000010000000
101000010000000
0100100...

output:

62081795
95804054
777619450
563379359
109107623
100329408
267979341
901644200
779751121
559146832
406650879
647322387
846940656
630986451
616411325
83123021
394094716
70006260
933808103
663366266
945745153
566130099
996235960
810087727
230637522
413973815
130152979
511507434
219400090
688865016
6259...

result:

ok 47271 numbers

Test #5:

score: 0
Accepted
time: 1052ms
memory: 172976kb

input:

10
15 6474
2891 6989 5736 3876 8676 2208 177 3034 6059 1982 6497 9229 288 4182 3574
111100000000000
110010000000000
010110000000000
111110000000000
110001000000000
011001000000000
101111000000000
011111000000000
001000100000000
010100100000000
001100100000000
011010100000000
100110100000000
11011010...

output:

225258451
776361832
85737572
677656463
683289382
770355753
735559690
859475762
933130708
299277092
59373303
622607898
482620327
768328714
250013721
504808565
399471634
590126752
88091761
285800769
913111555
968428082
539091898
200811015
385870745
591273975
1945708
164724882
350907522
739668945
72230...

result:

ok 95126 numbers

Test #6:

score: 0
Accepted
time: 815ms
memory: 173016kb

input:

10
15 16554
9863 5384 5246 673 9186 36 1721 1840 7430 6147 2984 2536 2171 7007 5917
100000000000000
001000000000000
011000000000000
000100000000000
011100000000000
000010000000000
010010000000000
110010000000000
001010000000000
101010000000000
000110000000000
010110000000000
110110000000000
00111000...

output:

359449432
347869278
950160256
692539196
158343762
528693165
84666450
367359549
500250254
716904999
532508339
873732132
503868313
236435126
512432505
378248297
824496858
674490286
59979008
441623864
89603292
277297928
573697328
54579538
771050423
93875736
316625940
274496904
953043310
129513994
85764...

result:

ok 207722 numbers

Test #7:

score: 0
Accepted
time: 919ms
memory: 173048kb

input:

10
15 31
370 7055 5794 5780 5105 8113 9658 5692 2155 186 1409 3492 912 834 6359
110100010000000
101101001100000
011001110010000
010110111110000
111100011001000
100010101111100
100110110101010
110110001010110
011110001011110
001101101111110
100100111111110
010101010110001
110110001110001
011000110001...

output:

697620535
461603366
952160183
789486629
699790052
791611840
696059912
395966174
982917002
948360471
554451480
352880705
376781300
817700435
557142106
478984754
983544739
218377225
326535910
812400089
655162561
363190360
225373231
196456871
142861635
408941719
317760556
773781321
252514290
243448014
...

result:

ok 147661 numbers

Test #8:

score: 0
Accepted
time: 914ms
memory: 172976kb

input:

10
15 3266
2366 3787 9081 5571 4276 2141 8969 6126 1343 4664 4882 7035 8858 2962 176
110010000000000
111010000000000
000110000000000
010110000000000
000011000000000
011011000000000
111111000000000
100101100000000
010101100000000
001111100000000
101111100000000
011111100000000
111111100000000
1001000...

output:

336415702
423201060
622112899
631183951
727425470
129628919
610511516
545941034
140782579
344045218
805309332
151772369
565343550
930401029
938895358
430994628
918453017
185040521
888383524
319452117
265019565
605439428
484849785
871366437
907973912
279816246
456841097
40489076
401287827
838074133
2...

result:

ok 179926 numbers

Test #9:

score: 0
Accepted
time: 69ms
memory: 172972kb

input:

10
11 240
3099 5395 7933 4165 6905 155 9024 4868 4471 3265 6006
10100000000
00110000000
01101000000
00000100000
01110100000
10101100000
01111100000
01000010000
10100010000
11100010000
00101010000
01101010000
00100110000
01110110000
11001110000
10111110000
11100001000
10110001000
00010101000
11010101...

output:

910360647
569857716
507357938
45293331
881028167
37463947
729896278
433696051
786100773
911932692
328879997
2174731
607011773
786860164
324474313
406583561
672064698
38714763
708892496
52561550
979735571
189529813
505930214
451591117
435916230
710695287
874331292
354755770
87987455
326252361
1608961...

result:

ok 1756 numbers

Test #10:

score: 0
Accepted
time: 168ms
memory: 172788kb

input:

10
8 6
8831 7735 1885 7922 8373 3405 2193 1081
01001000
10101010
11011001
11001101
11100011
10001011
8 6
8941 6552 7498 1714 8756 8902 4361 3446
11001000
01000110
00100110
01101001
11101101
00101111
9 12
3811 4401 6483 9951 5123 8336 9231 1287 8917
001100000
101010000
100010100
011011100
101010110
0...

output:

699125565
472393958
179781506
926071922
881327256
569318703
483589877
201206499
335825567
662295298
287110811
486321046
678767029
133583455
317452494
347293909
116930041
88476056
311960804
597087075
727443005
707346792
807854893
25428919
0
494747342
494747342
103662337
473150639
703324191
469990323
...

result:

ok 1396 numbers

Test #11:

score: 0
Accepted
time: 123ms
memory: 173120kb

input:

10
9 271
5967 534 3870 6710 6136 7395 9660 6281 6908
000000000
100000000
010000000
110000000
001000000
000100000
100100000
110100000
001100000
000010000
100010000
110010000
011010000
111010000
010110000
001110000
111110000
000001000
100001000
110001000
001001000
111001000
100101000
110101000
0111010...

output:

951951842
528691978
657311412
689727086
791716876
448620554
952230933
344708660
891755107
292232452
837545786
768003680
327052793
236419739
199145098
368715508
242665162
865475839
689727086
72308273
290017768
702543969
810894812
36434632
882335024
897509799
380805590
165489868
111712706
237450950
86...

result:

ok 24008 numbers

Test #12:

score: 0
Accepted
time: 728ms
memory: 173116kb

input:

10
15 2703
3064 5292 7904 3159 9249 8440 7665 2033 9168 8842 9571 5832 2570 2216 8309
111100000000000
111010000000000
110110000000000
101110000000000
011110000000000
111001000000000
110101000000000
101101000000000
011101000000000
110011000000000
101011000000000
011011000000000
100111000000000
010111...

output:

293014159
497856417
317419191
337190889
952232477
929101562
627747465
478930541
858488537
775013884
933533400
437559456
989147832
749509700
675012980
423360437
752070922
132711205
624960958
848924676
548278696
841792573
48567922
540802869
658309717
631678440
974542436
777219853
426129496
592472014
2...

result:

ok 27026 numbers

Test #13:

score: 0
Accepted
time: 790ms
memory: 173088kb

input:

10
15 2325
9065 6772 2790 3411 4425 2965 9181 5267 8165 2310 4144 8316 3210 2047 1693
111100000000000
111010000000000
110110000000000
101110000000000
011110000000000
111001000000000
110101000000000
101101000000000
011101000000000
110011000000000
101011000000000
011011000000000
100111000000000
001111...

output:

244517396
708537205
816816
825169164
475595161
347479943
452626401
507774557
789301567
512656395
729865162
650056000
132569210
326873306
615979310
295848586
461753764
887238230
88176839
570204662
852111345
233490468
458262952
242436950
415575453
372551800
930041729
895837974
648219905
467568998
9202...

result:

ok 23140 numbers

Test #14:

score: 0
Accepted
time: 715ms
memory: 173024kb

input:

10
15 9796
2950 394 5271 3957 6357 8734 9284 3228 6353 5460 7840 8192 3112 2789 5687
111111000000000
111110100000000
111101100000000
111011100000000
110111100000000
101111100000000
011111100000000
111110010000000
111101010000000
111011010000000
110111010000000
101111010000000
011111010000000
1111001...

output:

248249845
867585010
948128745
983768131
267318091
124167884
713438438
244872148
312066088
1689550
587079541
832558778
910218043
696878097
912150751
813238890
51459960
585656515
186908819
540707392
886467615
311482119
847188209
686723199
293626228
70086705
597097411
641229591
152244088
819887735
6956...

result:

ok 98095 numbers

Test #15:

score: 0
Accepted
time: 718ms
memory: 173016kb

input:

10
15 12522
4326 4687 8707 3200 1333 4201 9355 3246 3652 6211 679 3694 1704 6920 5310
111111100000000
111111010000000
111110110000000
111101110000000
111011110000000
110111110000000
101111110000000
011111110000000
111111110000000
111111001000000
111110101000000
111101101000000
111011101000000
110111...

output:

164932777
199927135
569002197
472360455
77449125
583304233
354344997
61988838
154243626
609162382
832022844
940988846
805902763
759156036
978941219
622958572
307473848
478614621
937764288
946152748
957613153
708940873
743453384
778770631
861193720
272053207
521113252
715489515
54524565
111092968
676...

result:

ok 124816 numbers

Test #16:

score: 0
Accepted
time: 759ms
memory: 173012kb

input:

10
15 862
3238 5190 1298 1676 9728 6832 805 9325 4203 9251 5768 9342 7108 8645 8665
111000000000000
110100000000000
101100000000000
011100000000000
110010000000000
101010000000000
011010000000000
100110000000000
010110000000000
001110000000000
110001000000000
101001000000000
011001000000000
10010100...

output:

277931631
938474977
757195940
596883260
402056318
970727573
70581903
348154271
517911214
847101490
618386860
516691804
789188502
802949898
678898222
393198812
112937639
171104479
38525270
650759128
567139457
459335642
215112873
20014642
315817180
116343870
743335087
614093892
898387739
792650410
523...

result:

ok 8633 numbers

Test #17:

score: 0
Accepted
time: 228ms
memory: 173048kb

input:

10
12 132
7974 5623 9702 2227 8116 6865 980 6282 7919 7486 2122 1993
110000000000
101000000000
011000000000
100100000000
010100000000
001100000000
100010000000
010010000000
001010000000
000110000000
100001000000
010001000000
001001000000
000101000000
000011000000
100000100000
010000100000
0010001000...

output:

814859054
52102400
498138814
71010534
318764722
147514556
780871350
801167175
419955605
592443836
759139366
102392099
395965070
697323765
215453924
455783532
794118034
234941311
170880687
118010349
325743070
79151198
859581322
649715188
453138288
732359106
847390699
153670693
337120038
481968345
859...

result:

ok 11812 numbers

Test #18:

score: 0
Accepted
time: 200ms
memory: 173124kb

input:

10
14 5720
2118 3564 6317 8033 4765 8143 6534 9490 8169 4294 5731 8692 9890 9146
11111100000000
11111010000000
11110110000000
11101110000000
11011110000000
10111110000000
01111110000000
11111001000000
11110101000000
11101101000000
11011101000000
10111101000000
11110011000000
11101011000000
110110110...

output:

281326753
889779028
623191157
618713150
7758803
927102473
781432708
79475264
729594777
665208426
839247877
122477458
988808572
994971359
232379298
243266699
427232469
415169392
87422113
922502393
325913519
361387526
239694763
153466032
143154386
182289126
565484404
51127285
14051570
325361960
539364...

result:

ok 13880 numbers

Test #19:

score: 0
Accepted
time: 211ms
memory: 172968kb

input:

10
12 1995
2243 2731 4986 6548 2360 3997 7159 9434 2754 9841 5777 6348
000000000000
010000000000
101000000000
111000000000
010100000000
110100000000
001100000000
101100000000
111100000000
000010000000
100010000000
011010000000
111010000000
100110000000
101110000000
011110000000
000001000000
10000100...

output:

751755530
767656452
223619929
599634170
113592957
440208418
975108311
716133146
786702347
748992069
849962072
748633952
39694174
123775
379276730
131526830
973997127
573718680
773251384
404474559
190453259
547653127
62163933
74474220
317773634
469134034
824552273
484276116
446156856
919336174
254993...

result:

ok 35483 numbers

Test #20:

score: 0
Accepted
time: 83ms
memory: 172592kb

input:

10
8 124
6412 9064 7325 4488 4373 3510 1203 4155
01000000
00100000
00010000
01010000
10110000
01110000
11110000
00001000
11001000
00101000
11101000
00011000
00111000
10111000
01111000
11111000
01100100
11100100
01010100
01110100
11001100
00101100
00011100
10011100
01011100
11011100
00000010
01000010...

output:

331906138
591042739
258005841
933335804
440292306
668621297
131173881
879680865
568659812
820234102
589419673
711159114
91214738
529361733
786698082
653088985
209573579
897321895
392308438
335489756
541910532
139861374
282139693
790137422
915161173
463526018
975365968
445900149
679675310
612013841
5...

result:

ok 13782 numbers

Test #21:

score: 0
Accepted
time: 714ms
memory: 173084kb

input:

10
15 32768
6170 7346 4714 7007 5420 2165 7677 4267 3519 1688 3403 8237 3803 3076 5133
000000000000000
100000000000000
010000000000000
110000000000000
001000000000000
101000000000000
011000000000000
111000000000000
000100000000000
100100000000000
010100000000000
110100000000000
001100000000000
10110...

output:

758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
758579657
...

result:

ok 327680 numbers