Last active
July 28, 2016 14:36
-
-
Save macrat/16ff4a68453b9ad285f89a756ec44224 to your computer and use it in GitHub Desktop.
こだわり者いろはちゃん。雑すぎて死にそう実装。 http://abc042.contest.atcoder.jp/tasks/arc058_a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
target = input().split(' ')[0] | |
coins = {*range(10)} - {*map(int, input().split(' '))} | |
result = '' | |
for c in target: | |
try: | |
result += str(min(x for x in coins if int(c) <= x)) | |
except ValueError: | |
for i in range(-1, -len(result), -1): | |
try: | |
result = (result[:i] | |
+ str(min(x for x in coins if int(result[i]) < x)) | |
+ str(min(coins))) | |
except ValueError: | |
pass | |
else: | |
break | |
candidate = result + str(min(coins)) * (len(target) - len(result)) | |
if int(target) <= int(candidate): | |
result = candidate | |
break | |
print(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calc(target, coins, result=[]): | |
if len(target) == 0: | |
return result | |
try: | |
return calc(target[1:], | |
coins, | |
[*result, min(x for x in coins if int(target[0]) <= x)]) | |
except ValueError: | |
return calc([target[1]+1, *target[2:]], coins, [*result, min(coins)]) | |
print(''.join(map(str, | |
calc(list(map(int, input().split(' ')[0]))[::-1], | |
{*range(10)} - {*map(int, input().split(' '))})[::-1]))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
target = list(map(int, input().split(' ')[0]))[::-1] | |
coins = {*range(10)} - {*map(int, input().split(' '))} | |
r = [] | |
for i, c in enumerate(target): | |
try: | |
r.append(min(x for x in coins if int(c) <= x)) | |
except ValueError: | |
target[i + 1] += 1 | |
r.append(min(coins)) | |
print(''.join(str(c) for c in r[::-1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment