Problem:


Score : 300 points

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.

She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

 1 ≦ N < 10000

 1 ≦ K < 10

 0 ≦ D_1 < D_2 < … < D_K≦9

\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

Input

The input is given from Standard Input in the following format:

N K
D_1 D_2 … D_K

Output

Print the amount of money that Iroha will hand to the cashier.

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

Sample Input 2

9999 1
0

Sample Output 2

9999



Sample input:
1000 8
1 3 4 5 6 7 8 9


Sample output:
2000

Submission status: Wrong Answer

Solution code:
n, k = input().split()

lst = list(input().split())
res = ""
for i in range(int(n), 10000):
    for j in lst:
        if j in str(i):
            break
    else:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n, k = input().split()

lst = list(input().split())
res = ""
for i in range(int(n), 10000):
    for j in lst:
        if j in str(i):
            break
        if j == lst[len(lst) - 1] and not j in str(i):
            print(i)
            exit()

Submission status: Wrong Answer

Solution code:
n, k = input().split()

lst = list(map(int, input().split()))
res = ""
for i in range(len(n)):
    append = int(n[i])
    while (1):
        if append in lst:
            append = append + 1
        else:
            break
    res += str(append)

print(res)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
digit = [str(i) for i in range(10) if not i in d]
ans = []
stack = [i for i in digit]
while stack:
  s = stack.pop()
  if int(s) >= n:
    ans.append(s)
  else:
    for i in digit:
      if len(i+s) <= len(str(n))+1:
        stack.append(i+s)

print(min(ans))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(input().split())
while True:
  s=str(n)
  for x in d:
    if x in s:
      break
    print(n)
    exit()
  n+=1




print()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
digit = [str(i) for i in range(10) if not i in d]
ans = []
stack = [i for i in digit]
while stack:
  s = stack.pop()
  if int(s) >= n:
    ans.append(s)
  else:
    for i in digit:
      if len(i+s) <= len(str(n)):
        stack.append(i+s)
if len(ans) > 0:
  print(min(ans))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
digit = [str(i) for i in range(10) if not i in d]
ans = []
stack = [i for i in digit]
while stack:
  s = stack.pop()
  if int(s) >= n:
    ans.append(s)
  else:
    for i in digit:
      if len(i+s) <= len(str(n)):
        stack.append(i+s)
if len(ans) > 0:
  print(min(ans))
else:
  print(n)

Submission status: Wrong Answer

Solution code:
line1 = input()
line2 = input()
price, k = line1.split(" ")
num = line2.split(" ")
ans = ""

for w in price:
    if w in num:
        for i in range(int(w)+1, 10):
            if str(i) not in num:
                ans = ans + str(i)
            break
    else:
        ans = ans + w
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())

A = list(map(str, input().split()))


for i in range(n, n+10000):
    if len(set(str(i)) & set(A)) == 0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
def main():
    n,k=map(int,input().split())
    d=set(map(int,input().split()))
    ln=[int(i) for i in list(str(n))]
    l=len(ln)
    
    flag=True
    x=min(set(range(10))-d)
    for i in range(l):
        if flag:
            while ln[i] in d:
                ln[i]+=1
                flag=False

        else:
            ln[i]=x
    
    print(''.join([str(i) for i in ln]))
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
l = list(input().split())
for i in range(n,n+10001):
    chk = True
    
    for st in list(str(i)):
        if st in l:
            chk = False
    if chk:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
l = list(input().split())
for i in range(n,10001):
    chk = True
    
    for st in list(str(i)):
        if st in l:
            chk = False
    if chk:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
l = list(input().split())
for i in range(n,n+20000):
    check = True
    
    for j in list(str(i)):
        if j in l:
            check = False 
    if check:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(str, input().split()))
num_set = set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
N_list = list(str(N))

diff_list = sorted(list(num_set.difference(set(D))))

if (list(set(D)&set(N_list)) == []):
    print(N)
