QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#188627#4917. 中奖率hos_lyric#23 1351ms19892kbPython32.7kb2023-09-26 05:36:402024-07-04 02:09:32

Judging History

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

  • [2024-07-04 02:09:32]
  • 评测
  • 测评结果:23
  • 用时:1351ms
  • 内存:19892kb
  • [2023-09-26 05:36:40]
  • 提交

answer

from functools import *
import sys
sys.set_int_max_str_digits(10**5)

N, T = map(int, input().split())
S = input()

Y = [0 for i in range(N + 1)]
for i in range(N):
    Y[i + 1] = Y[i] + (ord(S[i]) - ord('0'))
# print(Y)
D = [0 for i in range(N)]
for i in range(N):
    D[i] = N * Y[i] - Y[N] * i
# print(D)

# sub2
def cmp(a, b):
    d = a[0] * b[1] - a[1] * b[0]
    if (d > 0):
        return -1
    if (d < 0):
        return +1
    return (a[1] - b[1])
LIM_SUB2 = 1005
xs = []
if N <= 10:
    xs = [(0, 0) for i in range(N * LIM_SUB2)]
    for q in range(LIM_SUB2):
        for r in range(N):
            xs[N * q + r] = (Y[N] * q + Y[r], N * q + r)
    xs = sorted(xs, key=cmp_to_key(cmp))

