Submission #2225698


Source Code Expand

from functools import reduce

def obsession(n, disliked):
    def nearest(digit):
        for i in range(digit, digit + 10):
            mod10 = i % 10
            if mod10 not in disliked:
                return (mod10, i != mod10)

    will_pay = list(map(int, str(n)))
    index = 0
    while index < len(will_pay):
        digit = will_pay[index]
        if digit in disliked:
            substitute, carry = nearest(digit)
            will_pay[index] = substitute
            while carry and index > 0:
                substitute, carry = nearest(will_pay[index - 1] + 1)
                will_pay[index - 1] = substitute
                index -= 1
            if carry:
                will_pay.insert(0, nearest(1)[0])
                index += 1
        index += 1
    return reduce(lambda x, y: x * 10 + y, will_pay, 0)


if __name__ == '__main__':
    n, _ = map(int, input().split())
    disliked = set(map(int, input().split()))
    print(obsession(n, disliked))

Submission Info

Submission Time
Task C - Iroha's Obsession
User tekess
Language Python (3.4.3)
Score 0
Code Size 1002 Byte
Status WA
Exec Time 25 ms
Memory 3700 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status AC
AC × 8
WA × 2
Set Name Test Cases
Sample
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask1_X_01.txt, subtask1_X_02.txt, subtask1_X_03.txt, subtask1_X_04.txt, subtask1_X_05.txt, subtask1_X_06.txt, subtask1_X_07.txt, subtask1_X_08.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 25 ms 3700 KB
subtask0_sample_02.txt AC 24 ms 3572 KB
subtask1_X_01.txt AC 23 ms 3572 KB
subtask1_X_02.txt AC 23 ms 3572 KB
subtask1_X_03.txt AC 23 ms 3572 KB
subtask1_X_04.txt AC 23 ms 3572 KB
subtask1_X_05.txt AC 23 ms 3572 KB
subtask1_X_06.txt WA 23 ms 3572 KB
subtask1_X_07.txt WA 23 ms 3572 KB
subtask1_X_08.txt AC 23 ms 3572 KB