QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#262753#885. Keep Calm And Carry OffFyindTL 10ms8196kbPython31012b2023-11-23 22:56:162023-11-23 22:56:17

Judging History

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

  • [2023-11-23 22:56:17]
  • 评测
  • 测评结果:TL
  • 用时:10ms
  • 内存:8196kb
  • [2023-11-23 22:56:16]
  • 提交

answer

import sys
sys.setrecursionlimit(10000000)

def toInt (x):
    ret=0
    l=range (len(x))
    for i in l:
        ret=ret*10+int (x[i])
    return ret


x = toInt(input())

y = toInt(input())

ss = x + y
sumstr = str(ss)[::-1]
sumlen = len(sumstr)

xstr = str(x)[::-1]
xstr = xstr.ljust(sumlen, "0")
ystr = str(y)[::-1]
ystr = ystr.ljust(sumlen, "0")

pos = -1
for i in range(sumlen):
    if (int(xstr[i]) + int(ystr[i]) != int(sumstr[i])):
        pos = i
        # print(xstr[i], ystr[i], sumstr[i])

if pos == -1:
    print(0)
else:
    ans = min(x, y)
    ansxstr = ("0" * pos) + str(int(xstr[pos]) + 1) + xstr[pos + 1:]
    # ansxstr = ansxstr[:str(x).__len__()]
    # print(ansxstr)
    revx = toInt(ansxstr[::-1])
    ans = min(ans, abs(x - revx))
    ansystr = ("0" * pos) + str(int(ystr[pos]) + 1) + ystr[pos + 1:]
    # ansystr = ansystr[:str(y).__len__()]
    # print(ansystr)
    revy = toInt(ansystr[::-1])
    ans = min(ans, abs(y - revy))
    print(ans)

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 8132kb

input:

10
99

output:

1

result:

ok answer is '1'

Test #2:

score: 0
Accepted
time: 9ms
memory: 8160kb

input:

90
10

output:

10

result:

ok answer is '10'

Test #3:

score: 0
Accepted
time: 9ms
memory: 8192kb

input:

23425
487915

output:

12085

result:

ok answer is '12085'

Test #4:

score: 0
Accepted
time: 4ms
memory: 8148kb

input:

1
1

output:

0

result:

ok answer is '0'

Test #5:

score: 0
Accepted
time: 10ms
memory: 8100kb

input:

99
99

output:

1

result:

ok answer is '1'

Test #6:

score: 0
Accepted
time: 10ms
memory: 8096kb

input:

14
86

output:

14

result:

ok answer is '14'

Test #7:

score: 0
Accepted
time: 10ms
memory: 8196kb

input:

899999999999999999999
100000000000000000001

output:

100000000000000000001

result:

ok answer is '100000000000000000001'

Test #8:

score: -100
Time Limit Exceeded

input:

615357649595284099508435993883986571313695656691562389866620971630644953030429613681442060702023197532680463771166724257258948140032009435767225187778914625685600736964207275868974321513156027752788270804733647164380664571327109020774746630643814103150883559720458844636326901760106285413007100737536...

output:


result: