output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the number of times the ball will make a bounce where the coordinate is at most X. * * *
s489510984
Wrong Answer
p03000
Input is given from Standard Input in the following format: N X L_1 L_2 ... L_{N-1} L_N
print(0)
Statement A ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \leq i \leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}. How many times will the ball make a bounce where the coordinate is at most X?
[{"input": "3 6\n 3 4 5", "output": "2\n \n\nThe ball will make a bounce at the coordinates 0, 3, 7 and 12, among which two\nare less than or equal to 6.\n\n* * *"}, {"input": "4 9\n 3 3 3 3", "output": "4\n \n\nThe ball will make a bounce at the coordinates 0, 3, 6, 9 and 12, among which\nfour are less than or equal to 9."}]
Print the number of times the ball will make a bounce where the coordinate is at most X. * * *
s931135488
Accepted
p03000
Input is given from Standard Input in the following format: N X L_1 L_2 ... L_{N-1} L_N
numeroA, numeroB = [], [] contadorCoord = 0 contador = 1 numerosSTRa = input().split(" ") for p in numerosSTRa: numeroA.append(int(p)) numerosSRTB = input().split(" ") for j in numerosSRTB: numeroB.append(int(j)) for i in numeroB: contadorCoord += i if contadorCoord <= numeroA[1]: contador += 1 print(contador)
Statement A ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \leq i \leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}. How many times will the ball make a bounce where the coordinate is at most X?
[{"input": "3 6\n 3 4 5", "output": "2\n \n\nThe ball will make a bounce at the coordinates 0, 3, 7 and 12, among which two\nare less than or equal to 6.\n\n* * *"}, {"input": "4 9\n 3 3 3 3", "output": "4\n \n\nThe ball will make a bounce at the coordinates 0, 3, 6, 9 and 12, among which\nfour are less than or equal to 9."}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s294368886
Accepted
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(input()) def II(): return map(int, input().split()) def III(): return list(map(int, input().split())) def Line(N, num): if num == 1: return [I() for _ in range(N)] else: read_all = [tuple(II()) for _ in range(N)] return map(list, zip(*read_all)) ################# def scc(N, G, RG): used = [False] * N group = [None] * N order = [] def dfs(S): i_order = [] temp_order = [] level = 0 while S: v1 = S.pop() if used[v1[0]]: continue if v1[1] < level: for _ in range(len(temp_order) - v1[1]): x = temp_order.pop() i_order.append(x) level = v1[1] level += 1 if not used[v1[0]]: for v1_to in G[v1[0]]: if not used[v1_to]: S.append((v1_to, level)) temp_order.append(v1[0]) used[v1[0]] = True for t in reversed(temp_order): i_order.append(t) return i_order for i in range(N): if not used[i]: i_order = dfs([(i, 0)]) order += i_order def rdfs(S, col): used[S[0]] = True while S: v1 = S.pop() for v1_to in RG[v1]: if not used[v1_to]: used[v1_to] = True S.append(v1_to) group[v1] = col used = [False] * N label = 0 for s in reversed(order): if not used[s]: rdfs([s], label) label += 1 return label, group def edges_to_pt(s, t, n, directed=False): pt = [[] for _ in range(n)] for i in range(len(s)): pt[s[i] - 1].append(t[i] - 1) if directed == False: pt[t[i] - 1].append(s[i] - 1) return pt N, M = II() if M > 0: L, R, D = Line(M, 3) else: print("Yes") exit() pt = edges_to_pt(L, R, N) label, group = scc(N, pt, pt) x = [] used = [False] * label for i in range(N): if not used[group[i]]: x.append(i) used[group[i]] = True pt_l = [[] for _ in range(N)] for i in range(M): pt_l[L[i] - 1].append((R[i] - 1, D[i])) pt_l[R[i] - 1].append((L[i] - 1, -D[i])) check_visited = [False] * N l = [None] * N for v in x: check_visited[v] = True l[v] = 0 S = [v] while S: v1 = S.pop() for i in pt_l[v1]: if check_visited[i[0]] == False: check_visited[i[0]] = True l[i[0]] = l[v1] + i[1] S.append(i[0]) else: if l[i[0]] == l[v1] + i[1]: continue else: print("No") exit() print("Yes")
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s603212830
Wrong Answer
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
n, m = [int(x) for x in input().split()] res = "Yes" nd = 10**9 x = [nd] * (n + 1) rd = [[] for x in range(n + 1)] for k in range(m): L, r, d = [int(x) for x in input().split()] if L < r: rd[L].append([r, d]) else: rd[r].append([L, -d]) first = True fi = 0 for i in range(1, n + 1): if res == "No": break for dd in rd[i]: r = dd[0] d = dd[1] if first: x[i] = 0 x[r] = x[i] + d fi = i first = False else: v = x[i] + d if x[i] != nd and x[r] != nd: if x[i] + d != x[r]: res = "No" break elif x[r] == nd: x[r] = x[i] + d else: x[r] = v print(res)
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s551850972
Accepted
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") AZ = "abcdefghijklmnopqrstuvwxyz" ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2, N + 1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) def base_10_to_n_without_0(X, n): X -= 1 if X // n: return base_10_to_n_without_0(X // n, n) + [X % n] return [X % n] #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N, M = IL() graph = [[] for i in range(N)] for _ in range(M): l, r, d = IL() graph[l - 1].append((r - 1, d)) graph[r - 1].append((l - 1, -d)) q = deque([i for i in range(N)]) pos = [None for i in range(N)] while q: x = q.popleft() if pos[x] == None: pos[x] = 0 for y, d in graph[x]: if pos[y] == None: pos[y] = pos[x] + d q.appendleft(y) continue if pos[y] != pos[x] + d: print("No") exit() print("Yes")
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s944208329
Runtime Error
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
class WeightUnionfindtree: def __init__(self,number): self.par = [i for i in range(number)] self.rank = [0]*(number) self.weight=[0]*(number) def find(self,x):#親を探す xの親を示す if self.par[x] ==x: return x else: r = self.find(self.par[x]) self.weight[x]+=self.weight[self.par[x]] self.par[x]=r return self.par[x] def weighted(self,x): self.find(x) return self.weight[x] def union(self,x,y,w):#weight(y) = weight(x) + w となるように x と y をマージする w += self.weighted(x) w -= self.weighted(y) px = self.find(x) py = self.find(y) if px == py: return if self.rank[px]<self.rank[py]: self.par[px]=py self.weight[px]=-w else: self.par[py]=px self.weight[py] = w if self.rank[px]==self.rank[py]: self.rank[px] +=1 def connect(self,x,y):#親が同じかみる return self.find(x)==self.find(y) def diff(self,x,y): return self.weighted(y-self.weighted(x) N,M = map(int,input().split()) Tree = WeightUnionfindtree(N) ans = 'Yes' for i in range(M): L,R,D = map(int,input().split()) if Tree.connect(L-1,R-1): if Tree.diff(L-1,R-1)!=D: ans = 'No' else: Tree.union(L-1,R-1,D) print(ans)
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s700254213
Runtime Error
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
import sys l1 = list(map(int, input().split())) N = l1[0] M = l1[1] dat = [] #per_dis = [[ 0 for n in range(N+1)] for n in range(N+1)] per_dis = [ [] for n in range(N+1)] for n in range(M): x = list(map(int, input().split())) dat.append(x) for x in dat: if per_dis[x[0]][x[1]] == 0 and per_dis[x[1]][x[0]] == 0: per_dis[x[0]][x[1]] = x[2] per_dis[x[1]][x[0]] = -x[2] for i in range(1,N): for j in range(i+1,N): if per_dis[i][j] != 0 and per_dis[i+1][j+1] != 0 and per_dis[i][j+1] == 0: per_dis[i][j+1] = per_dis[i][j] + per_dis[i+1][j+1] per_dis[j+1][i] = -per_dis[i][j+1] elif per_dis[i][j] == 0 and per_dis[i+1][j+1] != 0 and per_dis[i][j+1] != 0: per_dis[i][j] = per_dis[i][j+1] - per_dis[i+1][j+1] per_dis[j][i] = -per_dis[i][j] elif per_dis[i][j] != 0 and per_dis[i+1][j+1] == 0 and per_dis[i][j+1] != 0: per_dis[i+1][j+1] = per_dis[i][j+1] - per_dis[i][j] per_dis[j+1][i+1] = -per_dis[i+1][j+1] else: if abs(per_dis[x[0]][x[1]]) != x[2]: print("No") sys.exit(0) print("Yes")
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s985108796
Runtime Error
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
comp = [False] * (N + 1) cond = True hold = [] for i in range(M): l = new_LRD[i][0] r = new_LRD[i][1] d = new_LRD[i][2] if i == 0: comp[l] = 0 comp[r] = d else: if not isinstance(comp[l], bool): if isinstance(comp[r], bool): comp[r] = (comp[l] + d) else: if comp[r] != (comp[l] + d): cond = False break else: if not isinstance(comp[r], bool): comp[l] = (comp[r] - d) else: hold.append([l, r, d]) for i in range(len(hold)): l = hold[i][0] r = hold[i][1] d = hold[i][2] if not isinstance(comp[l], bool): if isinstance(comp[r], bool): comp[r] = (comp[l] + d) else: if comp[r] != (comp[l] + d): cond = False break else: if not isinstance(comp[r], bool): comp[l] = (comp[r] - d) else: continue if cond: print('Yes') else: print('No')
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s370995653
Wrong Answer
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
num = [int() for i in input().split()] if num[0] % 2 == 0: print("Yes") else: print("No")
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s770370185
Wrong Answer
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
print("No")
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s895782685
Runtime Error
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
import sys sys.setrecursionlimit(200002) def dfs(s): global x, G for t, d in G[s]: if x[t] is None: x[t] = x[s] + d if not dfs(t): return False else: if x[t] != x[s] + d: return False return True n, m = map(int, input().split()) x = [None] * n G = [[] for _ in range(n)] for _ in range(m): l, r, d = map(int, input().split()) G[l-1].append([r-1, d]) g[r-1].append([l-1, -d]) res = True for i in range(n): if x[i] is None: x[i] = 0 res &= dfs(i) print('Yes' if res==True, else 'No')
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s394863940
Wrong Answer
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
# coding: UTF-8 import numpy as np def solve(): ans = np.random.random() # print(ans) if ans <= 0.5: ans = "Yes" else: ans = "No" return ans if __name__ == "__main__": ans = solve() print(ans, flush=True)
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s815231514
Runtime Error
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
# coding: UTF-8 from collections import deque # testdata class Graph: # nodes # links def __init__(self): self.nodes = set() self.links = {} # nodes -> [tuple(f,cost)] def readtext(self): N, M = map(int, input().split()) for i in range(M): v, w, c = map(int, input().split()) self.addlink((v, w, c)) def addlink(self, link): v, w, c = link if v not in self.nodes: self.nodes.add(v) self.links[v] = [] if w not in self.nodes: self.nodes.add(w) self.links[w] = [] if v in self.links: self.links[v].append((w, c)) self.links[w].append((v, -c)) else: self.links[v] = [] self.links[v].append((w, c)) self.links[w].append((v, -c)) def addlinks(self, links): for link in links: self.addlink(link) def depthfirstsearch(self, so): visited = set() linq = {} # O(links) for key in self.links: linq[key] = deque(self.links[key]) # recursive subfunction def dfsrec(v, so): so.enter() visited.add(v) while linq[v]: cand, cost = linq[v].popleft() if cand not in visited: so.beforeEnter(v, cand, cost) so = dfsrec(cand, so) so.exit() return so # call subfunction noq = deque(self.nodes) while noq: x = noq.pop() if x not in visited: so.enterConnectedPart(x) so = dfsrec(x, so) return so class Searcher: def __init__(self): pass def enter(self): pass def exit(self): pass def enterConnectedPart(self): pass class TimeSearcher(Searcher): def __init__(self, graph): self.time = 0 self.parts = 0 self.dist = {} # nodes -> integer for node in graph.nodes: self.dist[node] = None def beforeEnter(self, v, cand, cost): self.dist[cand] = self.dist[v] + cost def enter(self): self.time += 1 # def exit(self): # self.time += 1 def enterConnectedPart(self, start): self.parts += 1 self.dist[start] = 0 def show(self): for node in self.dist: print(str(node) + " at " + str(self.dist[node])) def validate(self, graph): for v in graph.links: for w, cost in graph.links[v]: if self.dist[w] != self.dist[v] + cost: return False return True if __name__ == "__main__": g = Graph() g.readtext() so = TimeSearcher(g) so = g.depthfirstsearch(so) if so.validate(g): print("Yes") else: print("No")
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s676356918
Wrong Answer
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
n, m = map(int, input().split()) groups = [] wgroup = [-1] * (n + 1) dist = [-1] * (n + 1) newgroupid = 0 er = False for i in range(m): l, r, d = map(int, input().split()) if er: pass else: if wgroup[l] == -1 and wgroup[r] == -1: # l and r no group agroup = set() agroup.add(l) agroup.add(r) dist[l] = 0 dist[r] = d groups.append(agroup) wgroup[l] = newgroupid wgroup[r] = newgroupid newgroupid += 1 elif wgroup[l] != -1 and wgroup[r] == -1: # r to l-group groups[wgroup[l]].add(r) dist[r] = dist[l] + d wgroup[r] = wgroup[l] elif wgroup[l] == -1 and wgroup[r] != -1: # l to r-group groups[wgroup[r]].add(l) dist[l] = dist[r] - d wgroup[l] = wgroup[r] else: if wgroup[l] == wgroup[r]: # 同じグループである。 if d != dist[r] - dist[l]: er = True else: if len(groups[wgroup[l]]) >= len(groups[wgroup[r]]): diff = (dist[l] + d) - dist[r] for c in groups[wgroup[r]]: dist[c] += diff wgroup[c] = wgroup[r] newset = groups[wgroup[l]] | groups[wgroup[r]] groups[wgroup[l]] = newset else: diff = (dist[r] - d) - dist[l] for c in groups[wgroup[l]]: dist[c] += diff wgroup[c] = wgroup[l] newset = groups[wgroup[l]] | groups[wgroup[r]] groups[wgroup[r]] = newset for gr in groups: # 各グループの位置最小、最大の差が10**9以内か? if er: pass else: tmin = 9999999999 tmax = 0 for c in gr: tmin = min(tmin, dist[c]) tmax = max(tmax, dist[c]) if tmax - tmin > 10**9: er = True # else:print('dist ok') print("No" if er else "Yes")
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print `Yes`; if it does not exist, print `No`. * * *
s897721963
Runtime Error
p03450
Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M
import heapq def dijkstra(nodes, N): dist = [float("inf") for i in range(N + 2)] prev = [float("inf") for i in range(N + 2)] dist[0] = 0 q = [] heapq.heappush(q, (0, 0)) while len(q) != 0: prov_cost, src = heapq.heappop(q) if dist[src] < prov_cost: continue for nextnum, dis in nodes[src].nextnode: cost = dis if dist[nextnum] >= dist[src] + cost: dist[nextnum] = dist[src] + cost heapq.heappush(q, (dist[nextnum], nextnum)) prev[nextnum] = src return get_path(N + 1, prev) def get_path(goal, prev): path = [goal] dest = goal while prev[dest] != float("inf"): path.append(prev[dest]) dest = prev[dest] return list(reversed(path)) class People: def __init__(self, num): self.nodenum = num self.nextnode = [] def set_node(self, num, dis): self.nextnode.append((num, dis)) def node_adj(self): if self.nextnode == []: self.nextnode.append((self.nodenum + 1, 0)) N, M = (int(i) for i in input().split()) nodes = [] for i in range(N + 2): nodes.append(People(i)) for i in range(M): L, R, D = (int(i) for i in input().split()) nodes[L].set_node(R, D) for i in range(N + 1): nodes[i].node_adj() ans = dijkstra(nodes, N) flag = True for i in range(N + 1): if ans[i] != i: flag = False if flag: print("Yes") else: print("No")
Statement There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
[{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}]
Print the minimum number of bridges that must be removed. * * *
s927578709
Accepted
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
############################################################################### from sys import stdout from bisect import bisect_left as binl from copy import copy, deepcopy from collections import defaultdict mod = 1 def intin(): input_tuple = input().split() if len(input_tuple) <= 1: return int(input_tuple[0]) return tuple(map(int, input_tuple)) def intina(): return [int(i) for i in input().split()] def intinl(count): return [intin() for _ in range(count)] def modadd(x, y): global mod return (x + y) % mod def modmlt(x, y): global mod return (x * y) % mod def lcm(x, y): while y != 0: z = x % y x = y y = z return x def combination(x, y): assert x >= y if y > x // 2: y = x - y ret = 1 for i in range(0, y): j = x - i i = i + 1 ret = ret * j ret = ret // i return ret def get_divisors(x): retlist = [] for i in range(1, int(x**0.5) + 3): if x % i == 0: retlist.append(i) retlist.append(x // i) return retlist def get_factors(x): retlist = [] for i in range(2, int(x**0.5) + 3): while x % i == 0: retlist.append(i) x = x // i retlist.append(x) return retlist def make_linklist(xylist): linklist = {} for a, b in xylist: linklist.setdefault(a, []) linklist.setdefault(b, []) linklist[a].append(b) linklist[b].append(a) return linklist def calc_longest_distance(linklist, v=1): distance_list = {} distance_count = 0 distance = 0 vlist_previous = [] vlist = [v] nodecount = len(linklist) while distance_count < nodecount: vlist_next = [] for v in vlist: distance_list[v] = distance distance_count += 1 vlist_next.extend(linklist[v]) distance += 1 vlist_to_del = vlist_previous vlist_previous = vlist vlist = list(set(vlist_next) - set(vlist_to_del)) max_distance = -1 max_v = None for v, distance in distance_list.items(): if distance > max_distance: max_distance = distance max_v = v return (max_distance, max_v) def calc_tree_diameter(linklist, v=1): _, u = calc_longest_distance(linklist, v) distance, _ = calc_longest_distance(linklist, u) return distance ############################################################################### def main(): n, m = intin() ablist = intinl(m) ablist.sort() candidates = [] for a, b in ablist: if not candidates: candidates.append((a, b - 1)) continue ca, cb = candidates[-1] if a <= cb: candidates[-1] = (max(a, ca), min(b - 1, cb)) continue candidates.append((a, b - 1)) print(len(candidates)) if __name__ == "__main__": main()
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s378148898
Accepted
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
from sys import stdin n, m = [int(x) for x in stdin.readline().rstrip().split()] li = [list(map(int, stdin.readline().rstrip().split())) for _ in range(m)] li.sort() point = 1 lin = [1, n] for i in range(m): lin = [max(lin[0], li[i][0]), min(lin[1], li[i][1])] if lin[1] - lin[0] <= 0: point += 1 lin = li[i] print(point)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s831867880
Accepted
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
_, *l = [list(map(int, i.split())) for i in open(0)] l.sort(key=lambda x: x[1]) A = S = 0 for s, t in l: if S <= s: A += 1 S = t print(A)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s509130683
Runtime Error
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n,m = map(int, input().split()) a = [] for i in range(m): x,y = map(int, input().split()) a.append((x,y)) a.sort() ans = 1 l,r = a[0][] for x,y in a[1:]: if r <= x: ans += 1 r = x l = y else: r = max(r, y) print(ans)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s411973693
Runtime Error
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n,m=map(int, input().split()) ab=[list(map(int, input().split())) for _ in range(m)] ab.sort(key=lambda ab:ab[1]) ans=[ab[0]] for i in range(1:m): if ans[-1][1]<=ab[i][0]: ans.append(ab[i]) print(len(ans))
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s565774528
Runtime Error
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n,m=map(int,input().split()) ab=[] for _ in range(m): a,b=map(int,input().split()) ab.append([a,b]) ab.sort((key=lambda x: x[1])) cnt=0 border=0 for item in ab: if item[0]>=border: border=item[1] cnt+=1 print(cnt)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s917743851
Runtime Error
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
N = int(input()) A = [int(x) for x in input().split()] B = sorted([a - i - 1 for i, a in enumerate(A)]) if N % 2: median = B[N // 2] else: median = (B[(N - 1) // 2] + B[N // 2]) // 2 print(sum([abs(b - median) for b in B]))
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s374780348
Runtime Error
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
def main(): # Input [N, M] = list(map(int, input().rstrip().split(" "))) a, b = [], [] for i in range(M): [_a, _b] = list(map(int, input().rstrip().split(" "))) a.append(_a) b.append(_b) output = solve(N, M, a, b) print(output) def solve(N, M, a, b): # 切断したい橋の候補をboolean値で表す bool_list = [] for i in range(M): bool_list.append([True if (a[i] <= j+1) and (j+1 < b[i]) else False for j in range(N-1) ]) S = [bool_list] counter = 0 while S: C1 = S.pop() C2 = [] l1 = C1.pop(0) for l2 in C1: l3 = l1 and l2 l3 = [l1[i] and l2[i] for i in range(len(l1))] if sum(l3) == 0: # 積が「すべてFalseになった場合」は別のループを回す C2.append(l2) else: l1 = l3 if C2: # 別のループを回すためにSにpush S.append(C2) counter += 1 return counter if __name__ == "__main__": main()
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s385705499
Runtime Error
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n,m=map(int,input().split()) mx =[0 for i in range(0,n)] for z in range(0,m): a,b=map(int,input().split()) mx[b]=max(mx[b],a) cnt=0 cn=0 for z in range(0,n): if cut<mx[z]: cut=z cn=cn+1 print(cn)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s462561436
Runtime Error
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n,m=map(int,input().split()) mx =[0 for i in range(0,n)] for z in range(0,m): a,b=map(int,input().split()) mx[b-1]=max(mx[b-1],a-1) cut=0 cn=0 for z in range(0,n): if cut<mx[z]: cut=z cn=cn+1 print(cn)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s838276665
Runtime Error
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
N,M = map(int,input().split()) a,b = [0 for i in range(M)],[0 for i in range(M)] A,B = [0 for i in range(M)],[0 for i in range(M)] t = 0 for i in range(M): a[i],b[i] = map(int,input().split()) flug = -1 for j in range(t): if a[i]<A[j] and b[i]>B[j]: A[j] = b[i] B[j] = a[i] flug = 1 if flug = -1: A[t] = b[i] B[t] = a[i] t = t + 1 print(t)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s840417996
Runtime Error
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n, m = map(int,input().split()) todo = [] lis = [0 for _ in range(n+1)] for i in range(m): _ = list(map(int,input().split())) is[_[0] -1] += 1 lis[_[1] ] = lis[_[1] ] -1 for i in range(1,len(lis)): lis[i] = lis[i] + lis[i-1] count = 0 #print(lis) for i in range(len(lis)-1): if lis[i]>lis[i+1] and lis[i+1] != 0: count += 1 print(count)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s576500906
Runtime Error
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n, m = map(int, input().split()) ab = [] for i in range(m): a, b = map(int, input().split()) ab.append((a,b)) ab = sorted(ab, key = lambda x: x[[1]) left = 0 ans = 0 for a, b in ab: if a < left: ans += 1 left = b-1 print(ans)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s783386957
Runtime Error
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
#区間スケジューリング n, m = map(int, input().split()) lst = [] for _ in range(m): a, b = map(int, input().split()) lst.append([a, b]) lst.sort(key=lambda x:x[1]) ans = 0 ed = 0 for _ in lst: if _[0] < ed: else: ed = _[1] ans += 1 print(ans)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s487425239
Accepted
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
N, M = list(map(int, input().split(" "))) left_list = list() right_list = list() for _ in range(M): a, b = list(map(int, input().split(" "))) left_list.append(a) right_list.append(b) sorted_blocking_section_list = sorted(range(M), key=lambda i: right_list[i]) blocking_bridge = None blocking_bridge_cnt = 0 for section in sorted_blocking_section_list: left_bridge = left_list[section] right_bridge = right_list[section] - 1 if blocking_bridge is None or blocking_bridge < left_bridge: blocking_bridge = right_bridge blocking_bridge_cnt += 1 print(blocking_bridge_cnt)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s092285742
Accepted
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
m = lambda: map(int, input().split()) N, M = m() l = [tuple(m()) for _ in range(M)] ans = [] l.sort(key=lambda x: x[1]) for i in range(M): if not ans or ans[-1] < l[i][0]: ans.append(l[i][1] - 1) print(len(ans))
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s508668738
Accepted
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n, m = map(int, input().split()) wars = [] for _ in range(m): wars.append(tuple(map(int, input().split()))) wars.sort(key=lambda x: x[1]) last_distruction = -1 distruction = 0 for l, r in wars: if l > last_distruction: distruction += 1 last_distruction = r - 1 print(distruction)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s308755167
Accepted
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
a, b = list(map(int, input().split())) input_lines = [list(map(int, input().split())) for i in range(b)] input_lines = sorted( input_lines, key=lambda x: x[1] ) # 各要素において[1]に基づきソートする c = [0] for i in input_lines: # for j in c: # if j > i[0]: # p=1 if max(c) <= i[0]: c.append(i[1]) print(len(c) - 1)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s684270685
Wrong Answer
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
N, M = map(int, input().split()) banned_list = [] * M for i in range(M): banned_list.append(tuple(map(int, input().split()))) banned_briges = [set() for _ in range(N - 1)] for j, one in enumerate(banned_list): for i in range(one[0] - 1, one[1] - 1): banned_briges[i] |= {j} banned_num = [len(one) for one in banned_briges] counter = 0 while sum([sum(one) for one in banned_briges]) != 0: remove_index = banned_num.index(max(banned_num)) remove_island = banned_briges[remove_index] banned_briges = [one - remove_island for one in banned_briges] banned_num = [len(one) for one in banned_briges] counter += 1 print(counter)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s143706037
Accepted
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
N, M, *L = map(int, open(0).read().split()) sheet = [[[], []] for i in range(N + 1)] for i, m in enumerate(zip(*[iter(L)] * 2)): sheet[m[0]][0].append(i) sheet[m[1]][1].append(i) ans = 0 log = set() cnt = set() for i in range(1, N + 1): for x in sheet[i][1]: if x not in log: ans += 1 log = log.union(cnt) cnt = set() for x in sheet[i][0]: cnt.add(x) print(ans)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s601636293
Wrong Answer
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n, m = map(int, input().split()) ab = [list(map(int, input().split())) for _ in [0] * m] hm = {} for a, b in ab: if (b - a) in hm.keys(): hm[b - a] += [(a, b)] else: hm[b - a] = [(a, b)] hmk = sorted(hm.keys()) l = [False] * n for k in hmk: c = hm[k] if k == 1: for a, _ in c: l[a] = True else: for a, b in c: if True in l[a:b]: pass else: l[b - 1] = True print(l.count(True))
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the minimum number of bridges that must be removed. * * *
s823936047
Wrong Answer
p03295
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
# 方針 もっとも近い敵でない島の集まりを調べると区間スケジュール問題となる。 # 一列に並んでいるので飛んだ島とは繋げない # 橋の取り壊しの最小値というが、分割としてはもっとも番号の若いものまでしか無理である。 # 最近接の敵である島の数字をもつ配列を考える。 N, M = (int(_) for _ in input().split()) mostNeightborOpponent = [N + 1 for _ in range(N)] # print(mostNeightborOpponent) for i in range(M): a, b = (int(_) for _ in input().split()) if mostNeightborOpponent[a - 1] > b: mostNeightborOpponent[a - 1] = b # print(mostNeightborOpponent) # island:・・・島|島・・・の右の島のindex island = 1 bridgeWillBreak = 0 while island < N: minOpIsland = mostNeightborOpponent[island - 1] for i in range(island - 1, N): if minOpIsland > mostNeightborOpponent[i]: minOpIsland = mostNeightborOpponent[i] # print(minOpIsland) island = minOpIsland if island >= N: break bridgeWillBreak += 1 print(bridgeWillBreak)
Statement There are N islands lining up from west to east, connected by N-1 bridges. The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed.
[{"input": "5 2\n 1 4\n 2 5", "output": "1\n \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n 1 8\n 2 7\n 3 5\n 4 6\n 7 9", "output": "2\n \n\n* * *"}, {"input": "5 10\n 1 2\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 4\n 3 5\n 4 5", "output": "4"}]
Print the reversed str in a line.
s441661847
Runtime Error
p00006
str (the size of str ≤ 20) is given in a line.
print(input[::-1])
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s012528208
Accepted
p00006
str (the size of str ≤ 20) is given in a line.
# 0006 x = str(input()) y = "".join(list(reversed(x))) print(y)
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s659539917
Accepted
p00006
str (the size of str ≤ 20) is given in a line.
print("".join(reversed(input()))) # ????????????????
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s591399247
Accepted
p00006
str (the size of str ≤ 20) is given in a line.
S = "" for i in input(): S = i + S print(S)
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s104232112
Wrong Answer
p00006
str (the size of str ≤ 20) is given in a line.
a = list(list(map(str, input().split())))
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s526007596
Runtime Error
p00006
str (the size of str ≤ 20) is given in a line.
date = str(input()).reverse() print(date)
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s103172909
Accepted
p00006
str (the size of str ≤ 20) is given in a line.
a = str(input()) b = list(reversed(a)) c = "".join(list(reversed(a))) print(c)
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s865028366
Runtime Error
p00006
str (the size of str ≤ 20) is given in a line.
print(input().reverse())
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s199250397
Runtime Error
p00006
str (the size of str ≤ 20) is given in a line.
print(input().reversed)
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s963627881
Wrong Answer
p00006
str (the size of str ≤ 20) is given in a line.
print(input()[-1])
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s909060046
Accepted
p00006
str (the size of str ≤ 20) is given in a line.
str = list(input()) rstr = str[::-1] print(*rstr, sep="")
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s392653024
Accepted
p00006
str (the size of str ≤ 20) is given in a line.
S = input() N = len(S) for i in range(N): print(S[N - i - 1], end="") print("")
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s223899236
Accepted
p00006
str (the size of str ≤ 20) is given in a line.
print("".join(reversed(input())))
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s127093588
Accepted
p00006
str (the size of str ≤ 20) is given in a line.
alpha = input() alpha = alpha[::-1] print(alpha)
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s607480231
Wrong Answer
p00006
str (the size of str ≤ 20) is given in a line.
print(input()[::-3])
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s758526449
Accepted
p00006
str (the size of str ≤ 20) is given in a line.
st = input() ans = "" for i in range(len(st)): ans += st[len(st) - i - 1] print(ans)
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s226186162
Accepted
p00006
str (the size of str ≤ 20) is given in a line.
spam = input() spam = [i for i in spam] spam.reverse() spam = "".join(spam) print(spam)
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the reversed str in a line.
s712125378
Wrong Answer
p00006
str (the size of str ≤ 20) is given in a line.
print(str(reversed(input())))
Reverse Sequence Write a program which reverses a given string str.
[{"input": "w32nimda", "output": "admin23w"}]
Print the number of the unnecessary cards. * * *
s019737048
Runtime Error
p03780
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
import itertools N,K = map(int,input().split()) A = list(map(int,input().split())) A.sort() need = [] iranaiko = [] for a in A: if a >= K: need.append(a) elif a in need: need.append(a) elif a in iranaiko: pass else: z = 0 B = A[:] B.remove(a) fusoku = [K - i - 1 for i in range(a)] for bi,b in enumerate(B): if b >= K: break B = B[:bi + 1] for i in range(1,len(B) + 1): C = list(itertools.combinations(B,i)) for c in C: if sum(c) in fusoku: need.append(a) z = 1 break if z == 1: break if z == 0: iranaiko.append(a) print(N - len(need))
Statement AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards _good_ when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is _unnecessary_ or not, as follows: * If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. * Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
[{"input": "3 6\n 1 4 3", "output": "1\n \n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is\nalso good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is\nNOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\n* * *"}, {"input": "5 400\n 3 1 4 1 5", "output": "5\n \n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\n* * *"}, {"input": "6 20\n 10 4 3 10 25 2", "output": "3"}]
Print the number of the unnecessary cards. * * *
s495994085
Wrong Answer
p03780
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
from itertools import accumulate N, K = map(int, input().split()) A = list(map(int, input().split())) # K以上の数はすべて必要なのでA未満の数だけを考える A = sorted([a for a in A if a < K], reverse=True) N = len(A) need = 0 for n in range(N): # 何枚目のカードについての判定か # dp1[k]:= 1 ~ i - 1までのカードを使って数jが作れるか dp1 = [0] * (K + 1) dp1[0] = 1 for i in range(n): for j in range(K, -1, -1): if A[i] > j: continue dp1[j] = dp1[j - A[i]] # dp2[k] := N ~ i + 1までのカードを使って数jが作れるか dp2 = [0] * (K + 1) dp2[0] = 1 for i in range(n + 1, N): for j in range(K, -1, -1): if A[i] > j: continue dp2[j] = dp2[j - A[i]] dp2 = list(accumulate(dp2)) for k in range(K + 1): # 1 ~ i - 1番目まででkが作れない if not dp1[k]: continue # 1 ~ i - 1番目までだけで必要な条件が作れる if K - A[n] <= k < K: need += 1 break # 範囲外参照 if K - A[n] - k - 1 < 0: continue # 累積和を用いてkと組み合わせて、条件の範囲内に対応する値がN ~ i + 1までのカードで作れるかを判定 if dp2[K - k] - dp2[K - A[n] - k - 1] > 0: need += 1 break print(N - need)
Statement AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards _good_ when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is _unnecessary_ or not, as follows: * If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. * Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
[{"input": "3 6\n 1 4 3", "output": "1\n \n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is\nalso good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is\nNOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\n* * *"}, {"input": "5 400\n 3 1 4 1 5", "output": "5\n \n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\n* * *"}, {"input": "6 20\n 10 4 3 10 25 2", "output": "3"}]
Print the number of the unnecessary cards. * * *
s091121419
Accepted
p03780
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") AZ = "abcdefghijklmnopqrstuvwxyz" ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2, N + 1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) def base_10_to_n_without_0(X, n): X -= 1 if X // n: return base_10_to_n_without_0(X // n, n) + [X % n] return [X % n] #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N, K = IL() A = IL() A.sort(reverse=True) ans = 0 now = 0 cnt = 0 for i in range(N): a = A[i] if now + a >= K: ans += cnt + 1 cnt = 0 else: now += a cnt += 1 print(N - ans)
Statement AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards _good_ when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is _unnecessary_ or not, as follows: * If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. * Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
[{"input": "3 6\n 1 4 3", "output": "1\n \n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is\nalso good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is\nNOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\n* * *"}, {"input": "5 400\n 3 1 4 1 5", "output": "5\n \n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\n* * *"}, {"input": "6 20\n 10 4 3 10 25 2", "output": "3"}]
Print the number of the unnecessary cards. * * *
s615384881
Runtime Error
p03780
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
import sys def findminsum(lst,K,N): inf=10**10 dp=[[inf]*N for s in range(K+1)] for s in range(K+1): for j in range(N): if j==0 and s<=lst[j] ds[s][j]=lst[0] elif s>lst[j] and j>0: dp[s][j]=min(dp[s-lst[j]][j-1]+lst[j], dp[s][j-1]) elif s<=lst[j] and j>0: dp[s][j]=min(lst[j],dp[s][j-1]) # print(lst) # print(dp[0][:]) # print(dp[1][:]) # print(dp[K][:]) return dp[K][N-1] def main(): N,K=map(int,sys.stdin.readline().strip().split()) cards=list(map(int,sys.stdin.readline().strip().split())) cards.sort() nn=0 for i in range(N): if cards[i]<K: c=cards[i] cards[i]=0 if findminsum(cards,K-c,N)>=K: nn+=1 cards[i]=c else: break print(nn) if __name__=='__main__': main()
Statement AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards _good_ when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is _unnecessary_ or not, as follows: * If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. * Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
[{"input": "3 6\n 1 4 3", "output": "1\n \n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is\nalso good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is\nNOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\n* * *"}, {"input": "5 400\n 3 1 4 1 5", "output": "5\n \n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\n* * *"}, {"input": "6 20\n 10 4 3 10 25 2", "output": "3"}]
Print the number of the unnecessary cards. * * *
s057620758
Runtime Error
p03780
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0;i < n;i++) #define REPR(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++) typedef long long llong; char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; char moji3[10]={'0','1','2','3','4','5','6','7','8','9'}; #define Sort(a) sort(a.begin(),a.end()); #define Reverse(a) reverse(a.begin(),a.end()); #define print(a) cout << a << endl; #define n_max 5005 int A[n_max]; int n,k; bool judge( int ind){ int dp[5000]={}; if(A[ind] >=k) return true; dp[0]=1; REP(i,n){ int a= A[i]; if(i==ind) continue; REPR(j,k){ if( j-a >= 0 and dp[j-a] ==1 ) dp[j]=1; } } FOR(i,k-A[ind],k) if(dp[i] == 1) return true; return false; } int main(){ cin >> n >> k; REP(i,n) cin >> A[i]; sort(A,A+n); int left = -1; int right = n-1; int mid; while(1){ if(left + 1 >= right ) break; mid=(left + right) / 2; if(judge(mid)){ right= mid-1 ; } else left = mid; } if(judge(right)){ cout << left + 1 << endl; } else cout << right +1 << endl; }
Statement AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards _good_ when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is _unnecessary_ or not, as follows: * If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. * Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
[{"input": "3 6\n 1 4 3", "output": "1\n \n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is\nalso good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is\nNOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\n* * *"}, {"input": "5 400\n 3 1 4 1 5", "output": "5\n \n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\n* * *"}, {"input": "6 20\n 10 4 3 10 25 2", "output": "3"}]
Print the number of the unnecessary cards. * * *
s363631033
Accepted
p03780
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
def d_NoNeed(N, K, A): a = sorted(A) s = t = 0 # aのうち要素が大きいものから見ていったとき、 # その要素を入れても総和がK未満のものだけ加えていく # 最後に連続して加えた要素の個数が解となる # (それら以外の要素の組み合わせでK以上にでき、かつ、 # それらの総和がK未満になるため) for i in range(N - 1, -1, -1): if s + a[i] < K: s += a[i] t += 1 else: t = 0 return t N, K = [int(i) for i in input().split()] A = [int(i) for i in input().split()] print(d_NoNeed(N, K, A))
Statement AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards _good_ when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is _unnecessary_ or not, as follows: * If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. * Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
[{"input": "3 6\n 1 4 3", "output": "1\n \n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is\nalso good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is\nNOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\n* * *"}, {"input": "5 400\n 3 1 4 1 5", "output": "5\n \n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\n* * *"}, {"input": "6 20\n 10 4 3 10 25 2", "output": "3"}]
Print the number of the unnecessary cards. * * *
s983988441
Runtime Error
p03780
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
N,K = map(int,input().split()) a = list(map(int,input().split())) a.sort() if a[0] >= K: print(0) exit() a = [a[i] for i in range(N) if a[i]<K] a.reverse() N = len(a) ans = N dp = [False]*K dp[0] = True Smax = 0 for i in range(N): a_ = a[i] if Smax + a_ >= K: ans = N-i-1 updated = False for j in range(min(Smax,K-a_-1),-1,-1): if dp[j]: dp[j+a_=True if not updated: Smax = max(Smax,j+a_) updated = True print(ans)
Statement AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards _good_ when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is _unnecessary_ or not, as follows: * If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. * Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
[{"input": "3 6\n 1 4 3", "output": "1\n \n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is\nalso good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is\nNOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\n* * *"}, {"input": "5 400\n 3 1 4 1 5", "output": "5\n \n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\n* * *"}, {"input": "6 20\n 10 4 3 10 25 2", "output": "3"}]
Print the number of the unnecessary cards. * * *
s800112841
Wrong Answer
p03780
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
n, k = list(map(int, input().split(" "))) a = list(map(int, input().split(" "))) s = sum(a) c = 0 if s < k: print(len(a)) exit() for i in a: if s - i > k: c += 1 print(c)
Statement AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards _good_ when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is _unnecessary_ or not, as follows: * If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. * Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
[{"input": "3 6\n 1 4 3", "output": "1\n \n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is\nalso good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is\nNOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\n* * *"}, {"input": "5 400\n 3 1 4 1 5", "output": "5\n \n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\n* * *"}, {"input": "6 20\n 10 4 3 10 25 2", "output": "3"}]
Print the number of the unnecessary cards. * * *
s028124288
Wrong Answer
p03780
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
from itertools import chain, combinations def powersetoverK(iterable): return list( filter( lambda x: sum(map(int, x)) >= K, chain.from_iterable( combinations(iterable, r) for r in range(len(iterable) + 1) ), ) ) N, K = map(int, input().split()) a = input().split() print( N - sum( [ len(powersetoverK(a[: i - 1] + a[i:])) == 0 and len(powersetoverK(a)) > 0 for i in range(1, N + 1) ] ) )
Statement AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards _good_ when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is _unnecessary_ or not, as follows: * If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. * Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
[{"input": "3 6\n 1 4 3", "output": "1\n \n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is\nalso good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is\nNOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\n* * *"}, {"input": "5 400\n 3 1 4 1 5", "output": "5\n \n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\n* * *"}, {"input": "6 20\n 10 4 3 10 25 2", "output": "3"}]
Print the number of the unnecessary cards. * * *
s472957019
Wrong Answer
p03780
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
N, K = map(int, input().split()) tmp = list(map(int, input().split())) card = [] ans = 0 for c in tmp: if c < K: card.append(c) dpf = [] dpr = [] dpf.append([0] * K) dpr.append([0] * K) dpf[0][0] = 1 dpr[0][0] = 1 for i in range(len(card)): tmp = [0] * K c = card[i] for j in range(K - c): if dpf[-1][j] == 1: tmp[j + c] = 1 tmp[j] = 1 dpf.append(tmp) for i in reversed(range(len(card))): tmp = [0] * K c = card[i] for j in range(K - c): if dpr[-1][j] == 1: tmp[j + c] = 1 tmp[j] = 1 dpr.append(tmp) reversed(dpr) print(dpf) print(dpr) ans = len(card) for i in range(len(card)): x = dpf[i] y = dpr[len(card) - i - 1] itx = 0 ity = K - 1 c = card[i] for j in range(K): if x[itx] == 1: break itx += 1 for j in range(K): if y[ity] == 1: break ity -= 1 while True: if itx + ity >= K - c and itx + ity < K: ans -= 1 break if itx + ity < K - c: if itx == K - 1: itx += 1 while itx + 1 < K: itx += 1 if x[itx] == 1: break if itx == K - 1 and x[itx] == 0: itx += 1 if itx >= K: break if itx + ity >= K: if ity == 0: ity -= 1 while ity - 1 >= 0: ity -= 1 if y[ity] == 1: break if ity == 0 and y[ity] == 0: ity -= 1 if ity < 0: break print(ans)
Statement AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards _good_ when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is _unnecessary_ or not, as follows: * If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. * Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
[{"input": "3 6\n 1 4 3", "output": "1\n \n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is\nalso good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is\nNOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\n* * *"}, {"input": "5 400\n 3 1 4 1 5", "output": "5\n \n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\n* * *"}, {"input": "6 20\n 10 4 3 10 25 2", "output": "3"}]
Print the number of the unnecessary cards. * * *
s360601217
Runtime Error
p03780
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
n, k = map(int, input().split()) a = list(map(int, input().split())) sm = sum(a) if k > sm: print(n) else: table = [[0] for i in range(2 * k)] table[0] = [-1] for elm in a: idxlist = [] for i in range(2 * k): if table[i] != [0]: if i + elm < 2 * k: idxlist.append(i + elm) for idx in idxlist: table[idx].extend(table[idx - elm]) table[idx].append(elm) need = 0 for elm in a: if elm >= k: need += 1 else: flag = False for i in range(k, k + elm): if elm in table[i]: need += 1 break print(n - need)
Statement AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards _good_ when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is _unnecessary_ or not, as follows: * If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. * Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
[{"input": "3 6\n 1 4 3", "output": "1\n \n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is\nalso good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is\nNOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\n* * *"}, {"input": "5 400\n 3 1 4 1 5", "output": "5\n \n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\n* * *"}, {"input": "6 20\n 10 4 3 10 25 2", "output": "3"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s871479946
Wrong Answer
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
n, k = map(int, input().split()) hate_list = map(int, input().split()) p_list = [] ok_list = [] s = 0 for x in hate_list: while x > s: ok_list.append(s) s += 1 s += 1 ok_list.append(10) # nの桁をリスト化 ndgts = [] while n > 0: ndgts.append(n % 10) n //= 10 flag = 0 # necessality of a comparison for y in reversed(ndgts): if flag > 0: p_list.append(0) continue for x in range(11 - k): if y == ok_list[x]: p_list.append(x) break elif y < ok_list[x]: p_list.append(x) flag = 1 break # print(p_list) p_list.reverse() for x in range(len(p_list) - 1): if p_list[x] == 10 - k: p_list[x] = 0 p_list[x + 1] += 1 if p_list[-1] == 10 - k: p_list[-1] = 0 if ok_list[0] == 0: p_list.append(1) else: p_list.append(0) payment = 0 # print(p_list) for x in reversed(p_list): payment = 10 * payment + ok_list[x] print(payment)
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s969313017
Wrong Answer
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
from itertools import combinations_with_replacement n, k = map(int, input().split()) d = [int(x) for x in input().split()] dd = set(list(range(10))) - set(d) x = str(n) lst = [] dd = list(dd) dd.sort() sel = [] for i in dd: if int(x[0]) <= i and len(sel) < 3: sel.append(i * 10 ** (len(x) - 1)) if len(sel) < 2: if len(dd) == 1: sel.append((dd[0] * 10 + dd[0]) * 10 ** (len(x) - 1)) else: if dd[0] != 0: sel.append((dd[0] * 10 + dd[1]) * 10 ** (len(x) - 1)) else: sel.append((dd[1] * 10 + dd[0]) * 10 ** (len(x) - 1)) for j in sel: for l in combinations_with_replacement(dd, len(x) - 1): cnt = j for i in range(len(x) - 1): cnt += 10 ** (len(x) - i - 2) * l[i] if cnt >= n: lst.append(cnt) print(min(lst))
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s533710138
Accepted
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
N, K, *D = map(int, open(0).read().split()) Ds = set(D) item = set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) - Ds strs = set(str(x) for x in item) for i in range(N, 10000): s = set(str(i)) if s.issubset(strs): print(i) break else: il = list(item) il.sort() if il[0] == 0: ans = [str(il[1])] + ([str(il[0])] * len(str(N))) print("".join(ans)) else: ans = [str(il[0])] * (len(str(N)) + 1) print("".join(ans))
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s974401356
Wrong Answer
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
N, K = map(int, input().split()) D = list(map(int, input().split())) A = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for i in range(0, K): A.remove(D[i]) A = sorted(A) B = A B.append(0) ans = 0 M = str(N) L = len(M) if A[0] == 0: ans += 111111 * A[1] else: ans += 111111 * A[0] if L == 5: for q in range(0, 11 - K): for w in range(0, 10 - K): for e in range(0, 10 - K): for r in range(0, 10 - K): for t in range(0, 10 - K): for y in range(0, 10 - K): if ( ans >= 1000 * (100 * B[q] + 10 * A[w] + A[e]) + 100 * A[r] + 10 * A[t] + A[y] >= N ): ans = ( 1000 * (100 * B[q] + 10 * A[w] + A[e]) + 100 * A[r] + 10 * A[t] + A[y] ) elif L == 4: for q in range(0, 11 - K): for w in range(0, 10 - K): for e in range(0, 10 - K): for r in range(0, 10 - K): for t in range(0, 10 - K): if ( ans >= 100 * (100 * B[q] + 10 * A[w] + A[e]) + 10 * A[r] + A[t] >= N ): ans = ( 100 * (100 * B[q] + 10 * A[w] + A[e]) + 10 * A[r] + A[t] ) elif L == 3: for q in range(0, 11 - K): for w in range(0, 10 - K): for e in range(0, 10 - K): for r in range(0, 10 - K): if ans >= 10 * (100 * B[q] + 10 * A[w] + A[e]) + A[r] >= N: ans = 10 * (100 * B[q] + 10 * A[w] + A[e]) + A[r] elif L == 2: for q in range(0, 11 - K): for w in range(0, 10 - K): for e in range(0, 10 - K): if ans >= 100 * B[q] + 10 * A[w] + A[e] >= N: ans = 100 * B[q] + 10 * A[w] + A[e] else: for q in range(0, 11 - K): for w in range(0, 10 - K): if ans >= 10 * B[q] + A[w]: ans = 10 * B[q] + A[w] print(ans)
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s745574367
Accepted
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
#!/usr/bin/env python3 import sys # import math # from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from copy import deepcopy # to copy multi-dimentional matrix without reference # from fractions import gcd # for Python 3.4 (previous contest @AtCoder) def main(): mod = 1000000007 # 10^9+7 inf = float("inf") # sys.float_info.max = 1.79...e+308 # inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x) - 1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x) - 1, input().split())) def li(): return list(input()) n, k = mi() dislike = input().split() start = n while True: # print(start) for digit in str(start): if digit in dislike: start += 1 break else: print(start) exit() if __name__ == "__main__": main()
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s565426486
Runtime Error
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
n, k = map(int, input().split()) dislikes = list(map(int, input().split()) m = n while True: m = list(str(m)) l = [] for p in m: if int(p) not in dislikes: l.append(p) continue else: m = int(''.join(m))+1 break if len(l) >= len(str(n)): if int(''.join(l))>=n: break print(''.join(m))
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s795267920
Runtime Error
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
n,k = map(int, input().split()) li = [] i = 0 for i<k: li.append(int(input())) i += 1 else: Li = list(n) while not set(li)&set(Li) == {}: n += 1 Li = list(n) else: print("".join(Li))
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s457525529
Accepted
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
import sys from sys import exit from collections import deque from copy import deepcopy from bisect import bisect_left, bisect_right, insort_left, insort_right from heapq import heapify, heappop, heappush from itertools import product, permutations, combinations, combinations_with_replacement from functools import reduce from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9 + 7 def lcm(x, y): return x * y // gcd(x, y) def lgcd(l): return reduce(gcd, l) def llcm(l): return reduce(lcm, l) def powmod(n, i, mod=MOD): return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod) def div2(x): return x.bit_length() def div10(x): return len(str(x)) - (x == 0) def intput(): return int(input()) def mint(): return map(int, input().split()) def lint(): return list(map(int, input().split())) def ilint(): return int(input()), list(map(int, input().split())) def judge(x, l=["Yes", "No"]): print(l[0] if x else l[1]) def lprint(l, sep="\n"): for x in l: print(x, end=sep) def ston(c, c0="a"): return ord(c) - ord(c0) def ntos(x, c0="a"): return chr(x + ord(c0)) class counter(dict): def __init__(self, *args): super().__init__(args) def add(self, x, d=1): self.setdefault(x, 0) self[x] += d def list(self): l = [] for k in self: l.extend([k] * self[k]) return l class comb: def __init__(self, n, mod=None): self.l = [1] self.n = n self.mod = mod def get(self, k): l, n, mod = self.l, self.n, self.mod k = n - k if k > n // 2 else k while len(l) <= k: i = len(l) l.append( l[i - 1] * (n + 1 - i) // i if mod == None else (l[i - 1] * (n + 1 - i) * powmod(i, -1, mod)) % mod ) return l[k] def pf(x, mode="counter"): C = counter() p = 2 while x > 1: k = 0 while x % p == 0: x //= p k += 1 if k > 0: C.add(p, k) p = p + 2 - (p == 2) if p * p < x else x if mode == "counter": return C S = set([1]) for k in C: T = deepcopy(S) for x in T: for i in range(1, C[k] + 1): S.add(x * (k**i)) if mode == "set": return S if mode == "list": return sorted(list(S)) ###################################################### N, K = mint() D = lint() S = set([str(d) for d in D]) for x in range(N, 100000): s = str(x) tmp = True for i in range(len(s)): if s[i] in S: tmp = False break if tmp: print(x) exit()
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s090531824
Wrong Answer
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
# @oj: atcoder # @id: hitwanyang # @email: [email protected] # @date: 2020-08-13 22:50 # @url:https://atcoder.jp/contests/abc042/tasks/arc058_a import sys, os from io import BytesIO, IOBase import collections, itertools, bisect, heapq, math, string from decimal import * # region fastio BUFSIZE = 8192 BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ def main(): n, k = map(int, input().split()) d = list(map(int, input().split())) mx = 10000 ans = 10000 while mx >= 0: temp = str(mx) f = True for i in range(len(temp)): if int(temp[i]) in d: f = False break if f and mx >= n: ans = min(ans, mx) mx = mx - 1 print(ans) if __name__ == "__main__": main()
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s910040309
Accepted
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
N, K = map(int, input().split(" ")) list_num = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] D = input().split(" ") use_num = list(set(list_num) - set(D)) ok = [] for a in use_num: ok.append(a) for b in use_num: ok.append(a + b) for c in use_num: ok.append(a + b + c) for d in use_num: ok.append(a + b + c + d) for e in use_num: ok.append(a + b + c + d + e) ans = [] for i in ok: if int(i) >= N: ans.append(int(i)) print(min(ans))
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s796667941
Accepted
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
import sys import math import collections import itertools import array import inspect # Set max recursion limit sys.setrecursionlimit(1000000) # Debug output def chkprint(*args): names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()} print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args)) # Binary converter def to_bin(x): return bin(x)[2:] def li_input(): return [int(_) for _ in input().split()] def gcd(n, m): if n % m == 0: return m else: return gcd(m, n % m) def gcd_list(L): v = L[0] for i in range(1, len(L)): v = gcd(v, L[i]) return v def lcm(n, m): return (n * m) // gcd(n, m) def lcm_list(L): v = L[0] for i in range(1, len(L)): v = lcm(v, L[i]) return v # Width First Search (+ Distance) def wfs_d(D, N, K): """ D: 隣接行列(距離付き) N: ノード数 K: 始点ノード """ dfk = [-1] * (N + 1) dfk[K] = 0 cps = [(K, 0)] r = [False] * (N + 1) r[K] = True while len(cps) != 0: n_cps = [] for cp, cd in cps: for i, dfcp in enumerate(D[cp]): if dfcp != -1 and not r[i]: dfk[i] = cd + dfcp n_cps.append((i, cd + dfcp)) r[i] = True cps = n_cps[:] return dfk # Depth First Search (+Distance) def dfs_d(v, pre, dist): """ v: 現在のノード pre: 1つ前のノード dist: 現在の距離 以下は別途用意する D: 隣接リスト(行列ではない) D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト """ global D global D_dfs_d D_dfs_d[v] = dist for next_v, d in D[v]: if next_v != pre: dfs_d(next_v, v, dist + d) return def sigma(N): ans = 0 for i in range(1, N + 1): ans += i return ans def comb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2, r + 1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p - 1, r, p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result def bisearch(L, target): low = 0 high = len(L) - 1 while low <= high: mid = (low + high) // 2 guess = L[mid] if guess == target: return True elif guess < target: low = mid + 1 elif guess > target: high = mid - 1 if guess != target: return False # -------------------------------------------- dp = None def main(): N, K = li_input() D = input().split() c_money = N while True: is_dislike = False for a in set(str(c_money)): if a in D: is_dislike = True break if is_dislike: c_money += 1 else: print(c_money) return main()
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s102458951
Accepted
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
n, k = [int(i) for i in input().split()] d = [int(i) for i in input().split()] ok = [1 for i in range(10)] for i in range(len(d)): ok[d[i]] = -1 for i in range(n, 100000): complete = True for j in range(len(str(i))): if ok[int(str(i)[j])] == -1: complete = False break if complete: print(i) exit() """ import copy def listToString(_list, split=""): maped_list = map(str, _list) # mapで要素すべてを文字列に mojiretu = split.join(maped_list) return mojiretu n, k = [int(i) for i in input().split()] d = [int(i) for i in input().split()] ok = [1 for i in range(10)] for i in range(len(d)): ok[d[i]] = -1 # nをしたの位から順に置き換えていく money = [0] for i in range(len(str(n))): money.append(int(str(n)[i])) # 最小でなくともn以上の整数を作る for i in reversed(range(1, len(money))): for j in range(money[i], 10+money[i]): _j = j % 10 if ok[_j] == 1: if _j >= money[i]: money[i] = _j break else: money[i] = _j # print("okList:{}".format(ok)) # print(money) while True: if money[0] != 0: break else: del(money[0]) # print(money) # 次に可能な限り最小化していく for i in range(len(money)): for j in range(10): if ok[j] == 1: tmpMoney = copy.deepcopy(money) tmpMoney[i] = j # print("n:{} tmpMoney:{}".format(n, int(listToString(tmpMoney)))) if int(listToString(tmpMoney)) >= n: # print("money:{}".format(money)) money[i] = j break print(int(listToString(money))) """
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s092788160
Accepted
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
N, K = map(int, input().split()) L = input() def func1(N): if len(str(N)) == 5: if ( str(N)[0] in L or str(N)[1] in L or str(N)[2] in L or str(N)[3] in L or str(N)[4] in L ): return False elif len(str(N)) == 4: if str(N)[0] in L or str(N)[1] in L or str(N)[2] in L or str(N)[3] in L: return False elif len(str(N)) == 3: if str(N)[0] in L or str(N)[1] in L or str(N)[2] in L: return False elif len(str(N)) == 2: if str(N)[0] in L or str(N)[1] in L: return False elif len(str(N)) == 1: if str(N)[0] in L: return False else: return True while func1(N) == False: N += 1 print(N)
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s167636672
Accepted
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
# # Written by NoKnowledgeGG @YlePhan # ('ω') # # import math # mod = 10**9+7 # import itertools # import fractions # import numpy as np # mod = 10**4 + 7 """def kiri(n,m): r_ = n / m if (r_ - (n // m)) > 0: return (n//m) + 1 else: return (n//m)""" """ n! mod m 階乗 mod = 1e9 + 7 N = 10000000 fac = [0] * N def ini(): fac[0] = 1 % mod for i in range(1,N): fac[i] = fac[i-1] * i % mod""" """mod = 1e9+7 N = 10000000 pw = [0] * N def ini(c): pw[0] = 1 % mod for i in range(1,N): pw[i] = pw[i-1] * c % mod""" """ def YEILD(): yield 'one' yield 'two' yield 'three' generator = YEILD() print(next(generator)) print(next(generator)) print(next(generator)) """ """def gcd_(a,b): if b == 0:#結局はc,0の最大公約数はcなのに return a return gcd_(a,a % b) # a = p * b + q""" """def extgcd(a,b,x,y): d = a if b!=0: d = extgcd(b,a%b,y,x) y -= (a//b) * x print(x,y) else: x = 1 y = 0 return d""" def readInts(): return list(map(int, input().split())) def main(): n, k = readInts() D = input().split() # print(D) # print(list(str(now))) # print(set(str(n)) & set(D)) # print({'2','5'} & {'2'}) while set(str(n)) & set(D): n += 1 print(n) if __name__ == "__main__": main()
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s798348466
Accepted
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
N, K = list(map(int, input().split(" "))) D = list(map(int, input().split(" "))) # print(N, K) # print(D) obse_num = [0 for i in range(10)] for i in range(K): obse_num[D[i]] = 1 pay_money = N while 1: obse_flag = 1 S = list(str(pay_money)) for char in S: if obse_num[int(char)] == 1: obse_flag = 0 break if obse_flag == 1: break pay_money += 1 print(pay_money)
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s506011827
Accepted
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
# At BC 042 C (300) # find first digit (from the left) # that needs to be changed. # if that digit is incremented, then # decrement everything after it as much as possible # if that digit has to be decremented, then increase (or insert) a digit # before that digit and then decrement everything after the incremented digit # def dec(i, D): for k in range(i - 1, -1, -1): if k not in D: return k return i def inc(i, D): for k in range(i + 1, 10): if k not in D: return k return i def max_dec_or_inc(A, start, D): for j in range(start, len(A)): d = dec(A[j], D) if d != A[j]: while d != A[j]: A[j] = d d = dec(A[j], D) elif A[j] in D: # must change u = inc(i, D) A[j] = u def inc_one(A, end, D): for j in range(end - 1, -1, -1): up = inc(A[j], D) if up != A[j]: A[j] = up return j A.insert(0, inc(0, D)) return 0 def f(n, D): out = list(map(int, str(n))) for j, i in enumerate(out): if i in D: # first from left that needs to be changed up = inc(i, D) if up != i: # possible to increment at j out[j] = up # decrement everything after j max_dec_or_inc(out, j + 1, D) else: # must decrement at index j out[j] = dec(i, D) # increment one before j idx = inc_one(out, j, D) # decrement everything after j max_dec_or_inc(out, idx + 1, D) break r = int("".join([str(x) for x in out])) return r assert f(1000, [1, 3, 4, 5, 6, 7, 8, 9]) == 2000 assert f(9999, [0]) == 9999 assert f(6888, [8, 9]) == 7000 assert f(9999, [9]) == 10000 assert f(9999, [0, 9]) == 11111 assert f(9999, [0, 1, 9]) == 22222 n, k = map(int, input().split()) D = list(sorted(map(int, input().split()))) ans = f(n, D) print(ans)
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s056751290
Accepted
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N, K = IL() D = IL() for i in range(N, 100000): flag = 1 for j in str(i): if int(j) in D: flag = 0 if flag: print(i) exit()
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s501167089
Wrong Answer
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
# coding:UTF-8 import sys def resultSur97(x): return x % (10**9 + 7) if __name__ == "__main__": # ------ 入力 ------# nk = list(map(int, input().split())) # スペース区切り連続数字 x = nk[1] dList = list(map(int, input().split())) # スペース区切り連続数字 # ------ 処理 ------# f = 0 n = nk[0] while f == 0: nList = [int(c) for c in str(n)] # 数字→単数字リスト変換 b = 1 for i in nList: for j in dList: if i == j: b = 0 break if b == 1: break else: n += n # ------ 出力 ------# print("{}".format(n)) # if flg == 0: # print("YES") # else: # print("NO")
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s656527362
Runtime Error
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
import copy def make1d(n, m): return [copy.deepcopy(m) for i in range(0, n)] s = list(map(int, input().split())) t = list(map(int, input().split())) # 支払う金額s[0]を桁ごとに分解する # 支払う金額の桁数:n n = 0 while (s[0] // (10**n)) >= 10: n = n + 1 l = make1d(n + 1, 1) m = s[0] for i in range(0, n + 1): l[n - i] = m % 10 m = m // 10 # 使えない数字->tを使える数字->numに変換 num = make1d(10, 1) for i in range(0, len(t)): num[t[i]] = 0 # 支払う金額からスタートしてダメな数字を含む場合は1増やしていく # 払うべき金額->l,使える数字->num(使える->1,使えない->0),支払う金額(答え)->a a = l limit = 10 ** len(a) - 1 a_int = int("".join(map(str, a))) # 桁数が一致しているときは tmp = 1 for i in range(0, n + 1): tmp = tmp * num[a[i]] if tmp == 1: ans = a_int while tmp == 0: if a_int <= limit - 1: a_int = a_int + 1 a_tmp = a_int for i in range(0, n + 1): a[n - i] = a_tmp % 10 a_tmp = a_tmp // 10 tmp = 1 for i in range(0, n + 1): tmp = tmp * num[a[i]] ans = a_int else: # 桁が一つ増える場合 count = 0 count_n = 1 # 0以外の最小の数 while count == 0: count = count + num[count_n] if num[0] == 1: a = make1d[n + 2, 0] a[0] = count_n else: a = make1d[n + 2, count_n] ans = int("".join(map(str, a))) print(ans)
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s231547753
Runtime Error
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
N, K = [int(i) for i in input().split()] ds = [int(i) for i in input().split()] # N, K = (99999, 8) # ds = [0,1,2,3,4,5,6,7,9] 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: num += 10 ** (n - i) return search_nearest_larger(num) else: n_digits[i] = d_out return to_num(n_digits[: i + 1] + [avail_min] * (n - i - 1)) return to_num(n_digits) return search_nearest_larger(N) res = run_code(N, K, ds) print(res)
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s194052996
Wrong Answer
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
N, K = map(int, input().split()) D = list(map(int, input().split())) A = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for i in range(0, K): A.remove(D[i]) A = sorted(A) ans = 999999 # 小さい順に数字を作る for q in range(0, 10 - K): # 100000担当 for w in range(0, 10 - K): # 10000担当 for e in range(0, 10 - K): # 1000担当 for r in range(0, 10 - K): # 100担当 for t in range(0, 10 - K): # 10担当 for y in range(0, 10 - K): # 1担当 if ( ans >= 100000 * A[q] + 10000 * A[w] + 1000 * A[e] + 100 * A[r] + 10 * A[t] + A[y] >= N ): ans = ( 100000 * A[q] + 10000 * A[w] + 1000 * A[e] + 100 * A[r] + 10 * A[t] + A[y] ) else: pass print(ans)
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s053126409
Accepted
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
class A: def solve(self): [a, b, c] = sorted([int(x) for x in input().split(" ")]) if a == 5 and b == 5 and c == 7: print("YES") else: print("NO") class B: def solve(self): [n, l] = [int(x) for x in input().split(" ")] strings = [] for r in range(n): strings.append(input()) sorted_strings = sorted(strings) print("".join(sorted_strings)) class C: def fix(self, final_amount, likes): i = 0 import bisect as b changed = False for i, x in enumerate(reversed(final_amount)): real_index = len(final_amount) - i - 1 ind = b.bisect_right(likes, int(x)) if ind != len(likes): final_amount[real_index] = str(likes[ind]) changed = True break if not changed: ind = b.bisect_right(likes, 0) final_amount = [str(likes[ind])] + final_amount i = 1 else: i = len(final_amount) - i - 1 while i < len(final_amount): final_amount[i] = str(likes[0]) i += 1 return final_amount def solve(self): [n, k] = [int(x) for x in input().split(" ")] dislikes = [int(x) for x in input().split(" ")] likes = [] for r in range(10): if r not in dislikes: likes.append(r) import bisect as b final_amount = [] sn = str(n) for ind in range(len(sn)): c = sn[ind] i = b.bisect_left(likes, int(c)) if i == len(likes): prev_len = len(final_amount) final_amount = self.fix(final_amount, likes) final_amount += [str(likes[0]) for r in range(len(sn) - prev_len)] break if str(c) != str(likes[i]): final_amount.append(str(likes[i])) final_amount += [ str(likes[0]) for r in range(len(sn) - len(final_amount)) ] break final_amount.append(str(likes[i])) print("".join(final_amount)) C().solve()
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s344873323
Wrong Answer
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
import sys N, K = map(int, sys.stdin.readline().split()) D = list(map(int, sys.stdin.readline().split())) number_set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} iroha_set = set(D) usage_set = number_set - iroha_set usage_list = list(usage_set) str_N = str(N) ans_list = [] str_list = [] for i in range(len(str_N)): str_list.append(str(max(usage_set))) escape_flag = 0 ans_num = 0 for i in reversed(range(len(str_N))): for j in reversed(list(usage_set)): str_list[i] = str(j) temp_str2 = "" for k in range(len(str_N)): temp_str2 += str_list[k] temp_num2 = int(temp_str2) if temp_num2 < N: escape_flag = 1 break ans_num = temp_num2 if escape_flag == 1: break if ans_num < N: ans_str = [] if usage_list[0] == 0: ans_str.append(usage_list[1]) else: ans_str.append(0) for i in range(len(str_N)): ans_str.append(str(min(usage_set))) ffff = "" for i in ans_str: ffff += str(i) ans_num = int(ffff) print(ans_num)
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s518668263
Wrong Answer
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
import itertools as it price, hate = input().split() price = int(price) hate = int(hate) numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] number_of_hate = [x for x in input().split()] number_of_like = [] # print(number_of_hate) flag1 = False flag2 = False flag3 = False f4 = False for c in range(0, 10): if str(c) not in number_of_hate: number_of_like.append(str(c)) # number_of_like.sort() if price >= 1000: ans = ["0", "0", "0", "0"] value_of_thou = int(str(price // 1000)) value_of_hun = int(str((price // 100) % 10)) value_of_ten = int(str((price // 10) % 10)) value_of_one = int(str(price % 10)) for c in range(len(number_of_like)): if value_of_thou <= int(number_of_like[c]) and flag1 is False: ans[0] = number_of_like[c] flag1 = True if value_of_hun <= int(number_of_like[c]) and flag2 is False: ans[1] = number_of_like[c] flag2 = True if value_of_ten <= int(number_of_like[c]) and flag3 is False: ans[2] = number_of_like[c] flag3 = True if value_of_one <= int(number_of_like[c]) and f4 is False: ans[3] = number_of_like[c] f4 = True if flag1 is True and flag2 is True and flag3 is True and f4 is True: break for i in ans: print(i, end="") elif price >= 100: ans = ["0", "0", "0"] value_of_hun = int(str(price // 100)) value_of_ten = int(str((price % 100) // 10)) value_of_one = int(str(price % 10)) for c in range(len(number_of_like)): if value_of_hun <= int(number_of_like[c]) and flag1 is False: ans[0] = number_of_like[c] flag1 = True if value_of_ten <= int(number_of_like[c]) and flag2 is False: ans[1] = number_of_like[c] flag2 = True if value_of_one <= int(number_of_like[c]) and flag3 is False: ans[2] = number_of_like[c] flag3 = True if flag1 is True and flag2 is True and flag3 is True: break for i in ans: print(i, end="") elif price >= 10: ans = ["0", "0"] value_of_ten = int(str(price // 10)) value_of_one = int(str(price % 10)) for c in range(len(number_of_like)): if value_of_ten <= int(number_of_like[c]) and flag1 is False: ans[0] = number_of_like[c] flag1 = True if value_of_one <= int(number_of_like[c]) and flag2 is False: ans[1] = number_of_like[c] flag2 = True if flag1 is True and flag2 is True: break for i in ans: print(i, end="") else: value_of_one = int(str(price)) for c in range(len(number_of_like)): if value_of_one <= int(number_of_like[c]): print(number_of_like[c], end="") break print()
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s345758312
Runtime Error
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
def digit(): N, K = [int(n) for n in input().split()] digit = [int(n) for n in input().split()] for i in range(N, N*10): b = i while b != 0: if (b % 10) in digit: break b /= 10 if b == 0: print(i) break: digit()
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s988180258
Wrong Answer
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
N, K = map(int, input().split()) D = list(map(int, input().split())) D_ALL = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # 使える値 like = sorted(list(set(D_ALL) - set(D))) small = like[0] is_inc = False out = "" for i, s in enumerate(str(N)): num = int(s) for i2, like_num in enumerate(like): if is_inc: out += str(small) break if like_num >= num: out += str(like_num) if like_num > num: is_inc = True break if i2 == len(like) - 1 and i == 0: out = str(like[1]) if small == 0 else str(small) out += str(small) is_inc = True print(out)
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s632970991
Wrong Answer
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
N, K = [int(i) for i in input().split()] dl = [int(i) for i in input().split()] D = [1 if i not in dl else 0 for i in range(10)] D = D + D[:1] n = str(N)[::-1] ans = [] add = 0 for a in range(len(n)): try: num = D.index(1, int(n[a]) + add) ans.append(num % 10) if num == 10: add = 1 else: add = 0 except: add = 1 ans.append(D.index(1)) if add == 1: ans.append(D.index(1, add)) # print(D) print("".join(map(str, ans[::-1])))
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s925357999
Wrong Answer
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
def cin(): return map(int, input().split()) def cina(): return list(map(int, input().split())) a, b = cin() a = list(str(a)) c = cina() d = {1, 2, 3, 4, 5, 6, 7, 8, 9} e = d.difference(c) s = "" for i in a: replace = False rep = -1 for j in range(len(c)): if int(i) == c[j]: replace = True break if replace: for k in e: if k > int(i): rep = k break else: rep = i s += str(rep) print(s)
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s180603882
Wrong Answer
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
N, K, *D = open(0).read().split() (*N,) = map(int, N) (*D,) = map(int, D) N += [0] for i in range(len(N) - 1): while N[i] in D: N[i] += 1 if N[i] > 9: N[i] %= 10 N[i + 1] += 1 if N[i] > 0: while N[i] in D: N[i] += 1 i += 1 print("".join([str(j) for j in N[:i][::-1]]))
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s303559524
Runtime Error
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
n,k=map(int, input().split()) ds=list(map(str, input().split())) while i in str(n) for i in ds: n+=1 print(str(n))
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s771453819
Runtime Error
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
import numpy as np n = list(map(int, input().split())) d = np.array(list(map(int, input().split()))) a = len(str(n[0])) x = np.zeros(a + 1) for i in range(a + 1): x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i) i = 0 while i += a: i += 1 if np.any(d == x[0]) and x[0] != 0: i = 0 while np.any(d == x[i]): x[i] += 1 x[i + (i != a):] = 0 if x[i] == 10: x[i - 1] += 1 x[i:] = 0 ans = 0 for i in range(a + 1): ans += x[i] * np.power(10, a - i) print(int(ans))
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s817785256
Runtime Error
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
l=list(map(int,input().split())) d=list(map(int,input().split())) d_bar=[] for m in range(10): if m not in d: d_bar.append(m) d_bar.sort() n=[int(k) for k in str(l[0]) for i in range(len(n)) dig1=0 dig2=0 for j in range(l[1]): p=dig1+d_bar[j]*10**(range(l[0])-i) if p>l[0]: break dig1=p dig2=dig2+d_bar[j]*l[1]**(range(l[0])-i) dig2=dig2+1 r=dig R=[] while q!=0 or q!=1: q=q/l[1] r=q%l[1] R.append(r) s=int(sum[str(-t-1) for t in R]) print(s)
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s044894074
Runtime Error
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
n,k=map(int,input().split()) a=list(map(int,input().split())) m=[] for i in range(10): if i not in a: m.append(i) k=0 for a in m: for b in m: for c in m: for d in m: for e in m: num=a*10000+b*1000+c*100+d*10+e if k==0 and num>=n: print(num) k=1
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]
Print the amount of money that Iroha will hand to the cashier. * * *
s200630963
Runtime Error
p04045
The input is given from Standard Input in the following format: N K D_1 D_2 … D_K
n, k = input().split() dic = [int(_) for _ in input().split()] not_in = [i for i in range(10) if i not in dic] ans = [min(list(filter(lambda x: int(i) <= x, not_in))) for i in n] print("".join(map(str, ans)))
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.
[{"input": "1000 8\n 1 3 4 5 6 7 8 9", "output": "2000\n \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n 0", "output": "9999"}]