QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620162#8932. Bingozzpcd#WA 7ms10652kbPython31.2kb2024-10-07 16:51:252024-10-07 16:51:35

Judging History

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

  • [2024-10-07 16:51:35]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:10652kb
  • [2024-10-07 16:51:25]
  • 提交

answer

import sys
sys.set_int_max_str_digits(2000105)


def myint(x : str):
    if len(x) == 0:
        return int(0)
    return int(x)

T = int(input())
for _ in range(T):
    n, m = input().split()
    N = int(n)
    n = n
    M = int(m)
    N += 1
    n = str(N)
    if N <= M :
        print(M)
        continue
    if n.find(m) != -1:
        print(N)
        continue
    Ans = (N + M - 1) // M * M
    orgN = N
    N += M
    n = str(N)
    g = n.find(m)
    if g != -1 and g + len(m) + len(m) <= len(n):
        Ans = min(Ans, N - myint(n[-len(m):]))
    ri = M
    rt = 1
    now = int(0)
    for i in range(11):
        tmp = myint(n[-(len(m)+i):])
        if tmp <= M * rt:
            ri = min(ri, M * rt - tmp)

        rt *= 10
        # if now < ri:
        #     if(len(n) >= i + 1):
        #         ch = int(n[-i-1])
        #     else:
        #         ch = 0
        #     if ch==0: 
        #         continue
        #     now += (10 - ch) * 10**i
        #     if now < ri:
        #         N += (10 - ch) * 10**i
        #         n = str(N)
        #         if n.find(m) != -1:
        #             ri = min(ri, now)   

    # print(ri)
    Ans = min(Ans, orgN + ri)    
    print(Ans)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 10652kb

input:

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

output:

9
13
10
255
1370
3

result:

wrong answer 4th lines differ - expected: '251', found: '255'