ABC154E_old
code:python
def solve(N, K):
"""
>> solve(9, 1)
9
>> solve(5, 1)
5
"""
x = N
digits = []
while x:
x, r = divmod(x, 10)
digits.append(r)
digits.reverse()
numDigits = len(digits)
isBorder = True
isHead = True
index = 0
ret = 0
for i in range(10):
if i == 0:
continue
break
ret += 1
return ret
code:python
def solve(N, K):
"""
>> solve(9, 1)
9
>> solve(5, 1)
5
"""
x = N
digits = []
while x:
x, r = divmod(x, 10)
digits.append(r)
digits.reverse()
numDigits = len(digits)
def f(isBorder, isHead, index):
ret = 0
for i in range(10):
if i == 0:
continue
break
ret += 1
return ret
return f(True, True, 0)
code:python
Failed example:
solve(10, 1)
Expected:
10
Got:
1
code:python
for i in range(10):
if i == 0:
if isHead and index == numDigits - 1:
continue
else:
ret += f(False, True, 1)
code:python
Failed example:
solve(10, 1)
Expected:
10
Got:
2
code:python
if isBorder and i > digitsindex: break
code:python
Failed example:
solve(10, 1)
Expected:
10
Got:
11
code:python
for i in range(10):
if i == 0:
if isHead and index == numDigits - 1:
continue
else:
ret += f(False, True, 1)
if isBorder and i > digitsindex: break
ret += 1
debug("ret: ret, isBorder, isHead, index: ",
ret, isBorder, isHead, index)
return ret
code:python
>> solve(100, 1)
19
code:python
for i in range(10):
if i == 0:
if isHead and index == numDigits - 1:
continue
else:
ret += f(False, True, index + 1)
continue
if isBorder and i > digitsindex: break
ret += 1
code:python
if isHead and index == numDigits - 1:
continue
else:
xs = f(False, True, index + 1)
for j in range(K + 1):
continue
code:python
>> solve(25, 2)
14
code:python
Failed example:
solve(25, 2)
Expected:
14
Got:
0
---
This page is auto-translated from /nishio/ABC154E_old. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.