else:
    str_n = ''
    if '0' in diff_list:
        n_list = [diff_list[1]] + ['0']*len(N_list)
    else:
        n_list = [diff_list[0]] + ['0']*len(N_list)
    
    for i in n_list:
        str_n += str(i)
    new_n = int(str_n)+1
    for ii in range(N, new_n):
        if list(set(list(str(ii)))&set(D)) == []:
            print(ii)
            break

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(str, input().split()))
num_set = set(['1', '2', '3', '4', '5', '6', '7', '8', '9'])
N_list = list(str(N))

diff_list = list(num_set.difference(set(D)))

if (list(set(D)&set(N_list)) == []):
    print(N)
else:
    str_n = ''
    for i in [diff_list[0]]+[0]*len(N_list):
        str_n += str(i)
    new_n = int(str_n)+1
    for ii in range(N, new_n):
        if list(set(list(str(ii)))&set(D)) == []:
            print(ii)
            break

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(str, input().split()))
num_set = set(['1', '2', '3', '4', '5', '6', '7', '8', '9'])
N_list = list(str(N))

diff_list = list(num_set.difference(set(D)))

if (list(set(D)&set(N_list)) == [])|(list(set(D)&set(N_list)) == ['0']):
    print(N)
else:
    str_n = ''
    for i in [diff_list[0]]+[0]*len(N_list):
        str_n += str(i)
    new_n = int(str_n)+1
    for i in range(N, new_n):
        if list(set(list(str(i)))&set(D)) == []:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(str, input().split()))
num_set = set(['1', '2', '3', '4', '5', '6', '7', '8', '9'])
N_list = list(str(N))

diff_list = list(num_set.difference(set(D)))

if list(set(D)&set(N_list)) == []:
    print(N)
else:
    str_n = ''
    for i in [diff_list[0]]+[0]*len(N_list):
        str_n += str(i)
    new_n = int(str_n)+1
    for i in range(N, new_n):
        if list(set(list(str(i)))&set(D)) == []:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
import sys
import itertools
readline = lambda:sys.stdin.readline().rstrip()
N,K = readline().split()
dd = {int(s) for s in readline().split()}
table = [None] * 10
a = 10
for i in range(9,-1,-1):
    if i not in dd:
        a = i
    table[i] = a

nn = [int(n) for n in N]
mm = [table[n] for n in nn]
tab_min = min(x for x in table if x>0)
tab_zero = table[0]
        
if mm[0]==10:
    print(tab_min, end='')
    for z in itertools.repeat(tab_zero, len(mm)):
        print(z, end='')
else:
    for z,c in zip(mm, mm[1:]+[0]): 
        if c==10:
            print(max(tab_min, z), end='')
        elif z==10:
            print(tab_zero, end='')
        else:
            print(z, end='')
print()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
readline = lambda:sys.stdin.readline().rstrip()
N,K = readline().split()
dd = {int(s) for s in readline().split()}
table = [None] * 10
a = 10
for i in range(9,-1,-1):
    if i not in dd:
        a = i
    table[i] = a

nn = [int(n) for n in N]
mm = [table[n] for n in nn]
tab_min = min(x for x in table if x>0)
tab_zero = table[0]
        
if mm[0]==10:
    print(tab_min, end='')
    for z in itertools.repeat(tab_zero, len(mm)):
        print(z, end='')
else:
    for z,c in zip(mm, mm[1:]+[0]): 
        if c==10:
            print(min(tab_min, z), end='')
        elif z==10:
            print(tab_zero, end='')
        else:
            print(z, end='')
print()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
readline = lambda:sys.stdin.readline().rstrip()
N,K = readline().split()
dd = {int(s) for s in readline().split()}
table = [None] * 10
a = 10
for i in range(9,-1,-1):
    if i not in dd:
        a = i
    table[i] = a