for T in range(T):
    O, K = map(int, input().split())
    if (O == 1):
        if (Y[N - 1] == 0 and Y[N] == 1):
            # sub1
            print(K * N)
        elif (K < LIM_SUB2 - 1):
            # sub2
            print(xs[K][1])
        else:
            print("TODO")
    else:
        Q = K // N
        R = K % N
        if (D[R] < 0):
            print("inf")
        elif (D[R] == 0):
            hasBig = False
            for r in range(N):
                if (D[r] > 0):
                    hasBig = True
            if (hasBig):
                print("inf")
            else:
                ans = 0
                cnt = 0
                for r in range(N):
                    if (D[r] == 0):
                        cnt += 1
                        if (r <= R):
                            ans += 1
                        if (r == 0):
                            ans -= 1
                ans += cnt * Q
                print(ans)
        else:
            a = K // D[R]
            b = K % D[R]
            c = (Y[N] * Q + Y[R]) // D[R]
            d = (Y[N] * Q + Y[R]) % D[R]
            ans = 0
            cntA = 0
            cntC = 0
            for r in range(N):
                if (D[r] > 0):
                    # Y[r]/r >= Y[K]/K ?
                    if (Q >= ((Y[R] * r - R * Y[r]) + D[R] - 1) // D[R]):
                        # q <= (a D[R] + b) Y[r] - (c D[R] + d) r
                        cntA += Y[r]
                        cntC -= r
                        e = b * Y[r] - d * r
                        f = e // D[R]
                        ans += (f + 1)
                        if (r == 0):
                            ans -= 1
                        if (e % D[R] == 0):
                            # (a * Y[r] - c * r + f, r) > (Q, R)
                            q = a * Y[r] - c * r + f
                            if (q > Q or (q == Q and r > R)):
                                ans -= 1
            ans += cntA * a
            ans += cntC * c
            print(ans)

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 79ms
memory: 16368kb

input:

93594 19
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

803592238894397000180010742478410576139869323112765266001511168406933953751236048305575854734087992434865734898666775073462056595681265138821122297618629090129568166018988058397842512784043408247048475083486672197520209680936205310495190027161434933868319162317581353076485586012510746832534790123318...

result:

ok 19 tokens

Test #2:

score: 0
Accepted
time: 60ms
memory: 16336kb

input:

91106 19
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

inf
inf
inf
inf
13250042107896464722639737551541466942179901318817839832766590049487752727865912250795382770204236165270082111796839055561744227636073331650212700910581348097835459150251688363718468552900251250148301582337176568548165076825749090832639499887382431511630515262690992013373658775659429...

result:

ok 19 tokens

Test #3:

score: 0
Accepted
time: 70ms
memory: 16268kb

input:

91004 19
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

615583033926412665379213953324038024217834471026294801388188380855415202841104551684169952830165295737948000277599376689161324741020690179665753283567317214074727589342722310194779455556310818004374376474764064937590258429980614187691752943635481928305924995147441001944209678975366299644962193997878...

result:

ok 19 tokens

Test #4:

score: 0
Accepted
time: 81ms
memory: 16252kb

input:

90255 20
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

499599650596627581409270516073361171534798169651401128905539595097904284149229507117902151246635636602106763929398082171217870421053986702009355855535129786260850675383419648681127018158100775558533952949402381637753162134550874268417162202985795686214400585039764184003031446966858170110874690477358...

result:

ok 20 tokens

Test #5:

score: 0
Accepted
time: 61ms
memory: 16284kb

input:

91120 20
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

inf
79720591846983829206255887296207669486915366790122276434980101585360431827746713261002508648352372575865363390100523993630288523905911853973318127707889991724762296859274660492425147944952897963807830595800561901914978699828863421552748209566274991181115114248717641246059782816631387147071628022...

result:

ok 20 tokens

Subtask #2:

score: 9
Accepted

Test #6:

score: 9
Accepted
time: 12ms
memory: 12276kb

input:

10 19
0000000000
2 241
1 405
1 927
1 669
1 734
1 349
2 493
1 828
1 385
1 855
2 761
1 63
1 288
1 754
2 91
1 863
2 805
2 1000
1 1000

output:

241
405
927
669
734
349
493
828
385
855
761
63
288
754
91
863
805
1000
1000

result:

ok 19 tokens

Test #7:

score: 0
Accepted
time: 22ms
memory: 12504kb

input:

10 20
1111111111
2 112
2 917
1 364
1 898
1 37
2 456
2 839
1 414
1 13
1 858
2 49
2 653
2 502
1 562
1 138
2 559
2 778
2 494
2 1000
1 1000

output:

112
917
364
898
37
456
839
414
13
858
49
653
502
562
138
559
778
494
1000
1000

result:

ok 20 tokens

Test #8:

score: 0
Accepted
time: 27ms
memory: 12520kb

input:

10 20
1000000001
1 490
1 300
2 143
2 151
2 665
1 539
2 412
2 160
1 377
1 2
2 730
2 724
1 99
1 242
1 824
1 448
2 171
1 355
2 1000
1 1000

output:

1951
1191
73
40
inf
1612
139
inf
1501
2
inf
725
292
722
3291
893
44
354
inf
3991

result:

ok 20 tokens

Test #9:

score: 0
Accepted
time: 17ms
memory: 12536kb

input:

10 19
1101011111
2 84
2 777
1 278
1 396
1 795
2 487
1 102
1 408
2 502
1 786
1 419
1 431
1 722
1 826
2 66
1 545
2 334
2 1000
1 1000

output:

inf
inf
1842
2632
5292
inf
672
2712
77
5232
2782
2862
4802
2751
inf
3622
inf
inf
3331

result:

ok 19 tokens

Test #10:

score: 0
Accepted
time: 25ms
memory: 12552kb

input:

10 19
0101001111
1 718
1 477
2 994
2 205
2 432
2 650
1 358
2 497
2 22
1 549
1 506
2 856
2 564
1 891
2 2
1 970
1 211
2 1000
1 1000

output:

7180
4770
inf
inf
inf
65
3580
inf
inf
5490
5060
inf
inf
8910
inf
9700
2110
100
10000

result:

ok 19 tokens

Test #11:

score: 0
Accepted
time: 32ms
memory: 12544kb

input:

10 20
1000000000
2 219
2 205
1 392
2 750
2 415
1 768
1 997
2 833
1 354
1 565
2 106
2 552
2 336
1 865
1 319
1 343
1 576
2 945
2 1000
1 1000

output:

982
185
435
inf
374
1193
886
538
237
377
119
314
378
577
424
533
1151
851
inf
667

result:

ok 20 tokens

Test #12:

score: 0
Accepted
time: 27ms
memory: 12228kb

input:

8 20
11110110
2 831
1 724
2 234
2 180
2 86
1 419
2 862
2 587
2 393
1 169
2 606
1 370
1 555
1 498
1 222
1 321
1 142
2 698
2 1000
1 1000

output:

555
1444
234
92
86
627
862
392
785
85
606
370
831
498
222
161
142
698
inf
1499

result:

ok 20 tokens

Test #13:

score: 0
Accepted
time: 19ms
memory: 12544kb

input:

10 20
1011111111
1 204
2 208
2 915
1 290
2 331
2 426
1 685
1 744
2 374
2 28
2 832
2 72
1 264
2 93
1 791
1 995
2 687
2 715
2 1000
1 1000

output:

2031
inf
inf
2891
34
inf
6841
7431
inf
inf
inf
inf
2631
inf
7901
9941
inf
inf
inf
9991

result:

ok 20 tokens

Test #14:

score: 0
Accepted
time: 22ms
memory: 12524kb

input:

10 19
0100100010
1 316
2 321
2 229
1 947
1 734
1 656
2 42
2 467
2 729
2 414
2 146
2 766
2 514
2 218
1 757
2 279
1 980
2 1000
1 1000

output:

842
inf
115
3155
2445
2185
16
inf
365
inf
109
574
inf
inf
2515
140
1959
inf
1999

result:

ok 19 tokens

Test #15:

score: 0
Accepted
time: 24ms
memory: 12584kb

input:

10 20
1000110010
2 132
2 288
1 716
2 939
2 146
1 354
2 313
1 214
2 291
1 710
2 109
1 142
1 266
1 339
1 180
1 259
2 717
1 17
2 1000
1 1000

output:

132
inf
2146
470
49
1061
inf
641
98
1419
55
142
796
1016
359
776
717
17
inf
1999

result:

ok 20 tokens

Subtask #3:

score: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #16:

score: 0
Wrong Answer
time: 228ms
memory: 12424kb

input:

96819 19
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

TODO
TODO
747345185
TODO
669300879
348051855
803856551
TODO
48514529
TODO
TODO
100896344
42516464
542123409
541302510
128941120
763029472
1000000000
TODO

result:

wrong answer 1st words differ - expected: '699771300', found: 'TODO'

Subtask #4:

score: 13
Accepted

Test #26:

score: 13
Accepted
time: 450ms
memory: 13608kb

input:

91666 20
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

515706124162066910404299759270263525075572767596736003465355923316260588149010617187359188941516324390245173109156994742981144311903350592651694874773059936377465166504183446390352558958540404515986128670780159685531688747924073414308447680356209302719213735419339034163216206854876449919662582900737...

result:

ok 20 tokens

Test #27:

score: 0
Accepted
time: 426ms
memory: 16484kb

input:

91047 20
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

748490273573792980373170496345932289792264023510501461386640731746530837775985011360693655655538352612548991850863544262166372647195373109391450350236987371183192812616376657263677465623740226504269832462386067930101999093116909436323318899728117997747067096632539706580241112266144163828519249301668...

result:

ok 20 tokens

Test #28:

score: 0
Accepted
time: 215ms
memory: 19140kb

input:

92486 19
110100000000000000110000000000100000000000000011000001001000010000010000000000100100001000000001101000000001011100000100010000000000000010000010001001000000000000000000000010000010001101000000001010010010000001000000110001100110000100101100001001100100100000000000010000000000000001010110000...

output:

inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
65986075054599739720012701630831185271110376577710956354155795249031175809009390746092705206288087294293403254292953327740384132264386725134793857054678394086844847065095541776644414503257258213388206060729019472813862535764008464101493529685679752732762570081...

result:

ok 19 tokens

Test #29:

score: 0
Accepted
time: 291ms
memory: 19096kb

input:

90758 19
111001110101010111100000111111011011001010101101110101111111101000011100011111111010111111010110011111001010111111101110101110010110110111000011110110111001100100001010011001010001110111011110111111111101110110111001101110101100111010010111100011000101101110011011111101110111100011110111111...

output:

337152640595339377254913355446254892275950588290486782075348462146043348153437383075163218482882384949983968092847114987978727985457664584745249748842150893129020441591183196333370705055984869426758646982814357613345456867523827515149962034146732136117858448360902802565799798832441703259791269764809...

result:

ok 19 tokens

Test #30:

score: 0
Accepted
time: 54ms
memory: 19324kb

input:

95944 20
010111110111111111001111111111101111111011111011011101101110111111111101101111111111111111111111111111101011011110111111111111111111111111111110111101111111110111101110011111111111111111111101101101101111111111110110111111101111111101101111111101111111111111111111101111111111110100011101111...

output:

inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf

result:

ok 20 tokens

Test #31:

score: 0
Accepted
time: 1351ms
memory: 19480kb

input:

92585 20
110011011000101000000101010010100000000100000001110010010001100110001000100000100100000000111110001000000001000001100000110001001010000000101100000010100100001011010000001100000011000100011001000100000010010100001101000001110100001000011100010110100000100000101000010000000101000000100010010...

output:

693151164353298294991771915092246165588784011427723401514863569537180974110856679276502848848450095232556023520581621103706505329485541531644093395334224709813099430572342689943389061768308122334167396889122558885489842353859845505679740760989001467096316722773918455965593584892515339969002792035902...

result:

ok 20 tokens

Test #32:

score: 0
Accepted
time: 1191ms
memory: 19892kb

input:

100000 19
11010101011011001011010111100000010010101100101010111000101110101001010110011011010011100100011110010011010011110111000100110000001111110010101000011111010011011101001100000000101011110100100100101100101010101100110111010011000101110111010110101000010110001010111110001010110100110000001111...

output:

171664461199134562766995650684440673085489422465326109270356812483138547934706911599756894207664574188038519627617045518815980608296136814038903827336872029429200125283024307872759381900102481215772231730929597377309317705827303189555946879704202361491952110134028530508207284059394040436511100411837...

result:

ok 19 tokens

Test #33:

score: 0
Accepted
time: 195ms
memory: 19024kb

input:

90139 20
101101100100111111111011100111110110111001111101101101110111011101011100111110111010110111101110110111101011011101100111110111011011101101110111101011011101101110101111101011101100111110101111011101101110110101111001111101101110110011111011101110110110111001101111101110011111011011101101110...

output:

114295361082305127942208281911086652195193612036965258194540554839765604416562780276165239338044991656166078586296137971810820270121979910956362520343058615413830387682572956846149751679906531190159869196033901257029539803703475752647797700268137583373220831250186514085304302366054423749897416545653...

result:

ok 20 tokens

Test #34:

score: 0
Accepted
time: 61ms
memory: 19516kb

input:

98059 19
101111111111111111011011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111011111111111111111...

output:

inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf

result:

ok 19 tokens

Test #35:

score: 0
Accepted
time: 192ms
memory: 18940kb

input:

90139 20
101101100100111111111011100111110110111001111101101101110111011101011100111110111010110111101110110111101011011101100111110111011011101101110111101011011101101110101111101011101100111110101111011101101110110101111001111101101110110011111011101110110110111001101111101110011111011011101101110...

output:

114295361082305127942208281911086652195193612036965258194540554839765604416562780276165239338044991656166078586296137971810820270121979910956362520343058615413830387682572956846149751679906531190159869196033901257029539803703475752647797700268137583373220831250186514085304302366054423749897416545653...

result:

ok 20 tokens

Subtask #5:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 762ms
memory: 16656kb

input:

98506 19
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

TODO
2703886498544187712484987177912757769128873851038740691696213331814898158938010343551410181298135830176928740459581451207299445021985425025102696745207837754392528313685449043374129770731345472210115122444848771326517231678880094617268084021829966734648841069590819528041194834178022552768309776...

result:

wrong answer 1st words differ - expected: '129925218195110981928395603118...4444988083658465926564772872533', found: 'TODO'

Subtask #6:

score: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #41:

score: 0
Wrong Answer
time: 41ms
memory: 12024kb

input:

190 19
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2 3030536584264275991656446184192931032142342202853788773124469117132936126944321526393387980895665026...

output:

303053658426427599165644618419293103214234220285378877312446911713293612694432152639338798089566502665575779543814797512740930993972387315159956432349381665458354645284037027514891865835605478519158667178660184697604213917963871214214812993111821807966534988024828960583750304242594098806161798042315...

result:

wrong answer 2nd words differ - expected: '240718819323761259244088884648...0758149912664585545647515242225', found: 'TODO'

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%