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: Runtime Error

Solution code:
N, K = [int(i) for i in input().split()]
ds = [int(i) for i in input().split()]

#N, K = (99999, 1)
#ds = [0]

def run_code(N, K, ds):

    dislike_digits_set = set(i for i in ds)
    avail_digits = [i for i in range(10) if i not in dislike_digits_set]
    avail_min = avail_digits[0]

    def get_next_digit(d):
        last = [10]
        for ad in (avail_digits + last):
            if ad >= d:
                if ad == last:
                    return (1, avail_min)
                else:
                    return (0, ad)

    def to_num(n_digits):
        num = 0
        n = len(n_digits)
        for i in range(n):
            num += n_digits[i] * 10**(n-i-1)
        return num

    def to_digits(num):
        return [int(i) for i in str(num)]

    def search_nearest_larger(num):
        n_digits = to_digits(num)
        n = len(n_digits)

        for i in range(n):
            d_in = n_digits[i]
            inc, d_out = get_next_digit(d_in)
            if inc == 0 and d_in == d_out:
                continue

            if inc > 0:

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
n = str(N)
ans = N
for i in reversed(range(str(len(N)))):
    temp = n[i]
    while(int(temp) in D):
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
n = str(N)
ans = N
for i in reversed(range(N)):
    temp = n[i]
    while(int(temp) in D):
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n, k = [int(i) for i in input().split()]
q = n
not_liked = [int(i) for i in input().split()]
liked = [i for i in range(10) if i not in not_liked]
 
 
digits = list()
while(n):
	digits.append(n%10)
	n //= 10
digits.reverse()
 
 
ind = -2
for i in digits:
	if i not in liked:
		ind = digits.index(i)
		break
 
 
js = list()
jss = list()
for i in digits:
	for j in liked:
		if j >= i:
			js.append(j)
	jss.append(js[:])
	js.clear()
 
 
m = 0
number = str()
flag = True
for i in range(len(digits)):
	if m != ind+1:
		number += str(min(jss[i]))
		m += 1
	else:
		k = len(str(q)) - m
		val = int(number + str(min(liked))*k)
		if val <= 10000:
			print(val)
		else:
			print(10000)
		flag = False
		break
if flag:
	val1 = int(number)
	if val1 <= 10000:
		print(val1)
	else:
		print(10000)

Submission status: Runtime Error

Solution code:
n, k = [int(i) for i in input().split()]
q = n
not_liked = [int(i) for i in input().split()]
liked = [i for i in range(10) if i not in not_liked]
 
 
digits = list()
while(n):
	digits.append(n%10)
	n //= 10
digits.reverse()
 
 
ind = -2
for i in digits:
	if i not in liked:
		ind = digits.index(i)
		break
 
 
js = list()
jss = list()
for i in digits:
	for j in liked:
		if j >= i:
			js.append(j)
	jss.append(js[:])
	js = []
 
 
m = 0
number = str()
flag = True
for i in jss:
	if m != ind+1:
		number += str(min(i))
		m += 1
	else:
		k = len(str(q)) - m
		val = int(number + str(min(liked))*k)
		if val <= 10000:
			print(val)
		else:
			print(10000)
		flag = False
		break
if flag:
	val1 = int(number)
	if val1 <= 10000:
		print(val1)
	else:
		print(10000)

Submission status: Runtime Error

Solution code:
n, k = [int(i) for i in input().strip(" ").split()]
q = n
not_liked = [int(i) for i in input().strip(" ").split()]
liked = [i for i in range(10) if i not in not_liked]
 
 
digits = list()
while(n):
	digits.append(n%10)
	n //= 10
digits.reverse()
 
 
ind = -2
for i in digits:
	if i not in liked:
		ind = digits.index(i)
		break
 
 
js = list()
jss = list()
for i in digits:
	for j in liked:
		if j >= i:
			js.append(j)
	jss.append(js[:])
	js = []
 
 
m = 0
number = str()
flag = True
for i in jss:
	if m != ind+1:
		number += str(min(i))
		m += 1
	else:
		k = len(str(q)) - m
		val = int(number + str(min(liked))*k)
		if val <= 10000:
			print(val)
		else:
			print(10000)
		flag = False
		break
if flag:
	val1 = int(number)
	if val1 <= 10000:
		print(val1)
	else:
		print(10000)

Submission status: Runtime Error

Solution code:
n, k = [int(i) for i in input().strip(" ").split()]
q = n
not_liked = [int(i) for i in input().strip(" ").split()]
liked = [i for i in range(10) if i not in not_liked]
 
 
digits = list()
while(n):
	digits.append(n%10)
	n //= 10
digits.reverse()
 
 
ind = -2
for i in digits:
	if i not in liked:
		ind = digits.index(i)
		break
 
 
js = list()
jss = list()
for i in digits:
	for j in liked:
		if j >= i:
			js.append(j)
	jss.append(js[:])
	js = []
 
 
m = 0
number = str()
flag = True
for i in jss:
	if m != ind+1:
		number += str(min(i))
		m += 1
	else:
		k = len(str(q)) - m
		print(int(number + str(min(liked))*k))
		flag = False
		break
if flag:
	print(int(number))

Submission status: Runtime Error

Solution code:
N, K = raw_input().split()
D = raw_input().split()
candi = [str(i) for i in xrange(10)]
for d in D:
    candi.remove(d)

def decide(i):
    if i >= len(N):
        return ''
    for c in candi:
        if N[i] == c:
            return c + decide(i+1)
        elif N[i] < c:
            return c + candi[0] * (len(N) - i - 1)
    else:
        return (candi[0] if candi[0] != 0 else candi[1]) + decide(i)

print decide(0)

Submission status: Runtime Error

Solution code:
import itertools

if __name__ == "__main__":
    line_one = input().split()
    line_two = input().split()

    use_num = {'0','1','2','3','4','5','6','7','8','9'}.difference(line_two)
    all_comb = list(itertools.product(use_num, repeat=len(str(line_one[0]))))
    nums = list((map(int,["".join(x) for x in all_comb])))
    ans = min([x for x in nums if x >= int(line_one[0])])
    print(ans)

Submission status: Runtime Error

Solution code:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int main() {
  int n, k, d;
  bool is_safe[10] = {};
  std::cin >> n >> k;
  std::fill(is_safe, is_safe + 10, true);
  for (int ki = 0 ; ki < k; ++ki) {
    std::cin >> d;
    is_safe[d] = false;
  }
  while (true) {
    int r = n;
    while (r > 0) {
      if (not is_safe[r % 10]) {
        goto fail;
      }
      r /= 10;
    }
    std::cout << n << std::endl;
    return 0;
fail:
    ++n;
  }
}

Submission status: Runtime Error

Solution code:
n, k = map(int, raw_input().split())
d = map(int, raw_input().split())
def use_d(n):
    for i in list(str(n)):
        if int(i) in d:
            return True
    else:
        return False
while n < 100000:
    if use_d(n):
        n += 1
    else:
        print n
        sys.exit()