nn = [int(n) for n in N]
mm = [table[n] for n in nn]
tab_min = min(x for x in table if x>0)
tab_zero = table[0]
        
if mm[0]==10:
    print(tab_min, end='')
    for z in itertools.repeat(tab_zero, len(mm)-1):
        print(z, end='')
else:
    for z,c in zip(mm, mm[1:]+[0]): 
        if c==10:
            print(min(tab_min, z), end='')
        elif z==10:
            print(tab_zero, end='')
        else:
            print(z, end='')
print()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
readline = lambda:sys.stdin.readline().rstrip()
N,K = readline().split()
dd = {int(s) for s in readline().split()}
table = [None] * 10
a = 10
for i in range(9,-1,-1):
    if i not in dd:
        a = i
    table[i] = a

nn = (int(n) for n in N)
mm = [table[n] for n in nn]
tab_min = min(x for x in table if x>0)
tab_zero = table[0]
        
if mm[0]==10:
    print(tab_min, end='')
    for z in itertools.repeat(tab_zero, len(mm)-1):
        print(z, end='')
else:
    for z,c in zip(mm, mm[1:]+[0]): 
        if c==10:
            print(min(tab_min, z), end='')
        elif z==10:
            print(tab_zero, end='')
print()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
readline = lambda:sys.stdin.readline().rstrip()
N,K = readline().split()
dd = {int(s) for s in readline().split()}
table = [None] * 10
a = 10
for i in range(9,-1,-1):
    if i not in dd:
        a = i
    table[i] = a

nn = (int(n) for n in N)
mm = [table[n] for n in nn]
tab_min = min(x for x in table if x>0)
tab_zero = table[0]
        
if mm[0]==10:
    print(tab_min, end='')
    for z in itertools.repeat(tab_zero, len(mm)-1):
        print(z, end='')
else:
    for z,c in zip(mm, mm[1:]+[0]): 
        if c==10:
            print(min(tab_min, z), end='')
        else:
            print(z, end='')
print()

Submission status: Wrong Answer

Solution code:
def main():
  n, k = map(int, input().split())
  d = list(input().split())
  for i in range(n, 10000):
    if checknum(i, d):
      print(i)
      break

def checknum(n, d):
  for s in str(n):
    if d.count(s) > 0:
      return False
  return True
 
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
def main():
  n, k = map(int, input().split())
  d = list(map(int, input().split()))
  a = n
  for i in range(n, 10000):
    if checknum(i, d):
      a = i
      break
  print(a)

def checknum(n, d):
  for s in str(n):
    if d.count(int(s)) > 0:
      return False
  return True

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
def main():
  n, k = map(int, input().split())
  d = list(map(int, input().split()))
  a = 0
  for i in range(n, 10000):
    if checknum(i, d):
      a = i
      break
  print(a)

def checknum(n, d):
  for s in str(n):
    if d.count(int(s)) > 0:
      return False
  return True

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
# /usr/bin/env python3
# https://atcoder.jp/contests/abc042/tasks/arc058_a


def check_digit(d, target):
    for i in range(target, 10):
        if i not in d:
            return False, i
    else:
        return True, min(list(set(range(0, 10)) - set(d)))


n, k = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
saitei = min(list(set(range(0, 10)) - set(d)))
ans = ""

for i in range(len(str(n))):
    target = str(n)[-1 * (i + 1)]
    is_kuriagari, digit = check_digit(d, int(target))
    ans = str(digit) + ans
    if is_kuriagari:
        n += 10**i
    # print(f"ketakakutei: {digit}")
if is_kuriagari:
    ans = str(saitei) + ans
print(ans)

Submission status: Wrong Answer

Solution code:
#!/use/bin/env python3

