# 順に全部聞く # 答えにならないやつは聞かない Subs = [] for i in range(100000): is_ok = True x = i l = [] for j in range(5): l.append(x % 10) x //= 10 if(len(set(l)) == 5): Subs.append(l) # print(len(Subs)) # print(Subs) Asks = [] Results = [] ac_cnt = 0 Hiddens = [] Used = [] def hit_and_blow(ql, al): h = 0 b = 0 # TODO:高速化 for i in range(5): for j in range(5): if(ql[i] == al[j]): if(i == j): h += 1 else: b += 1 return (h, b) def is_possible(l): # 今のResultsやHiddensと矛盾しないか # 最悪30240^2かかるが大丈夫だろ 多分 for i in range(len(Results)): is_found = False for j in range(30): if(not Used[i][j] and Results[i][j] == hit_and_blow(Asks[i], l)): is_found = True break if(not is_found): return False return True for l in Subs: if(not is_possible(l)): continue print("".join([str(x) for x in l])) Asks.append(l) Result = [tuple(map(int, input().split())) for _ in range(30)] now_ac_cnt = 0 Results.append(Result) Used.append([False] * 30) for i in range(30): if(Result[i][0] == 5): now_ac_cnt += 1 if(ac_cnt < now_ac_cnt): Hiddens.append(l) for i in range(len(Results)): is_found = False for j in range(30): if(not Used[i][j] and Results[i][j] == hit_and_blow(Asks[i], l)): Used[i][j] = True is_found = True break assert(is_found) ac_cnt = now_ac_cnt if(now_ac_cnt == 30): break