QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#719014 | #885. Keep Calm And Carry Off | qwerasdf | WA | 15ms | 10628kb | Python3 | 1.4kb | 2024-11-06 22:03:08 | 2024-11-06 22:03:11 |
Judging History
answer
import sys
input = lambda:sys.stdin.readline().strip()
def sub(a, b):
# a - b
l = len(a)
ans = [0 for _ in range(l)]
for i in range(l-1, -1, -1):
if a[i] >= b[i]:
ans[i] = a[i] - b[i]
else:
ans[i] = a[i] - b[i] + 10
a[i-1] -= 1
return ans
def solve(a, b):
# a + x | b - x
l = len(a)
idx = 0
for i in range(l-1, -1, -1):
if a[i] + b[i] >= 10:
idx = i - 1
while idx >= 0 and a[i] + b[i] == 9:
idx -= 1
res = [0 for _ in range(l)]
for i in range(idx):
res[i] = a[i]
res[idx] = a[idx] + 1
for i in range(idx+1, l):
res[i] = 0
# print(res)
# print(a)
# print()
return sub(res, a)
a = [*map(int, [*input()])]
b = [*map(int, [*input()])]
la = len(a)
lb = len(b)
l = max(len(a), len(b)) + 1
a = [0 for _ in range(l-la)] + a
b = [0 for _ in range(l-lb)] + b
# print(a)
# print(b)
ans1 = solve(a, b)
ans2 = solve(b, a)
# print(ans1)
# print(ans2)
res = ans1
for i in range(l):
if ans1[i] == ans2[i]:
continue
if ans1[i] < ans2[i]:
res = ans1
break
else:
res = ans2
break
res = res[::-1]
while len(res) and res[-1] == 0:
res.pop()
if len(res) == 0:
res.append(0)
res = res[::-1]
print(*res, sep='')
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 10628kb
input:
10 99
output:
1
result:
ok answer is '1'
Test #2:
score: 0
Accepted
time: 15ms
memory: 10456kb
input:
90 10
output:
10
result:
ok answer is '10'
Test #3:
score: 0
Accepted
time: 10ms
memory: 10516kb
input:
23425 487915
output:
12085
result:
ok answer is '12085'
Test #4:
score: -100
Wrong Answer
time: 15ms
memory: 10516kb
input:
1 1
output:
9
result:
wrong answer expected '0', found '9'