(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

ans = n

while (1):

    c = True
    for ii in range(0, 4):
        b = n // pow(10, ii)
        d = b % 10

        if b == 0:
            break

        if d in a:
            c = False
            break

    if (c):
        ans = n
        break
    n += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/use/bin/env python3

(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

for i in range(0, 10):
    if i not in a:
        like.append(i)

ans = -1

while (1):

    c = True
    for ii in range(0, 4):
        b = n // pow(10, ii)
        d = b % 10

        if b == 0:
            break

        if d not in like:
            c = False
            break

    if (c):
        ans = n
        break
    n += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/use/bin/env python3

(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

for i in range(0, 10):
    if i not in a:
        like.append(i)

ans = -1

while (1):

    c = True
    for ii in range(0, 4):
        b = int((n / pow(10, ii))) % 10

        if b not in like:
            c = False
            break
    if (c):
        ans = n
        break
    n += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/use/bin/env python3

(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

for i in range(0, 10):
    if i not in a:
        like.append(i)

ans = -1

try:
    while (1):

        c = True
        for ii in range(0, 4):
            b = int((n / pow(10, ii))) % 10

            if b not in like:
                c = False
        if (c):
            ans = n
            raise Exception

        n += 1

except:
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/use/bin/env python3

(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

for i in range(0, 10):
    if i not in a:
        like.append(i)

ans = -1

try:
    while (1):

        c = True
        for ii in range(3, 0, -1):
            b = (n // pow(10, ii)) % 10

            if b not in like:
                c = False
        if (c):
            ans = n
            raise Exception

        n += 1

except:
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/use/bin/env python3

(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

for i in range(0, 10):
    if i not in a:
        if i != 0:
            like.append(i)

b = sorted(like)
k = b[0]

ans = k * n

print(ans)

Submission status: Wrong Answer

Solution code:
#!/use/bin/env python3

(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

for i in range(0, 10):
    if i not in a:
        like.append(i)

b = sorted(like)
k = b[0] if b[0] != 0 else b[1]

ans = k * n

print(ans)

Submission status: Wrong Answer

Solution code:
#!/use/bin/env python3

(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

for i in range(1, 10):
    if i not in a:
        like.append(i)

b = sorted(like)
k = b[0] if b[0] != 0 else b[1]

ans = k * n

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N, K = map(int, input().split())
D = list(map(int, input().split()))

for n in range(N, 10000+1):
  li = list(str(n))

  for i in li:
    if int(i) in D:
      break

  else:
    print(n)
    sys.exit()

Submission status: Wrong Answer

Solution code:
import sys

N, K = map(int, input().split())
D = list(map(int, input().split()))

for n in range(N, 10000):
  li = list(str(n))

  for i in li:
    if int(i) in D:
      break

  else:
    print(n)
    sys.exit()

Submission status: Wrong Answer

Solution code:
# /usr/bin/env python3
# https://atcoder.jp/contests/abc042/tasks/arc058_a

n, k = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
ans = 0
for i in range(len(str(n)) + 1):
    target = n // (10**i) % 10
    if i == len(str(n)) and target == 0:
        break
    for j in range(target, 10):
        if j not in d:
            ans += 10**i * j
            break
    else:
        n += 10**i
print(ans)

Submission status: Wrong Answer

Solution code:
# /usr/bin/env python3
# https://atcoder.jp/contests/abc042/tasks/arc058_a

n, k = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
ans = 0
for i in range(len(str(n)) + 1):
    target = n // (10**i) % 10
    for j in range(target, 10):
        if j not in d:
            ans += 10**i * j
            break
    else:
        n += 10**i
print(ans)

Submission status: Wrong Answer

Solution code:
# /usr/bin/env python3
# https://atcoder.jp/contests/abc042/tasks/arc058_a

n, k = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
ans = 0
for i in range(len(str(n))):
    target = n // (10**i) % 10
    for j in range(target, 10):
        if j not in d:
            ans += 10**i * j
            break
    else:
        n += 10**i
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product

N, K = map(int, input().split())
D = list(map(int, input().split()))
L = []
for i in range(10):
	if not i in D:
		L.append(i)
keta = len(str(N))
flg = 0

# 与えられた桁と同じ桁数で終わるとき
for num in product(L, repeat = keta):
	num = list(num)
	num.reverse()
	# print(num)
	val = 0
	for i in range(keta):
		val += num[i] * (10 ** i)
	if val >= N:
		flg = 1
		break
		
if flg:
	print(val)
# 与えられた桁で終わらないとき
else:
	for l in L:
		if l != 0:
			a = l
			break
	val = a * (10 ** (keta + 1))
	for i in range(keta):
		val += min(L) * (10 ** i)
	print(val)

Submission status: Wrong Answer

Solution code:
from itertools import product

N, K = map(int, input().split())
D = list(map(int, input().split()))
L = []
for i in range(10):
	if not i in D:
		L.append(i)
keta = len(str(N))
flg = 0

# 与えられた桁と同じ桁数で終わるとき
for num in product(L, repeat = keta):
	num = list(num)
	num.reverse()
	# print(num)
	val = 0
	for i in range(keta):
		val += num[i] * (10 ** i)
	if val >= N:
		flg = 1
		break
		
if flg:
	print(val)
else:
	for l in L:
		if l != 0:
			a = l
			break
	val = a * (10 ** (keta + 1))
	print(val)

Submission status: Wrong Answer

Solution code:
from itertools import product

N, K = map(int, input().split())
D = list(map(int, input().split()))
L = []
for i in range(10):
	if not i in D:
		L.append(i)
keta = len(str(N))
flg = 0

# 与えられた桁と同じ桁数で終わるとき
for num in product(L, repeat = keta):
	num = list(num)
	num.reverse()
	# print(num)
	val = 0
	for i in range(keta):
		val += num[i] * (10 ** i)
	if val >= N:
		flg = 1
		break
		
if flg:
	print(val)
else:
	val = min(L) * (10 ** (keta + 1))
	print(val)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
for i in range(10000):
  ok = True
  for di in d:
    if str(di) in str(i):
      ok = False
      break
  if ok and i >= n:
    break

print(i)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
usable = []
non_zero_usable = []
for i in range(10):
  if i not in d:
    usable.append(i)
    if i != 0:
      non_zero_usable.append(i)

su = sorted(usable)
zu = sorted(non_zero_usable)
ans = ''
for i, v in enumerate(list(str(n))):
  v = int(v)
  if i == 0:
    for z in zu:
      if v <= z:
        ans += str(z)
        break
    continue
  
  for s in su:
    if v <= s:
      ans += str(s)
      break
      
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(str,input().split()))
for k in range(100*N):
    N += 1
    for j in range(len(str(N))):
        if str(N)[j] in D:
            break
    else:
        print(N)
        exit()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(str,input().split()))
for k in range(9*N+1):
    N += 1
    for j in range(len(str(N))):
        if str(N)[j] in D:
            break
    else:
        print(N)
        exit()

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
N, K = map(int, input().split())
D = input().split()

O = []
for c in "0123456789":
    if c not in D:
        O.append(c)

# N = 523
# D = 2 3

#@lru_cache()
def func(s, i, over):
    if i == len(s):
        return ""
    # d < N[0] 
    if over:
        return O[0] + func(s, i+1, over=True)
    for d in O:
        if d < s[i]:
            continue
        if s[i] == d:
            return d + func(s, i+1, over=False)
        return d + func(s, i+1, over=True)
    return (O[1] if O[0] == '0' else O[0]) + func(s, i, over=True)

def solve(N, D):
    D = set(list(D))
    while True:
        ok = True
        for c in str(N):
            if c in D:
               ok = False
               break
        if ok:
            return N
        N+=1

#print(solve(N, D))
print(func(str(N), 0, over=False))

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
N, K = map(int, input().split())
D = input().split()

O = []
for c in "0123456789":
    if c not in D:
        O.append(c)

# N = 523
# D = 2 3

#@lru_cache()
def func(s, i, over):
    if i == len(s):
        return ""
    # d < N[0] 
    if over:
        return O[0] + func(s, i+1, over=True)
    for d in O:
        if d < s[i]:
            continue
        if s[i] == d:
            return d + func(s, i+1, over=False)
        return d + func(s, i+1, over=True)
    return "10" + func(s, i+1, over=True)

def solve(N, D):
    D = set(list(D))
    for n in range(int(N), 10001):
        ok = True
        for c in str(n):
            if c in D:
               ok = False
               break
        if ok:
            return n

print(solve(N, D))
#print(func(str(N), 0, over=False))

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
N, K = map(int, input().split())
D = input().split()

O = []
for c in "0123456789":
    if c not in D:
        O.append(c)

# N = 523
# D = 2 3

#@lru_cache()
def func(s, i, over):
    if i == len(s):
        return ""
    # d < N[0] 
    if over:
        return O[0] + func(s, i+1, over=True)
    for d in O:
        if d < s[i]:
            continue
        if s[i] == d:
            return d + func(s, i+1, over=False)
        return d + func(s, i+1, over=True)
    return "10" + func(s, i+1, over=True)

print(func(str(N), 0, over=False))

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
D = LIST()
d_s = set(D)
for i in range(N, 10000):
    l = list(str(i))
    l = list(map(int, l))
    l_s = set(l)
    s_intersection = d_s & l_s
    if len(s_intersection) == 0:
        print(i)
        exit()

    # if d_s.isdisjoint(l_s):
    #     print(i)
    #     exit()

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
D = LIST()
d_s = set(D)
for i in range(N, 10000):
    l = list(str(i))
    l = list(map(int, l))
    l_s = set(l)
    if d_s.isdisjoint(l_s):
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
inf = 10 * n + 1
stop = len(str(n)) + 1
num = []
for i in range(10):
    if i in d:
        pass
    else:
        num.append(i)


def dfs(pos, x):
    if pos == stop:
        if x >= n:
            return x
        else:
            return inf

    ret = [
        dfs(pos + 1, 10 * x + num_i) for num_i in num
    ]

    return min(ret)


print(dfs(0, 0))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
inf = 10 * n + 1
stop = len(str(n))
num = []
for i in range(10):
    if i in d:
        pass
    else:
        num.append(i)

ans = 0
for i in num:
    if i >= int(str(n)[0]):
        ans = i
        break
# 同じ桁数で超えない場合
if ans == 0:
    stop += 1
    if 0 in num:
        ans = num[1]
    else:
        ans = num[0]


def dfs(pos, x):
    if pos == stop:
        if x >= n:
            return x
        else:
            return inf

    ret = [
        dfs(pos + 1, 10 * x + num_i) for num_i in num
    ]

    return min(ret)


print(dfs(1, ans))

Submission status: Wrong Answer

Solution code:
n, k, *d = open(0).read().split()
over = False
ans = 0
for i in n:
    if over:
        for j in range(10):
            if not str(j) in d:
                ans = ans*10 + j
                break
    else:
        for j in range(int(i), 10):
            if not str(j) in d:
                over = (str(j)!=i)
                ans = ans*10 + j
                break
        else:
            ans += 1
            over = True
            for j in range(10):
                if not str(j) in d:
                    ans = ans*10 + j
                    break
print(ans)

Submission status: Wrong Answer

Solution code:
n, k, *d = open(0).read().split()
over = False
ans = 0
for i in n:
    if over:
        for j in range(10):
            if not str(j) in d:
                ans = ans*10 + j
                break
    else:
        for j in range(int(i), 10):
            if not str(j) in d:
                over = (str(j)!=i)
                ans = ans*10 + j
                break
        else:
            ans += 1
            for j in range(10):
                if not str(j) in d:
                    ans = ans*10 + j
                    break
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
dl = set(input().split())

for i in range(n, 10000):
    if set(str(i)).intersection(dl) == set():
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d_i = set(map(int, input().split()))
full = set(range(10))
useableList = full - d_i
useable_Top = full - d_i - set([0])
answer = []
isTop = True
isMatch = True
for x in str(n):
    if isMatch and int(x) in useableList: answer.append(x)
    elif isTop and int(x) > max(useable_Top): answer.append(min(useable_Top)* 10)
    elif isTop: answer.append(min(useable_Top - set(range(int(x) + 1))))
    else: answer.append(min(useableList))
    if isTop: isTop = False;
    if isMatch and int(x) not in useableList: isMatch = False
ans = ''
for x in range(len(answer)):
    ans += str(answer[x])
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d_i = set(map(int, input().split()))
full = set(range(10))
useableList = full - d_i
useable_Top = full - d_i - set([0])
answer = []
isTop = True
for x in str(n):
    if isTop and int(x) in useableList: answer.append(x)
    elif isTop and int(x) > max(useable_Top): answer.append(min(useable_Top)* 10)
    elif isTop: answer.append(min(useable_Top - set(range(int(x) + 1))))
    else: answer.append(min(useableList))
    if isTop: isTop = False;
ans = ''
for x in range(len(answer)):
    ans += str(answer[x])
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d_i = set(map(int, input().split()))
full = set(range(10))
useableList = full - d_i
useable_Top = full - d_i - set([0])
answer = []
isTop = True
for x in str(n):
    if int(x) in useableList: answer.append(x)
    elif isTop and int(x) > max(useable_Top): answer.append(min(useable_Top)* 10)
    elif isTop: answer.append(min(useable_Top - set(range(int(x) + 1))))
    else: answer.append(min(useableList))
    if isTop: isTop = False;
ans = ''
for x in range(len(answer)):
    ans += str(answer[x])
print(ans)

Submission status: Wrong Answer

Solution code:
s = input().split(" ")
n = int(s[0])
numbers = [ i for i in input() if i != " "]

for i in range(n, 10001):
  found = False
  snum = str(i)
  for num in numbers:
    if num in snum:
      found = True
      break
  
  if found == False:
     print(i)
     break

Submission status: Wrong Answer

Solution code:
nk = list(map(int, input().split()))
N = nk[0]
K = nk[1]

d = input().split()
a = True
for i in range(N, 20001):
  a = True
  for j in d:
    if str(i).count(j) > 0:
      a = False
      break
  if a:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
nk = list(map(int, input().split()))
N = nk[0]
K = nk[1]

d = input().split()
a = True
for i in range(N, 10001):
  a = True
  for j in d:
    if str(i).count(j) > 0:
      a = False
      break
  if a:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 042
# C - こだわり者いろはちゃん / Iroha's Obsession
D = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
N, K = map(int, input().split())
l = input().split()
for i in range(K):
    D.pop(D.index(int(l[i])))
X = ''
for i in range(3,-1,-1):
    for j in range(len(D)):
        if D[j] >= N//(10**i):
            X = X + str(D[j])
            break
    N = N - (N//(10**i))*(10**i)
print(X)

Submission status: Wrong Answer

Solution code:
N, _ = list(map(int, input().split()))
d = set(list(input().replace(" ", "")))

for i in range(1,100000001):
  n = str(N*i)
  ns = set(list(n))
  flg = False
  for t in ns:
    if t in d:
      flg = True
      break
  if flg == False:
    print(n)
    exit()
print(0)

Submission status: Wrong Answer

Solution code:
N, _ = list(map(int, input().split()))
d = set(list(input().replace(" ", "")))

for i in range(1,1000001):
  n = str(N*i)
  ns = set(list(n))
  flg = False
  for t in ns:
    if t in d:
      flg = True
      break
  if flg == False:
    print(n)
    exit()
print(0)