QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607430#8932. BingoUESTC_NLNS#WA 439ms10576kbPython31.3kb2024-10-03 14:55:112024-10-03 14:55:16

Judging History

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

  • [2024-10-03 14:55:16]
  • 评测
  • 测评结果:WA
  • 用时:439ms
  • 内存:10576kb
  • [2024-10-03 14:55:11]
  • 提交

answer

import sys

sys.set_int_max_str_digits(10**6 + 5)

t = int(input())
for i in range(t):
    n1, m1 = input().split()
    n, m = map(int, [n1, m1])
    if n < m:
        print(m)
        continue
    a1 = (n // m + 1) * m
    a1 = str(a1)
    n += 1
    n1 = str(n)
    if m1 in n1:
        print(n1)
        continue

    lm = len(m1)
    n21 = n1[: -2 * lm + 1]
    n2 = n1[-2 * lm + 1 :]
    a2 = "9" * len(n2)
    lst = n2[-lm:]
    # print(n2)
    for i in range(0, len(n2) - lm + 1):
        ok = 1
        for j in range(0, len(n2) - i - lm):
            if n2[i + j] != m1[j]:
                ok = 0
                break
        j = len(n2) - i - lm
        # print(f"{j, ok}")
        if ok == 0:
            continue

        a3 = m1[-i - 1 :] + "0" * (len(n2) - lm - i)
        if a3 > n2:
            a2 = min(a2, a3)
        # print(f"{m1 = },{a3 = }")
        # a3 = n2[:i] + m1 + "0" * (len(n2) - lm - i)
        # if a3 >= n2:
        #     a2 = min(a2, a3)

    a2 = n2[:-lm] + a2
    # print(a2)
    if len(a1) < len(a2):
        print(a1)
    elif len(a2) < len(a1):
        print(a2)
    else:
        print(min(a1, a2))

"""
6
7 3
12 3
9 10
249 51
1369 37
2 1

1
100000000001244 453

1
249 51

"""

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 10576kb

input:

6
7 3
12 3
9 10
249 51
1369 37
2 1

output:

9
13
10
251
1370
3

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 439ms
memory: 10560kb

input:

100000
3196282243 28
7614814237 33
2814581084 97
1075124401 58
7822266214 100
1767317768 31
7189709841 75
9061337538 69
6552679231 38
9946082148 18
5497675062 54
7787300351 65
4310767261 68
4811341953 100
3265496130 31
8294404054 62
2845521744 90
1114254672 26
6442013672 13
3744046866 40
3289624367 ...

output:

3196282244
233
097
458
6699999
1767317769
8999
569
238
118
5497675063
365
268
4199999
3265496131
062
790
6999
6442013673
3744046867
375
3999
5999
689
180
025
387
154
3823820672
9999
3593364027
593
493
265
7999
5999
8999
6999
146
479
355
780
2999
8999
155
010
477
148
6999
3
278
686
6999
9999
7999
371...

result:

wrong answer 2nd lines differ - expected: '7614814251', found: '233'