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 "Yes" if given dices are all different, otherwise "No" in a line.
s429316798
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
import random class dice: def __init__(self, t, S, E): self.dice = list(map(int, input().split())) self.t = t self.S = S self.E = E self.now_dice() def roll(self, order): if order == "E": self.t, self.E = self.W, self.t elif order == "N": self.t, self.S = self.S, self.g elif order == "S": self.t, self.S = self.N, self.t elif order == "W": self.t, self.E = self.E, self.g self.now_dice() def now_dice(self): self.N = 7 - self.S self.g = 7 - self.t self.W = 7 - self.E self.now = [self.t, self.S, self.E, self.N, self.W, self.g] return self.now if __name__ == "__main__": num = int(input()) dice_1 = dice(1, 2, 3) direc = ["N", "E", "W", "S"] x = 0 for _ in range(num - 1): dice_2 = dice(1, 2, 3) for __ in range(1200): random.shuffle(direc) dice_2.roll(direc[0]) if [dice_1.dice[dice_1.now[v] - 1] for v in range(6)] == [ dice_2.dice[dice_2.now[v] - 1] for v in range(6) ]: x += 1 break if x >= 1: print("No") else: print("Yes")
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s730200572
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
import sys import itertools class Dice(object): def __init__(self, faces: list): self.list_sn = [faces[5], faces[4], faces[0], faces[1]] # 6,5,1,2 self.list_we = [faces[5], faces[2], faces[0], faces[3]] # 6,5,1,2 def _roll_positive(self, list_a: list, list_b: list) -> list: list_a = list_a[1:] + list_a[0:1] # Roll one unit in the positive direction. list_b[0] = list_a[0] # Change the bottom face. list_b[2] = list_a[2] # Change the top face. return [list_a, list_b] def _roll_negative(self, list_a: list, list_b: list) -> list: list_a = list_a[3:] + list_a[0:3] list_b[0] = list_a[0] # Change the bottom face. list_b[2] = list_a[2] # Change the top face. return [list_a, list_b] def roll(self, direction: str): if "N" == direction: self.list_sn, self.list_we = self._roll_positive(self.list_sn, self.list_we) elif "S" == direction: self.list_sn, self.list_we = self._roll_negative(self.list_sn, self.list_we) elif "E" == direction: self.list_we, self.list_sn = self._roll_positive(self.list_we, self.list_sn) else: self.list_we, self.list_sn = self._roll_negative(self.list_we, self.list_sn) if __name__ == "__main__": dice_num = int(input()) dice_list = [ Dice(list(map(lambda x: int(x), input().split()))) for _ in range(dice_num) ] for Dice_a, Dice_b in itertools.combinations(dice_list, 2): for command in "NNNNWNNNWNNNENNNENNNWNNN": # Check all patterns. Dice_b.roll(command) if Dice_a.list_sn == Dice_b.list_sn and Dice_a.list_we == Dice_b.list_we: print("No") # Some pair is identical. sys.exit() print("Yes") # All dices are different.
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s129483169
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
number = int(input()) dices = [] for i in range(number): dices.append(input().split()) tf = 0 for i in range(number - 1): for j in range(i + 1, number): dice_1 = dices[i] dice_2 = dices[j] rolls = { " ": [0, 1, 2, 3, 4, 5], "W": [2, 1, 5, 0, 4, 3], "N": [1, 5, 2, 3, 0, 4], "E": [3, 1, 0, 5, 4, 2], "S": [4, 0, 2, 3, 5, 1], } orders = [" ", "N", "W", "E", "S", "NN"] for order in orders: copy_2 = dice_2 for d in order: roll = rolls[d] copy_2 = [copy_2[i] for i in roll] l = [1, 2, 4, 3] a0 = copy_2[0] == dice_1[0] a1 = copy_2[5] == dice_1[5] a2 = " ".join([copy_2[s] for s in l]) in " ".join( [dice_1[s] for s in l] * 2 ) if a0 and a1 and a2: tf += 1 if tf > 0: print("No") else: print("Yes")
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s688000961
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
class Dice: """Dice class""" def __init__(self): # ????????????????????? self.eyeIndex = 1 # center self.eyeIndex_E = 3 # east self.eyeIndex_W = 4 # west self.eyeIndex_N = 5 # north self.eyeIndex_S = 2 # south self.eye = 0 self.eye_S = 0 self.eye_E = 0 self.eye_W = 0 self.eye_N = 0 self.eye_B = 0 self.eyes = [] def convEyesIndexToEyes(self): self.eye = self.eyes[self.eyeIndex] self.eye_S = self.eyes[self.eyeIndex_S] self.eye_E = self.eyes[self.eyeIndex_E] self.eye_N = self.eyes[self.eyeIndex_N] self.eye_W = self.eyes[self.eyeIndex_W] self.eye_B = self.eyes[7 - self.eyeIndex] def shakeDice(self, in_command): pre_eyeIndex = self.eyeIndex if in_command == "E": self.eyeIndex = self.eyeIndex_W self.eyeIndex_E = pre_eyeIndex self.eyeIndex_W = 7 - self.eyeIndex_E elif in_command == "W": self.eyeIndex = self.eyeIndex_E self.eyeIndex_W = pre_eyeIndex self.eyeIndex_E = 7 - self.eyeIndex_W elif in_command == "N": self.eyeIndex = self.eyeIndex_S self.eyeIndex_N = pre_eyeIndex self.eyeIndex_S = 7 - self.eyeIndex_N elif in_command == "S": self.eyeIndex = self.eyeIndex_N self.eyeIndex_S = pre_eyeIndex self.eyeIndex_N = 7 - self.eyeIndex_S self.convEyesIndexToEyes() def rotateDice(self): # rotate clockwise pre_E = self.eyeIndex_E pre_S = self.eyeIndex_S pre_W = self.eyeIndex_W pre_N = self.eyeIndex_N self.eyeIndex_E = pre_N self.eyeIndex_S = pre_E self.eyeIndex_W = pre_S self.eyeIndex_N = pre_W self.convEyesIndexToEyes() def getEye(self): return self.eye def getEye_S(self): return self.eye_S def getEye_E(self): return self.eye_E def getEye_N(self): return self.eye_N def getEye_W(self): return self.eye_W def getEye_B(self): return self.eye_B def setEyes(self, eyes): # setEyes()???????????? ??????????????? eyes = "0 " + eyes self.eyes = list(map(int, eyes.split(" "))) self.convEyesIndexToEyes() def checkSameDice(dice_1, dice_2): shake_direction = "E" shake_cnt = 0 while True: if ( dice_2.getEye() == dice_1.getEye() and dice_2.getEye_B() == dice_1.getEye_B() ): break dice_2.shakeDice(shake_direction) shake_cnt = shake_cnt + 1 if shake_cnt >= 8: return False break if shake_cnt >= 4: shake_direction = "N" rotate_cnt = 0 while True: if ( dice_1.getEye() == dice_2.getEye() and dice_1.getEye_E() == dice_2.getEye_E() and dice_1.getEye_S() == dice_2.getEye_S() and dice_1.getEye_W() == dice_2.getEye_W() and dice_1.getEye_N() == dice_2.getEye_N() ): break dice_2.rotateDice() rotate_cnt = rotate_cnt + 1 if rotate_cnt >= 5: return False return True dice_cnt = int(input().rstrip()) # dice_eyes = [" " for i in range(dice_cnt)] dices = [] # set all dices for i in range(dice_cnt): # dice_eyes[i] = input().rtstrip() tmpDice = Dice() tmpDice.setEyes(input().rstrip()) dices.append(tmpDice) tmpDice = None judge = "Yes" for i in range(dice_cnt): for j in range(i + 1, dice_cnt): if checkSameDice(dices[i], dices[j]): judge = "No" break if judge == "No": break print(judge)
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s627390440
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
from itertools import combinations class Dice: def __init__(self, dim=list(range(1, 7))): self.dim = dim def roll(self, direction): if direction == "N": buff = self.dim[0] self.dim[0] = self.dim[1] self.dim[1] = self.dim[5] self.dim[5] = self.dim[4] self.dim[4] = buff if direction == "E": buff = self.dim[3] self.dim[3] = self.dim[5] self.dim[5] = self.dim[2] self.dim[2] = self.dim[0] self.dim[0] = buff if direction == "W": buff = self.dim[0] self.dim[0] = self.dim[2] self.dim[2] = self.dim[5] self.dim[5] = self.dim[3] self.dim[3] = buff if direction == "S": buff = self.dim[0] self.dim[0] = self.dim[4] self.dim[4] = self.dim[5] self.dim[5] = self.dim[1] self.dim[1] = buff def dice_ident(lsts, comb): for i in comb: D1 = Dice(lsts[i[0]]) D2 = Dice(lsts[i[1]]) for op in "EEENEEENEEESEEESEEENEEEN": if D1.dim == D2.dim: return print("No") D1.roll(op) return print("Yes") number = int(input()) comb = list(combinations(range(number), 2)) lsts = [] for i in range(number): lsts.append(list(map(int, input().split()))) dice_ident(lsts, comb)
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s542867527
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
class Dice: same_dice_index = ( (0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5), (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4), (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3), (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3), (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2), (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1), (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0), (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0), ) def __init__(self, str_list): self.faces = str_list def is_same(self, dice): for i in Dice.same_dice_index: for n, j in enumerate(i): if dice.faces[n] != self.faces[j]: break else: return True return False def is_unique(self, dices_list): for i in dices_list: if self.is_same(i): return False return True import sys n = int(sys.stdin.readline()) dices = [] for i in range(n): str_list = sys.stdin.readline().split() new_dice = Dice(str_list) if not new_dice.is_unique(dices): print("No") break dices.append(new_dice) else: print("Yes")
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s871744406
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
import itertools def get_dice(): input_data = input().split(" ") items = [int(cont) for cont in input_data] keys = ["T", "S", "E", "W", "N", "B"] return dict(zip(keys, items)) def rot_dice(rot, dice): if rot == "N": keys = ["T", "S", "B", "N"] items = dice["S"], dice["B"], dice["N"], dice["T"] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "S": keys = ["T", "S", "B", "N"] items = dice["N"], dice["T"], dice["S"], dice["B"] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "E": keys = ["T", "E", "B", "W"] items = dice["W"], dice["T"], dice["E"], dice["B"] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "W": keys = ["T", "E", "B", "W"] items = dice["E"], dice["B"], dice["W"], dice["T"] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "R": keys = ["N", "W", "S", "E"] items = dice["E"], dice["N"], dice["W"], dice["S"] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "L": keys = ["N", "W", "S", "E"] items = dice["W"], dice["S"], dice["E"], dice["N"] new_dice = dict(zip(keys, items)) dice.update(new_dice) def search_right_surf(conds, dice): a, b = conds a_key = [k for k, v in dice.items() if v == a] b_key = [k for k, v in dice.items() if v == b] key_list = a_key + b_key part_st = "".join(key_list) def search(part_st): if part_st in "TNBST": return "W" if part_st in "TSBNT": return "E" if part_st in "TEBWT": return "N" if part_st in "TWBET": return "S" if part_st in "NESWN": return "B" if part_st in "NWSEN": return "T" target_key = search(part_st) print(dice[target_key]) def search_top_surf(top_surf, dice): dice2_surf, *_ = [k for k, v in dice.items() if v == top_surf] if dice2_surf == "N": rot_dice("S", dice) if dice2_surf == "B": controls = list("SS") for i in controls: rot_dice(i, dice) if dice2_surf == "S": controls = list("N") for i in controls: rot_dice(i, dice) if dice2_surf == "W": controls = list("E") for i in controls: rot_dice(i, dice) if dice2_surf == "E": controls = list("W") for i in controls: rot_dice(i, dice) def search_flont_surf(flont_surf, dice): dice2_surf, *_ = [k for k, v in dice.items() if v == flont_surf] if dice2_surf == "E": controls = list("R") for i in controls: rot_dice(i, dice) if dice2_surf == "S": controls = list("RR") for i in controls: rot_dice(i, dice) if dice2_surf == "W": rot_dice("L", dice) def perfect_rot_compare(dice1, dice2): def compare_dice(dice1, dice2): if dice1 == dice2: return True comb = ["N", "S", "E", "W", "R", "L"] tups = list() for i in range(6): tups.append(itertools.combinations(comb, i)) if compare_dice(dice1, dice2): return True for commands in itertools.chain.from_iterable(tups): for command in commands: rot_dice(command, dice2) if compare_dice(dice1, dice2): return True return False def compare_many_dices(dice_list): dice1 = dice_list.pop(0) for dice2 in dice_list: if perfect_rot_compare(dice1, dice2): return True return False def q1(): dice = get_dice() controls = list(input()) for i in controls: rot_dice(i, dice) print(dice["T"]) def q2(): dice = get_dice() a = input() repeater = int(a) for neee in range(repeater): control_input = input().split(" ") conds = [int(i) for i in control_input] search_right_surf(conds, dice) def q3(): dice1 = get_dice() dice2 = get_dice() if perfect_rot_compare(dice1, dice2): print("Yes") else: print("No") def q4(): inp = input() dice_num = int(inp) dice_list = list() for i in range(dice_num): dice_list.append(get_dice()) if compare_many_dices(dice_list): print("No") else: print("Yes") q4()
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s520942693
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
# サイコロ 初期状態 # [1] N # [4][2][3][5] W[1]E # [6] S # # 上記の順番でラベルに対する整数が与えられる # l1 l2 l3 l4 l5 l6 # 複数のサイコロが全て異なっていれば'Yes' # 1組でも一致していたら'No' import copy class Dice: def __init__(self, l1, l2, l3, l4, l5, l6): self.l1 = l1 self.l2 = l2 self.l3 = l3 self.l4 = l4 self.l5 = l5 self.l6 = l6 self.tmp = 0 def move_n(self): self.tmp = self.l5 self.l5 = self.l1 self.l1 = self.l2 self.l2 = self.l6 self.l6 = self.tmp def move_s(self): self.tmp = self.l2 self.l2 = self.l1 self.l1 = self.l5 self.l5 = self.l6 self.l6 = self.tmp def move_e(self): self.tmp = self.l3 self.l3 = self.l1 self.l1 = self.l4 self.l4 = self.l6 self.l6 = self.tmp def move_w(self): self.tmp = self.l4 self.l4 = self.l1 self.l1 = self.l3 self.l3 = self.l6 self.l6 = self.tmp def show(self): return self.l1, self.l2, self.l3, self.l4, self.l5, self.l6 n = int(input()) yn_f = False d_inf1 = [] d_inf2 = [] for _ in range(n): d_inf1.append(Dice(*map(int, input().split()))) d_inf2 = copy.deepcopy(d_inf1) for i, d1 in enumerate(d_inf1): for j, d2 in enumerate(d_inf2): if i == j: continue if set(d1.show()) == set(d2.show()): ne_switch = 0 while d1.l2 != d2.l2: if ne_switch <= 3: d1.move_n() ne_switch += 1 elif 4 == ne_switch: d1.move_e() ne_switch = 0 e_cnt = 0 while d1.l1 != d2.l1 and e_cnt <= 3: d1.move_e() e_cnt += 1 if d1.l3 == d2.l3 and d1.l4 == d2.l4 and d1.l5 == d2.l5 and d1.l6 == d2.l6: yn_f = True if yn_f: break if yn_f: break print("No" if yn_f else "Yes")
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
If he can achieve the objective, print `OK`; if he cannot, print `NG`. * * *
s049860714
Runtime Error
p02693
Input is given from Standard Input in the following format: K A B
from sys import stdin import itertools import numpy as np from numba import njit def main(): # 入力 readline = stdin.readline N, M, Q = map(int, readline().split()) a = np.zeros(Q, dtype=np.int64) b = np.zeros(Q, dtype=np.int64) c = np.zeros(Q, dtype=np.int64) d = np.zeros(Q, dtype=np.int64) for i in range(Q): a[i], b[i], c[i], d[i] = map(int, readline().split()) arrays = np.array( list(itertools.combinations_with_replacement(range(1, M + 1), N)), dtype=np.int64, ) l = len(arrays) print(f(l, Q, a, b, c, d, arrays)) @njit("i8(i8,i8,i8[:],i8[:],i8[:],i8[:],i8[:,:])", cache=True) def f(l, Q, a, b, c, d, arrays): max_res = 0 for i in range(l): res = 0 for j in range(Q): if arrays[i][b[j] - 1] - arrays[i][a[j] - 1] == c[j]: res += d[j] max_res = max(max_res, res) return max_res if __name__ == "__main__": main()
Statement Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print `OK`; if he cannot, print `NG`.
[{"input": "7\n 500 600", "output": "OK\n \n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\n* * *"}, {"input": "4\n 5 7", "output": "NG\n \n\nNo multiple of 4 lies between 5 and 7.\n\n* * *"}, {"input": "1\n 11 11", "output": "OK"}]
If he can achieve the objective, print `OK`; if he cannot, print `NG`. * * *
s818586989
Runtime Error
p02693
Input is given from Standard Input in the following format: K A B
import numpy as np # from numba import jit n, m, q = map(int, input().split()) a = list(range(q)) b = list(range(q)) c = list(range(q)) d = list(range(q)) for i in range(q): a[i], b[i], c[i], d[i] = map(int, input().split()) A = np.sort(np.random.randint(1, m + 1, n)) # @jit def calc_energy(A): energy = 0.0 for i in range(q): if (A[b[i] - 1] - A[a[i] - 1]) == c[i]: energy += d[i] return energy T = 20000 temperature = 200 for t in range(T): A_prev = np.copy(A) energy_prev = calc_energy(A_prev) idx = np.random.randint(0, n) A[idx] = np.random.randint(1, m + 1) energy = calc_energy(A) if np.random.rand() < (energy - energy_prev) / temperature: pass else: A = np.copy(A_prev) temperature *= 0.999 print(np.int(calc_energy(A)))
Statement Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print `OK`; if he cannot, print `NG`.
[{"input": "7\n 500 600", "output": "OK\n \n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\n* * *"}, {"input": "4\n 5 7", "output": "NG\n \n\nNo multiple of 4 lies between 5 and 7.\n\n* * *"}, {"input": "1\n 11 11", "output": "OK"}]
If he can achieve the objective, print `OK`; if he cannot, print `NG`. * * *
s621070931
Runtime Error
p02693
Input is given from Standard Input in the following format: K A B
from bisect import bisect_left from collections import deque import copy def lis(A: list): L = [A[0]] for a in A[1:]: if a > L[-1]: # Lの末尾よりaが大きければ増加部分列を延長できる L.append(a) else: # そうでなければ、「aより小さい最大要素の次」をaにする # 該当位置は、二分探索で特定できる L[bisect_left(L, a)] = a return len(L) n = int(input()) a = tuple(map(int, input().split())) G = [[] for _ in range(n + 1)] for i in range(n - 1): u, v = map(int, input().split()) G[u].append(v) G[v].append(u) letu = [[] for _ in range(n + 1)] letu[1].append(1) que = deque([1]) while que: q = que.popleft() for nq in G[q]: let = copy.deepcopy(letu[q]) if letu[nq] != []: # seen配列としても使う。seenないと閉路でWA continue let = let + [nq] letu[nq] = let que.append(nq) for j in range(1, n + 1): tmp = [a[aa - 1] for aa in letu[j]] print(lis(tmp))
Statement Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print `OK`; if he cannot, print `NG`.
[{"input": "7\n 500 600", "output": "OK\n \n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\n* * *"}, {"input": "4\n 5 7", "output": "NG\n \n\nNo multiple of 4 lies between 5 and 7.\n\n* * *"}, {"input": "1\n 11 11", "output": "OK"}]
If he can achieve the objective, print `OK`; if he cannot, print `NG`. * * *
s181387925
Runtime Error
p02693
Input is given from Standard Input in the following format: K A B
n, m, q = map(int, input().split()) List = [list(map(int, input().split())) for i in range(q)] p_max = 0 point = 0 A = [1] * n E = [m] * n while A != E: # 得点計算 for j in range(q): if A[List[j][1] - 1] - A[List[j][0] - 1] == List[j][2]: point += List[j][3] # 最大値の更新 if p_max < point: p_max = point point = 0 # Aの更新 for i in reversed(range(0, n)): if A[i] < m: A[i] = A[i] + 1 if i != n - 1: for k in range(i + 1, n): A[k] = A[i] break print(p_max)
Statement Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print `OK`; if he cannot, print `NG`.
[{"input": "7\n 500 600", "output": "OK\n \n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\n* * *"}, {"input": "4\n 5 7", "output": "NG\n \n\nNo multiple of 4 lies between 5 and 7.\n\n* * *"}, {"input": "1\n 11 11", "output": "OK"}]
If he can achieve the objective, print `OK`; if he cannot, print `NG`. * * *
s371677733
Runtime Error
p02693
Input is given from Standard Input in the following format: K A B
nmq = list(map(int, input().split())) N = nmq[0] M = nmq[1] Q = nmq[2] ablist = [list(map(int, input().split())) for i in range(Q)] sumlist = [] alist = [i for i in range(1, M + 1)] import itertools as ite case = list(ite.combinations_with_replacement(alist, N)) for nowcase in case: sumd = 0 for i in range(Q): a = ablist[i][0] b = ablist[i][1] c = ablist[i][2] d = ablist[i][3] aa = nowcase[a - 1] ab = nowcase[b - 1] if ab - aa == c: sumd += d sumlist.append(sumd) print(max(sumlist))
Statement Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print `OK`; if he cannot, print `NG`.
[{"input": "7\n 500 600", "output": "OK\n \n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\n* * *"}, {"input": "4\n 5 7", "output": "NG\n \n\nNo multiple of 4 lies between 5 and 7.\n\n* * *"}, {"input": "1\n 11 11", "output": "OK"}]
If he can achieve the objective, print `OK`; if he cannot, print `NG`. * * *
s553257270
Runtime Error
p02693
Input is given from Standard Input in the following format: K A B
N, M = list(map(int, input().split())) src = [i + 1 for i in range(M * 2 + 1)] if N % 2 == 0: for m in range(M // 2): a = src[m] b = src[M - m] print("{} {}".format(a, b)) for m in range(M // 2): a = src[M + 1 + m] b = src[-(m + 1)] print("{} {}".format(a, b)) else: for m in range(M // 2): a = src[m] b = src[M - 1 - m] print("{} {}".format(a, b)) for m in range(M - (M // 2)): a = src[M + m] b = src[-(m + 1)] print("{} {}".format(a, b))
Statement Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print `OK`; if he cannot, print `NG`.
[{"input": "7\n 500 600", "output": "OK\n \n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\n* * *"}, {"input": "4\n 5 7", "output": "NG\n \n\nNo multiple of 4 lies between 5 and 7.\n\n* * *"}, {"input": "1\n 11 11", "output": "OK"}]
If he can achieve the objective, print `OK`; if he cannot, print `NG`. * * *
s695241163
Wrong Answer
p02693
Input is given from Standard Input in the following format: K A B
ppp = "Hello WOoooooooo?" print(ppp)
Statement Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print `OK`; if he cannot, print `NG`.
[{"input": "7\n 500 600", "output": "OK\n \n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\n* * *"}, {"input": "4\n 5 7", "output": "NG\n \n\nNo multiple of 4 lies between 5 and 7.\n\n* * *"}, {"input": "1\n 11 11", "output": "OK"}]
If he can achieve the objective, print `OK`; if he cannot, print `NG`. * * *
s453879029
Runtime Error
p02693
Input is given from Standard Input in the following format: K A B
import itertools N, M, Q = map(int, input().split()) m = list() res = -100 for i in range(Q): n = list(map(int, input().split())) m.append(n) l = [x for x in range(1, M + 1)] p = itertools.combinations_with_replacement(l, N) for p in p: total = 0 for i in range(Q): num = 0 a = m[i][0] b = m[i][1] A = p[a - 1] B = p[b - 1] C = B - A if m[i][2] == C: num = num + m[i][3] total = total + num if res < total: res = total print(res)
Statement Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print `OK`; if he cannot, print `NG`.
[{"input": "7\n 500 600", "output": "OK\n \n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\n* * *"}, {"input": "4\n 5 7", "output": "NG\n \n\nNo multiple of 4 lies between 5 and 7.\n\n* * *"}, {"input": "1\n 11 11", "output": "OK"}]
If he can achieve the objective, print `OK`; if he cannot, print `NG`. * * *
s228902818
Accepted
p02693
Input is given from Standard Input in the following format: K A B
s_K = input() s_AB = input().split() str = "NG" K = int(s_K) A = int(s_AB[0]) B = int(s_AB[1]) for w in range(A, B + 1): if w % K == 0: str = "OK" print(str)
Statement Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print `OK`; if he cannot, print `NG`.
[{"input": "7\n 500 600", "output": "OK\n \n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\n* * *"}, {"input": "4\n 5 7", "output": "NG\n \n\nNo multiple of 4 lies between 5 and 7.\n\n* * *"}, {"input": "1\n 11 11", "output": "OK"}]
If he can achieve the objective, print `OK`; if he cannot, print `NG`. * * *
s444843650
Runtime Error
p02693
Input is given from Standard Input in the following format: K A B
A = list(map(int, input().split())) # 入力のときに N を使う必要はありません i_max = 0 i_count = 0 j_count = 0 for x in range(1, A[2] + 1): if i_max < ((A[0] * x) // A[1] - A[0] * (x // A[1])): i_max = (A[0] * x) // A[1] - A[0] * (x // A[1]) i_count = x if (x - i_count) == 1: j_count = j_count + 1 if j_count == 2: break print(i_count)
Statement Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print `OK`; if he cannot, print `NG`.
[{"input": "7\n 500 600", "output": "OK\n \n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\n* * *"}, {"input": "4\n 5 7", "output": "NG\n \n\nNo multiple of 4 lies between 5 and 7.\n\n* * *"}, {"input": "1\n 11 11", "output": "OK"}]
If he can achieve the objective, print `OK`; if he cannot, print `NG`. * * *
s612981950
Runtime Error
p02693
Input is given from Standard Input in the following format: K A B
a, b, n = map(int, input().split()) ans = int((a * n) / b) - a * int(n / b) n = n - 1 ans = max(ans, int((a * n) / b) - a * int(n / b)) n = n - 2 ans = max(ans, int((a * n) / b) - a * int(n / b)) n = n - 3 ans = max(ans, int((a * n) / b) - a * int(n / b)) n = min(n, 1) ans = max(ans, int((a * n) / b) - a * int(n / b)) n = min(n, 2) ans = max(ans, int((a * n) / b) - a * int(n / b)) n = min(n, 3) ans = max(ans, int((a * n) / b) - a * int(n / b)) print(ans)
Statement Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print `OK`; if he cannot, print `NG`.
[{"input": "7\n 500 600", "output": "OK\n \n\nAmong the multiples of 7, for example, 567 lies between 500 and 600.\n\n* * *"}, {"input": "4\n 5 7", "output": "NG\n \n\nNo multiple of 4 lies between 5 and 7.\n\n* * *"}, {"input": "1\n 11 11", "output": "OK"}]
Print 1 if G has cycle(s), 0 otherwise.
s431214808
Wrong Answer
p02369
A directed graph G is given in the following format: |V| |E| s0 t0 s1 t1 : s|E|-1 t|E|-1 |V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., |V|-1 respectively. si and ti represent source and target nodes of i-th edge (directed).
from collections import deque, defaultdict def topological_sort(V, E): ''' Kahn's Algorithm (O(|V| + |E|) time) Input: V = [0, 1, ..., N-1]: a list of vertices of the digraph E: the adjacency list of the digraph (dict) Output: If the input digraph is acyclic, then return a topological sorting of the digraph. Else, return None. ''' indeg = {v: 0 for v in V} for ends in E.values(): for v in ends: indeg[v] += 1 q = deque([v for v in V if indeg[v] == 0]) top_sorted = [] while q: v = q.popleft() top_sorted.append(v) for u in E[v]: indeg[u] -= 1 if indeg[u] == 0: q.append(u) if len(top_sorted) == len(V): # The input digraph is acyclic. return top_sorted else: # There is a directed cycle in the digraph. return None N, M = map(int, input().split()) V = range(N) E = defaultdict(list) for _ in range(M): s, t = map(int, input().split()) E[s].append(t) print(0 if topological_sort(V, E) is None else 1)
Cycle Detection for a Directed Graph Find a cycle in a directed graph G(V, E).
[{"input": "3 3\n 0 1\n 0 2\n 1 2", "output": "0"}, {"input": "3 3\n 0 1\n 1 2\n 2 0", "output": "1"}]
Print 1 if G has cycle(s), 0 otherwise.
s248772854
Accepted
p02369
A directed graph G is given in the following format: |V| |E| s0 t0 s1 t1 : s|E|-1 t|E|-1 |V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., |V|-1 respectively. si and ti represent source and target nodes of i-th edge (directed).
# Cycle Detection for a Directed Graph [vertex, edge] = list(map(int, input("").split())) array = [[0 for j in range(vertex)] for i in range(vertex)] for i in range(edge): data = list(map(int, input("").split())) array[data[0]][data[1]] = 1 visited = [0 for j in range(vertex)] result = 0 def dfs(node, goal): for t in range(vertex): visited[node] = 1 if array[node][t] != 0 and t == goal: global result result = 1 if array[node][t] != 0 and visited[t] == 0: dfs(t, goal) for i in range(vertex): visited = [0 for j in range(vertex)] dfs(i, i) if result == 1: print(1) break if result == 0: print(0)
Cycle Detection for a Directed Graph Find a cycle in a directed graph G(V, E).
[{"input": "3 3\n 0 1\n 0 2\n 1 2", "output": "0"}, {"input": "3 3\n 0 1\n 1 2\n 2 0", "output": "1"}]
Output what day of the week it is in a line. Use the following conventions in your output: "mon" for Monday, "tue" for Tuesday, "wed" for Wednesday, "thu" for Thursday, "fri" for Friday, "sat" for Saturday, and "sun" for Sunday.
s634082731
Accepted
p00354
The input is given in the following format. X The input line specifies a day X (1 ≤ X ≤ 30) in September 2017.
X = int(input()) X = (X - 9) % 7 if X < 0: X = X + 7 y = "" if X == 0: y = "sat" elif X == 1: y = "sun" elif X == 2: y = "mon" elif X == 3: y = "tue" elif X == 4: y = "wed" elif X == 5: y = "thu" elif X == 6: y = "fri" print(y)
Day of Week The 9th day of September 2017 is Saturday. Then, what day of the week is the X-th of September 2017? Given a day in September 2017, write a program to report what day of the week it is.
[{"input": "1", "output": "fri"}, {"input": "9", "output": "sat"}, {"input": "30", "output": "sat"}]
Output what day of the week it is in a line. Use the following conventions in your output: "mon" for Monday, "tue" for Tuesday, "wed" for Wednesday, "thu" for Thursday, "fri" for Friday, "sat" for Saturday, and "sun" for Sunday.
s933222953
Accepted
p00354
The input is given in the following format. X The input line specifies a day X (1 ≤ X ≤ 30) in September 2017.
W = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] * 10 n = int(input()) print(W[n + 3])
Day of Week The 9th day of September 2017 is Saturday. Then, what day of the week is the X-th of September 2017? Given a day in September 2017, write a program to report what day of the week it is.
[{"input": "1", "output": "fri"}, {"input": "9", "output": "sat"}, {"input": "30", "output": "sat"}]
Output what day of the week it is in a line. Use the following conventions in your output: "mon" for Monday, "tue" for Tuesday, "wed" for Wednesday, "thu" for Thursday, "fri" for Friday, "sat" for Saturday, and "sun" for Sunday.
s950807768
Accepted
p00354
The input is given in the following format. X The input line specifies a day X (1 ≤ X ≤ 30) in September 2017.
lis = ["thu", "fri", "sat", "sun", "mon", "tue", "wed"] print(lis[int(input()) % 7])
Day of Week The 9th day of September 2017 is Saturday. Then, what day of the week is the X-th of September 2017? Given a day in September 2017, write a program to report what day of the week it is.
[{"input": "1", "output": "fri"}, {"input": "9", "output": "sat"}, {"input": "30", "output": "sat"}]
Output what day of the week it is in a line. Use the following conventions in your output: "mon" for Monday, "tue" for Tuesday, "wed" for Wednesday, "thu" for Thursday, "fri" for Friday, "sat" for Saturday, and "sun" for Sunday.
s536748964
Accepted
p00354
The input is given in the following format. X The input line specifies a day X (1 ≤ X ≤ 30) in September 2017.
print(["thu", "fri", "sat", "sun", "mon", "tue", "wed"][int(input()) % 7])
Day of Week The 9th day of September 2017 is Saturday. Then, what day of the week is the X-th of September 2017? Given a day in September 2017, write a program to report what day of the week it is.
[{"input": "1", "output": "fri"}, {"input": "9", "output": "sat"}, {"input": "30", "output": "sat"}]
Output what day of the week it is in a line. Use the following conventions in your output: "mon" for Monday, "tue" for Tuesday, "wed" for Wednesday, "thu" for Thursday, "fri" for Friday, "sat" for Saturday, and "sun" for Sunday.
s520055397
Accepted
p00354
The input is given in the following format. X The input line specifies a day X (1 ≤ X ≤ 30) in September 2017.
X = int(input()) Day = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] a = X % 7 if a == 2 or a == 3: print(Day[a + 3]) elif a == 4 or a == 5 or a == 6: print(Day[a - 4]) elif a == 0 or a == 1: print(Day[a + 3])
Day of Week The 9th day of September 2017 is Saturday. Then, what day of the week is the X-th of September 2017? Given a day in September 2017, write a program to report what day of the week it is.
[{"input": "1", "output": "fri"}, {"input": "9", "output": "sat"}, {"input": "30", "output": "sat"}]
Output what day of the week it is in a line. Use the following conventions in your output: "mon" for Monday, "tue" for Tuesday, "wed" for Wednesday, "thu" for Thursday, "fri" for Friday, "sat" for Saturday, and "sun" for Sunday.
s436578130
Accepted
p00354
The input is given in the following format. X The input line specifies a day X (1 ≤ X ≤ 30) in September 2017.
day = ["sat", "sun", "mon", "tue", "wed", "thu", "fri"] dayf = ["thu", "fri", "sat", "sun", "mon", "tue", "wed"] x = int(input()) if x < 9: print(dayf[x % 7]) else: print(day[abs(x - 9) % 7])
Day of Week The 9th day of September 2017 is Saturday. Then, what day of the week is the X-th of September 2017? Given a day in September 2017, write a program to report what day of the week it is.
[{"input": "1", "output": "fri"}, {"input": "9", "output": "sat"}, {"input": "30", "output": "sat"}]
If there is no closed curve that satisfies the condition, print `Impossible`. If such a closed curve exists, print `Possible` in the first line. Then, print one such curve in the following format: L x_0 y_0 x_1 y_1 : x_L y_L This represents the closed polyline that passes (x_0,y_0),(x_1,y_1),\ldots,(x_L,y_L) in this order. Here, all of the following must be satisfied: * 0 \leq x_i \leq N, 0 \leq y_i \leq 1, and x_i, y_i are integers. (0 \leq i \leq L) * |x_i-x_{i+1}| + |y_i-y_{i+1}| = 1. (0 \leq i \leq L-1) * (x_0,y_0) = (x_L,y_L). Additionally, the length of the closed curve L must satisfy 0 \leq L \leq 250000. It can be proved that, if there is a closed curve that satisfies the condition in Problem Statement, there is also a closed curve that can be expressed in this format. * * *
s091108141
Wrong Answer
p02739
Input is given from Standard Input in the following format: N A_0A_1 \cdots A_{2^N-1}
n = int(input()) a = [1 - int(c) for c in input()] s = [a[1 << i] for i in range(n)] for x in range(2**n): t = any(s[i] for i in filter(lambda i: (x >> i) & 1, range(n))) if a[x] != t: possible = False break else: possible = True if possible: print("Possible") res = [(0, 0)] for i in range(n): if s[i]: res.append((i, 1)) res.append((i + 1, 1)) res.append((i + 1, 0)) for i in range(n - 1, -1, -1): res.append((i, 0)) print(len(res) - 1) for x, y in res: print(x, y) else: print("Impossible")
Statement Given are a positive integer N and a sequence of length 2^N consisting of 0s and 1s: A_0,A_1,\ldots,A_{2^N-1}. Determine whether there exists a closed curve C that satisfies the condition below for all 2^N sets S \subseteq \\{0,1,\ldots,N-1 \\}. If the answer is yes, construct one such closed curve. * Let x = \sum_{i \in S} 2^i and B_S be the set of points \\{ (i+0.5,0.5) | i \in S \\}. * If there is a way to continuously move the closed curve C without touching B_S so that every point on the closed curve has a negative y-coordinate, A_x = 1. * If there is no such way, A_x = 0. For instruction on printing a closed curve, see Output below.
[{"input": "1\n 10", "output": "Possible\n 4\n 0 0\n 0 1\n 1 1\n 1 0\n 0 0\n \n\nWhen S = \\emptyset, we can move this curve so that every point on it has a\nnegative y-coordinate.\n\n![](https://img.atcoder.jp/agc043/d44ca639698b4c14bb84b90da5442ca6.png)\n\nWhen S = \\\\{0\\\\}, we cannot do so.\n\n![](https://img.atcoder.jp/agc043/5a960a0c4167e8593b6c8f8af685253d.png)\n\n* * *"}, {"input": "2\n 1000", "output": "Possible\n 6\n 1 0\n 2 0\n 2 1\n 1 1\n 0 1\n 0 0\n 1 0\n \n\nThe output represents the following curve:\n\n![](https://img.atcoder.jp/agc043/283e490d520a451f1b15160900c9b545.png)\n\n* * *"}, {"input": "2\n 1001", "output": "Impossible\n \n\n* * *"}, {"input": "1\n 11", "output": "Possible\n 0\n 1 1"}]
If there is no closed curve that satisfies the condition, print `Impossible`. If such a closed curve exists, print `Possible` in the first line. Then, print one such curve in the following format: L x_0 y_0 x_1 y_1 : x_L y_L This represents the closed polyline that passes (x_0,y_0),(x_1,y_1),\ldots,(x_L,y_L) in this order. Here, all of the following must be satisfied: * 0 \leq x_i \leq N, 0 \leq y_i \leq 1, and x_i, y_i are integers. (0 \leq i \leq L) * |x_i-x_{i+1}| + |y_i-y_{i+1}| = 1. (0 \leq i \leq L-1) * (x_0,y_0) = (x_L,y_L). Additionally, the length of the closed curve L must satisfy 0 \leq L \leq 250000. It can be proved that, if there is a closed curve that satisfies the condition in Problem Statement, there is also a closed curve that can be expressed in this format. * * *
s537896254
Wrong Answer
p02739
Input is given from Standard Input in the following format: N A_0A_1 \cdots A_{2^N-1}
print("Possible") print(0) print(1, 1)
Statement Given are a positive integer N and a sequence of length 2^N consisting of 0s and 1s: A_0,A_1,\ldots,A_{2^N-1}. Determine whether there exists a closed curve C that satisfies the condition below for all 2^N sets S \subseteq \\{0,1,\ldots,N-1 \\}. If the answer is yes, construct one such closed curve. * Let x = \sum_{i \in S} 2^i and B_S be the set of points \\{ (i+0.5,0.5) | i \in S \\}. * If there is a way to continuously move the closed curve C without touching B_S so that every point on the closed curve has a negative y-coordinate, A_x = 1. * If there is no such way, A_x = 0. For instruction on printing a closed curve, see Output below.
[{"input": "1\n 10", "output": "Possible\n 4\n 0 0\n 0 1\n 1 1\n 1 0\n 0 0\n \n\nWhen S = \\emptyset, we can move this curve so that every point on it has a\nnegative y-coordinate.\n\n![](https://img.atcoder.jp/agc043/d44ca639698b4c14bb84b90da5442ca6.png)\n\nWhen S = \\\\{0\\\\}, we cannot do so.\n\n![](https://img.atcoder.jp/agc043/5a960a0c4167e8593b6c8f8af685253d.png)\n\n* * *"}, {"input": "2\n 1000", "output": "Possible\n 6\n 1 0\n 2 0\n 2 1\n 1 1\n 0 1\n 0 0\n 1 0\n \n\nThe output represents the following curve:\n\n![](https://img.atcoder.jp/agc043/283e490d520a451f1b15160900c9b545.png)\n\n* * *"}, {"input": "2\n 1001", "output": "Impossible\n \n\n* * *"}, {"input": "1\n 11", "output": "Possible\n 0\n 1 1"}]
If there is no closed curve that satisfies the condition, print `Impossible`. If such a closed curve exists, print `Possible` in the first line. Then, print one such curve in the following format: L x_0 y_0 x_1 y_1 : x_L y_L This represents the closed polyline that passes (x_0,y_0),(x_1,y_1),\ldots,(x_L,y_L) in this order. Here, all of the following must be satisfied: * 0 \leq x_i \leq N, 0 \leq y_i \leq 1, and x_i, y_i are integers. (0 \leq i \leq L) * |x_i-x_{i+1}| + |y_i-y_{i+1}| = 1. (0 \leq i \leq L-1) * (x_0,y_0) = (x_L,y_L). Additionally, the length of the closed curve L must satisfy 0 \leq L \leq 250000. It can be proved that, if there is a closed curve that satisfies the condition in Problem Statement, there is also a closed curve that can be expressed in this format. * * *
s450850471
Wrong Answer
p02739
Input is given from Standard Input in the following format: N A_0A_1 \cdots A_{2^N-1}
print("Impossible")
Statement Given are a positive integer N and a sequence of length 2^N consisting of 0s and 1s: A_0,A_1,\ldots,A_{2^N-1}. Determine whether there exists a closed curve C that satisfies the condition below for all 2^N sets S \subseteq \\{0,1,\ldots,N-1 \\}. If the answer is yes, construct one such closed curve. * Let x = \sum_{i \in S} 2^i and B_S be the set of points \\{ (i+0.5,0.5) | i \in S \\}. * If there is a way to continuously move the closed curve C without touching B_S so that every point on the closed curve has a negative y-coordinate, A_x = 1. * If there is no such way, A_x = 0. For instruction on printing a closed curve, see Output below.
[{"input": "1\n 10", "output": "Possible\n 4\n 0 0\n 0 1\n 1 1\n 1 0\n 0 0\n \n\nWhen S = \\emptyset, we can move this curve so that every point on it has a\nnegative y-coordinate.\n\n![](https://img.atcoder.jp/agc043/d44ca639698b4c14bb84b90da5442ca6.png)\n\nWhen S = \\\\{0\\\\}, we cannot do so.\n\n![](https://img.atcoder.jp/agc043/5a960a0c4167e8593b6c8f8af685253d.png)\n\n* * *"}, {"input": "2\n 1000", "output": "Possible\n 6\n 1 0\n 2 0\n 2 1\n 1 1\n 0 1\n 0 0\n 1 0\n \n\nThe output represents the following curve:\n\n![](https://img.atcoder.jp/agc043/283e490d520a451f1b15160900c9b545.png)\n\n* * *"}, {"input": "2\n 1001", "output": "Impossible\n \n\n* * *"}, {"input": "1\n 11", "output": "Possible\n 0\n 1 1"}]
If there is no closed curve that satisfies the condition, print `Impossible`. If such a closed curve exists, print `Possible` in the first line. Then, print one such curve in the following format: L x_0 y_0 x_1 y_1 : x_L y_L This represents the closed polyline that passes (x_0,y_0),(x_1,y_1),\ldots,(x_L,y_L) in this order. Here, all of the following must be satisfied: * 0 \leq x_i \leq N, 0 \leq y_i \leq 1, and x_i, y_i are integers. (0 \leq i \leq L) * |x_i-x_{i+1}| + |y_i-y_{i+1}| = 1. (0 \leq i \leq L-1) * (x_0,y_0) = (x_L,y_L). Additionally, the length of the closed curve L must satisfy 0 \leq L \leq 250000. It can be proved that, if there is a closed curve that satisfies the condition in Problem Statement, there is also a closed curve that can be expressed in this format. * * *
s844997202
Runtime Error
p02739
Input is given from Standard Input in the following format: N A_0A_1 \cdots A_{2^N-1}
import sys N = int(input()) on = 0 for i in range(1 << N): a = int(sys.stdin.read(1)) if bin(i).count("1") == 1 and not a: on |= i if not a ^ bool(i & on): print("Impossible") break else: raise ValueError
Statement Given are a positive integer N and a sequence of length 2^N consisting of 0s and 1s: A_0,A_1,\ldots,A_{2^N-1}. Determine whether there exists a closed curve C that satisfies the condition below for all 2^N sets S \subseteq \\{0,1,\ldots,N-1 \\}. If the answer is yes, construct one such closed curve. * Let x = \sum_{i \in S} 2^i and B_S be the set of points \\{ (i+0.5,0.5) | i \in S \\}. * If there is a way to continuously move the closed curve C without touching B_S so that every point on the closed curve has a negative y-coordinate, A_x = 1. * If there is no such way, A_x = 0. For instruction on printing a closed curve, see Output below.
[{"input": "1\n 10", "output": "Possible\n 4\n 0 0\n 0 1\n 1 1\n 1 0\n 0 0\n \n\nWhen S = \\emptyset, we can move this curve so that every point on it has a\nnegative y-coordinate.\n\n![](https://img.atcoder.jp/agc043/d44ca639698b4c14bb84b90da5442ca6.png)\n\nWhen S = \\\\{0\\\\}, we cannot do so.\n\n![](https://img.atcoder.jp/agc043/5a960a0c4167e8593b6c8f8af685253d.png)\n\n* * *"}, {"input": "2\n 1000", "output": "Possible\n 6\n 1 0\n 2 0\n 2 1\n 1 1\n 0 1\n 0 0\n 1 0\n \n\nThe output represents the following curve:\n\n![](https://img.atcoder.jp/agc043/283e490d520a451f1b15160900c9b545.png)\n\n* * *"}, {"input": "2\n 1001", "output": "Impossible\n \n\n* * *"}, {"input": "1\n 11", "output": "Possible\n 0\n 1 1"}]
Print the answer. * * *
s829005258
Accepted
p03082
Input is given from Standard Input in the following format: N X S_1 S_2 \ldots S_{N}
N, X, *S = map(int, open(0).read().split()) e = enumerate d = range(X + 1) for i, s in e(sorted(S)): d = [(t * i + d[j % s]) % (10**9 + 7) for j, t in e(d)] print(d[-1])
Statement Snuke has a blackboard and a set S consisting of N integers. The i-th element in S is S_i. He wrote an integer X on the blackboard, then performed the following operation N times: * Choose one element from S and remove it. * Let x be the number written on the blackboard now, and y be the integer removed from S. Replace the number on the blackboard with x \bmod {y}. There are N! possible orders in which the elements are removed from S. For each of them, find the number that would be written on the blackboard after the N operations, and compute the sum of all those N! numbers modulo 10^{9}+7.
[{"input": "2 19\n 3 7", "output": "3\n \n\n * There are two possible orders in which we remove the numbers from S.\n * If we remove 3 and 7 in this order, the number on the blackboard changes as follows: 19 \\rightarrow 1 \\rightarrow 1.\n * If we remove 7 and 3 in this order, the number on the blackboard changes as follows: 19 \\rightarrow 5 \\rightarrow 2.\n * The output should be the sum of these: 3.\n\n* * *"}, {"input": "5 82\n 22 11 6 5 13", "output": "288\n \n\n* * *"}, {"input": "10 100000\n 50000 50001 50002 50003 50004 50005 50006 50007 50008 50009", "output": "279669259\n \n\n * Be sure to compute the sum modulo 10^{9}+7."}]
Print the answer. * * *
s622806485
Runtime Error
p03082
Input is given from Standard Input in the following format: N X S_1 S_2 \ldots S_{N}
# 通るかな? def 解(): import numpy as np import sys input = sys.stdin.readline N, Q = [int(_) for _ in input().split()] S = input() dS = {} for i in range(1, N + 1): s = S[i - 1] if s in dS: dS[s].add(i) else: dS[s] = {i} # aM = [1]*(N+2) # aM = {i:1 for i in range(N+2)} aM = np.array([1] * (N + 2)) for _ in range(Q): t, d = input().split() if t in dS: if d == "R": for i in dS[t]: if aM[i]: aM[i + 1] += aM[i] aM[i] = 0 else: for i in dS[t]: if aM[i]: aM[i - 1] += aM[i] aM[i] = 0 # print(sum(aM[i] for i in range(1,N+1))) print(sum(aM[1 : N + 1])) 解()
Statement Snuke has a blackboard and a set S consisting of N integers. The i-th element in S is S_i. He wrote an integer X on the blackboard, then performed the following operation N times: * Choose one element from S and remove it. * Let x be the number written on the blackboard now, and y be the integer removed from S. Replace the number on the blackboard with x \bmod {y}. There are N! possible orders in which the elements are removed from S. For each of them, find the number that would be written on the blackboard after the N operations, and compute the sum of all those N! numbers modulo 10^{9}+7.
[{"input": "2 19\n 3 7", "output": "3\n \n\n * There are two possible orders in which we remove the numbers from S.\n * If we remove 3 and 7 in this order, the number on the blackboard changes as follows: 19 \\rightarrow 1 \\rightarrow 1.\n * If we remove 7 and 3 in this order, the number on the blackboard changes as follows: 19 \\rightarrow 5 \\rightarrow 2.\n * The output should be the sum of these: 3.\n\n* * *"}, {"input": "5 82\n 22 11 6 5 13", "output": "288\n \n\n* * *"}, {"input": "10 100000\n 50000 50001 50002 50003 50004 50005 50006 50007 50008 50009", "output": "279669259\n \n\n * Be sure to compute the sum modulo 10^{9}+7."}]
Print the answer. * * *
s065184247
Accepted
p03082
Input is given from Standard Input in the following format: N X S_1 S_2 \ldots S_{N}
n, x = map(int, input().split()) s, f, M = sorted(list(map(int, input().split())))[::-1], [1, 1], 10**9 + 7 for i in range(2, n): f += [f[-1] * i % M] D = {x: f[n - 1]} for i, k in enumerate(s): m, inv = dict(), pow(n - i - 1, M - 2, M) for j, a in D.items(): m[j % k] = m.get(j % k, 0) + a for j, a in m.items(): D[j] = (D.get(j, 0) + a * inv) % M print(sum([i * j for i, j in m.items()]) % M)
Statement Snuke has a blackboard and a set S consisting of N integers. The i-th element in S is S_i. He wrote an integer X on the blackboard, then performed the following operation N times: * Choose one element from S and remove it. * Let x be the number written on the blackboard now, and y be the integer removed from S. Replace the number on the blackboard with x \bmod {y}. There are N! possible orders in which the elements are removed from S. For each of them, find the number that would be written on the blackboard after the N operations, and compute the sum of all those N! numbers modulo 10^{9}+7.
[{"input": "2 19\n 3 7", "output": "3\n \n\n * There are two possible orders in which we remove the numbers from S.\n * If we remove 3 and 7 in this order, the number on the blackboard changes as follows: 19 \\rightarrow 1 \\rightarrow 1.\n * If we remove 7 and 3 in this order, the number on the blackboard changes as follows: 19 \\rightarrow 5 \\rightarrow 2.\n * The output should be the sum of these: 3.\n\n* * *"}, {"input": "5 82\n 22 11 6 5 13", "output": "288\n \n\n* * *"}, {"input": "10 100000\n 50000 50001 50002 50003 50004 50005 50006 50007 50008 50009", "output": "279669259\n \n\n * Be sure to compute the sum modulo 10^{9}+7."}]
Print `YES` if Rng can complete the problem set without creating new candidates of problems; print `NO` if he cannot. * * *
s695012474
Runtime Error
p03578
Input is given from Standard Input in the following format: N D_1 D_2 ... D_N M T_1 T_2 ... T_M
n = input() d = [int(i) for i in input().split(" ")] m = input() t = [int(i) for i in input().split(" ")] d_set = set(d) d_set = list(d_set) t_set = set(t) t_set = list(t_set) flag =0 if len(t_set != d_set): flag = 1 else: for s in t_set: if(d.count(s) < t.count(s)): flag = 1 break if flag == 1: print("NO") else: print("YES")
Statement Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
[{"input": "5\n 3 1 4 1 5\n 3\n 5 4 3", "output": "YES\n \n\n* * *"}, {"input": "7\n 100 200 500 700 1200 1600 2000\n 6\n 100 200 500 700 1600 1600", "output": "NO\n \n\nNot enough 1600s.\n\n* * *"}, {"input": "1\n 800\n 5\n 100 100 100 100 100", "output": "NO\n \n\n* * *"}, {"input": "15\n 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5\n 9\n 5 4 3 2 1 2 3 4 5", "output": "YES"}]
Print `YES` if Rng can complete the problem set without creating new candidates of problems; print `NO` if he cannot. * * *
s626669208
Runtime Error
p03578
Input is given from Standard Input in the following format: N D_1 D_2 ... D_N M T_1 T_2 ... T_M
n = int(input()) D = list(map(int, input().split())) m = int(input()) T = list(map(int, input().split())) D.sort() T.sort() if n=<m: if D==T: print('YES') exit() else: print('NO') exit() r = 'YES' for i in range(m): if T[i] in D: idx = D.index(T[i]) D = D[idx+1:] else: r = 'NO' break print(r)
Statement Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
[{"input": "5\n 3 1 4 1 5\n 3\n 5 4 3", "output": "YES\n \n\n* * *"}, {"input": "7\n 100 200 500 700 1200 1600 2000\n 6\n 100 200 500 700 1600 1600", "output": "NO\n \n\nNot enough 1600s.\n\n* * *"}, {"input": "1\n 800\n 5\n 100 100 100 100 100", "output": "NO\n \n\n* * *"}, {"input": "15\n 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5\n 9\n 5 4 3 2 1 2 3 4 5", "output": "YES"}]
Print `YES` if Rng can complete the problem set without creating new candidates of problems; print `NO` if he cannot. * * *
s038702562
Runtime Error
p03578
Input is given from Standard Input in the following format: N D_1 D_2 ... D_N M T_1 T_2 ... T_M
mport collections n = int(input()) ln = list(map(int, input().split())) m = int(input()) lm = list(map(int, input().split())) c1 = collections.Counter(lm) c2 = collections.Counter(ln) for i in c1.keys(): if c2[i] < c1[i]: print("NO") exit() print("YES")
Statement Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
[{"input": "5\n 3 1 4 1 5\n 3\n 5 4 3", "output": "YES\n \n\n* * *"}, {"input": "7\n 100 200 500 700 1200 1600 2000\n 6\n 100 200 500 700 1600 1600", "output": "NO\n \n\nNot enough 1600s.\n\n* * *"}, {"input": "1\n 800\n 5\n 100 100 100 100 100", "output": "NO\n \n\n* * *"}, {"input": "15\n 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5\n 9\n 5 4 3 2 1 2 3 4 5", "output": "YES"}]
Print `YES` if Rng can complete the problem set without creating new candidates of problems; print `NO` if he cannot. * * *
s267910915
Runtime Error
p03578
Input is given from Standard Input in the following format: N D_1 D_2 ... D_N M T_1 T_2 ... T_M
= list(map(int,input().split())) m = int(input()) T = list(map(int,input().split())) if m > n: print('NO') exit() numd = [0]*200005 numt = [0]*200005 for d in D: numd[d] += 1 for t in T: numt[t] += 1 for t in T: if numt[t] > numd[t]: print('NO') exit() print('YES')
Statement Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
[{"input": "5\n 3 1 4 1 5\n 3\n 5 4 3", "output": "YES\n \n\n* * *"}, {"input": "7\n 100 200 500 700 1200 1600 2000\n 6\n 100 200 500 700 1600 1600", "output": "NO\n \n\nNot enough 1600s.\n\n* * *"}, {"input": "1\n 800\n 5\n 100 100 100 100 100", "output": "NO\n \n\n* * *"}, {"input": "15\n 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5\n 9\n 5 4 3 2 1 2 3 4 5", "output": "YES"}]
Print `YES` if Rng can complete the problem set without creating new candidates of problems; print `NO` if he cannot. * * *
s479916971
Runtime Error
p03578
Input is given from Standard Input in the following format: N D_1 D_2 ... D_N M T_1 T_2 ... T_M
n = int(input()) d = list(map(int, input().split())) m = int(input()) t = list(map(int, input().split())) t_ = set(t) for i in range(len(t_): if t.count(t_[i]) > d.count(t_[i]): print("NO") exit() print("YES")
Statement Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
[{"input": "5\n 3 1 4 1 5\n 3\n 5 4 3", "output": "YES\n \n\n* * *"}, {"input": "7\n 100 200 500 700 1200 1600 2000\n 6\n 100 200 500 700 1600 1600", "output": "NO\n \n\nNot enough 1600s.\n\n* * *"}, {"input": "1\n 800\n 5\n 100 100 100 100 100", "output": "NO\n \n\n* * *"}, {"input": "15\n 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5\n 9\n 5 4 3 2 1 2 3 4 5", "output": "YES"}]
Print `YES` if Rng can complete the problem set without creating new candidates of problems; print `NO` if he cannot. * * *
s060911978
Runtime Error
p03578
Input is given from Standard Input in the following format: N D_1 D_2 ... D_N M T_1 T_2 ... T_M
n=int(input()) d=sorted(list(map(int,input().split()))) m=int(input()) t=sorted(list(map(int,input().split()))) j=0 for i in range(len(t)): if j==len(s): print("NO") break t[i]==s[j]: j+=1 else: print("YES")
Statement Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
[{"input": "5\n 3 1 4 1 5\n 3\n 5 4 3", "output": "YES\n \n\n* * *"}, {"input": "7\n 100 200 500 700 1200 1600 2000\n 6\n 100 200 500 700 1600 1600", "output": "NO\n \n\nNot enough 1600s.\n\n* * *"}, {"input": "1\n 800\n 5\n 100 100 100 100 100", "output": "NO\n \n\n* * *"}, {"input": "15\n 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5\n 9\n 5 4 3 2 1 2 3 4 5", "output": "YES"}]
Print `YES` if Rng can complete the problem set without creating new candidates of problems; print `NO` if he cannot. * * *
s514717227
Accepted
p03578
Input is given from Standard Input in the following format: N D_1 D_2 ... D_N M T_1 T_2 ... T_M
# -*- 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 collections import Counter 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 #####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)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N = I() A = IL() M = I() B = IL() dic1 = DD(int) dic2 = DD(int) for a in A: dic1[a] += 1 for b in B: dic2[b] += 1 for k in dic2: if dic2[k] > dic1[k]: print("NO") exit() print("YES")
Statement Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
[{"input": "5\n 3 1 4 1 5\n 3\n 5 4 3", "output": "YES\n \n\n* * *"}, {"input": "7\n 100 200 500 700 1200 1600 2000\n 6\n 100 200 500 700 1600 1600", "output": "NO\n \n\nNot enough 1600s.\n\n* * *"}, {"input": "1\n 800\n 5\n 100 100 100 100 100", "output": "NO\n \n\n* * *"}, {"input": "15\n 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5\n 9\n 5 4 3 2 1 2 3 4 5", "output": "YES"}]
Print `YES` if Rng can complete the problem set without creating new candidates of problems; print `NO` if he cannot. * * *
s133183095
Accepted
p03578
Input is given from Standard Input in the following format: N D_1 D_2 ... D_N M T_1 T_2 ... T_M
from collections import defaultdict def getinputdata(): # 配列初期化 array_result = [] data = input() array_result.append(data.split(" ")) flg = 1 try: while flg: data = input() if data != "": array_result.append(data.split(" ")) else: flg = 0 finally: return array_result arr_data = getinputdata() n = int(arr_data[0][0]) arr = [int(x) for x in arr_data[1]] numbers = defaultdict(lambda: 0) for v in arr: numbers[v] += 1 hash01 = dict(numbers) m = int(arr_data[2][0]) arr_problem = [int(x) for x in arr_data[3]] numbers_problem = defaultdict(lambda: 0) for v in arr_problem: numbers_problem[v] += 1 hash02 = dict(numbers_problem) chkflg = True for k, v in hash02.items(): if not k in hash01 or v > hash01[k]: chkflg = False print("YES" if chkflg else "NO")
Statement Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
[{"input": "5\n 3 1 4 1 5\n 3\n 5 4 3", "output": "YES\n \n\n* * *"}, {"input": "7\n 100 200 500 700 1200 1600 2000\n 6\n 100 200 500 700 1600 1600", "output": "NO\n \n\nNot enough 1600s.\n\n* * *"}, {"input": "1\n 800\n 5\n 100 100 100 100 100", "output": "NO\n \n\n* * *"}, {"input": "15\n 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5\n 9\n 5 4 3 2 1 2 3 4 5", "output": "YES"}]
Print `YES` if Rng can complete the problem set without creating new candidates of problems; print `NO` if he cannot. * * *
s241734228
Accepted
p03578
Input is given from Standard Input in the following format: N D_1 D_2 ... D_N M T_1 T_2 ... T_M
import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect from time import perf_counter from fractions import Fraction # sys.setrecursionlimit(int(pow(10, 2))) # sys.stdin = open("input.txt", "r") # sys.stdout = open("output.txt", "w") mod = int(pow(10, 9) + 7) mod2 = 998244353 def data(): return sys.stdin.readline().strip() def out(*var, end="\n"): sys.stdout.write(" ".join(map(str, var)) + end) def l(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int, data().split()) def ssp(): return map(str, data().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)] # @lru_cache(None) N = l()[0] D = l() M = l()[0] T = l() d = {} t = {} for i in range(N): if D[i] not in d: d[D[i]] = 0 d[D[i]] += 1 for i in range(M): if T[i] not in t: t[T[i]] = 0 t[T[i]] += 1 ans = "YES" for ks in t: if ks not in d or d[ks] < t[ks]: ans = "NO" break print(ans)
Statement Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
[{"input": "5\n 3 1 4 1 5\n 3\n 5 4 3", "output": "YES\n \n\n* * *"}, {"input": "7\n 100 200 500 700 1200 1600 2000\n 6\n 100 200 500 700 1600 1600", "output": "NO\n \n\nNot enough 1600s.\n\n* * *"}, {"input": "1\n 800\n 5\n 100 100 100 100 100", "output": "NO\n \n\n* * *"}, {"input": "15\n 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5\n 9\n 5 4 3 2 1 2 3 4 5", "output": "YES"}]
Print `YES` if Rng can complete the problem set without creating new candidates of problems; print `NO` if he cannot. * * *
s362134160
Accepted
p03578
Input is given from Standard Input in the following format: N D_1 D_2 ... D_N M T_1 T_2 ... T_M
import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from decimal import * from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9 + 7 INF = float("inf") # 無限大 def gcd(a, b): return fractions.gcd(a, b) # 最大公約数 def lcm(a, b): return (a * b) // fractions.gcd(a, b) # 最小公倍数 def iin(): return int(sys.stdin.readline()) # 整数読み込み def ifn(): return float(sys.stdin.readline()) # 浮動小数点読み込み def isn(): return sys.stdin.readline().split() # 文字列読み込み def imn(): return map(int, sys.stdin.readline().split()) # 整数map取得 def imnn(): return map(lambda x: int(x) - 1, sys.stdin.readline().split()) # 整数-1map取得 def fmn(): return map(float, sys.stdin.readline().split()) # 浮動小数点map取得 def iln(): return list(map(int, sys.stdin.readline().split())) # 整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 def join(l, s=""): return s.join(l) # リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n - r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // ( math.factorial(n - r) * math.factorial(r) ) # 組み合わせの総数 def two_distance(a, b, c, d): return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離 def m_add(a, b): return (a + b) % MOD def print_list(l): print(*l, sep="\n") def sieves_of_e(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return is_prime N = iin() D = collections.Counter(iln()) M = iin() T = collections.Counter(iln()) isOK = False for key, value in T.items(): if value > D[key]: break else: isOK = True print("YES" if isOK else "NO")
Statement Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
[{"input": "5\n 3 1 4 1 5\n 3\n 5 4 3", "output": "YES\n \n\n* * *"}, {"input": "7\n 100 200 500 700 1200 1600 2000\n 6\n 100 200 500 700 1600 1600", "output": "NO\n \n\nNot enough 1600s.\n\n* * *"}, {"input": "1\n 800\n 5\n 100 100 100 100 100", "output": "NO\n \n\n* * *"}, {"input": "15\n 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5\n 9\n 5 4 3 2 1 2 3 4 5", "output": "YES"}]
Print `YES` if Rng can complete the problem set without creating new candidates of problems; print `NO` if he cannot. * * *
s169601185
Accepted
p03578
Input is given from Standard Input in the following format: N D_1 D_2 ... D_N M T_1 T_2 ... T_M
import sys import heapq import re from itertools import permutations from bisect import bisect_left, bisect_right from collections import Counter, deque from fractions import gcd from math import factorial, sqrt, ceil from functools import lru_cache, reduce INF = 1 << 60 MOD = 1000000007 sys.setrecursionlimit(10**7) # UnionFind class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) # ダイクストラ def dijkstra_heap(s, edge, n): # 始点sから各頂点への最短距離 d = [10**20] * n used = [True] * n # True:未確定 d[s] = 0 used[s] = False edgelist = [] for a, b in edge[s]: heapq.heappush(edgelist, a * (10**6) + b) while len(edgelist): minedge = heapq.heappop(edgelist) # まだ使われてない頂点の中から最小の距離のものを探す if not used[minedge % (10**6)]: continue v = minedge % (10**6) d[v] = minedge // (10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1]) return d # 素因数分解 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 # 2数の最小公倍数 def lcm(x, y): return (x * y) // gcd(x, y) # リストの要素の最小公倍数 def lcm_list(numbers): return reduce(lcm, numbers, 1) # リストの要素の最大公約数 def gcd_list(numbers): return reduce(gcd, numbers) # 素数判定 def is_prime(n): if n <= 1: return False p = 2 while True: if p**2 > n: break if n % p == 0: return False p += 1 return True # limit以下の素数を列挙 def eratosthenes(limit): A = [i for i in range(2, limit + 1)] P = [] while True: prime = min(A) if prime > sqrt(limit): break P.append(prime) i = 0 while i < len(A): if A[i] % prime == 0: A.pop(i) continue i += 1 for a in A: P.append(a) return P # 同じものを含む順列 def permutation_with_duplicates(L): if L == []: return [[]] else: ret = [] # set(集合)型で重複を削除、ソート S = sorted(set(L)) for i in S: data = L[:] data.remove(i) for j in permutation_with_duplicates(data): ret.append([i] + j) return ret # ここから書き始める n = int(input()) d = Counter(list(map(int, input().split()))) m = int(input()) t_list = list(map(int, input().split())) t = Counter(t_list) # print("d =", d) # print("t =", t) yes = True for i in t_list: # print() # print("d =", d) # print("t =", t) if d[i] == 0: yes = False break d[i] -= 1 if yes: print("YES") else: print("NO")
Statement Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
[{"input": "5\n 3 1 4 1 5\n 3\n 5 4 3", "output": "YES\n \n\n* * *"}, {"input": "7\n 100 200 500 700 1200 1600 2000\n 6\n 100 200 500 700 1600 1600", "output": "NO\n \n\nNot enough 1600s.\n\n* * *"}, {"input": "1\n 800\n 5\n 100 100 100 100 100", "output": "NO\n \n\n* * *"}, {"input": "15\n 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5\n 9\n 5 4 3 2 1 2 3 4 5", "output": "YES"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s915825043
Accepted
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
import queue from collections import defaultdict import copy N, M = map(int, input().split()) A = list(map(int, input().split())) ma = [2, 5, 5, 4, 5, 6, 3, 7, 6] BA = [[0, 0] for _ in range(M)] # (必要本数,-1*数字) for i in range(M): BA[i][1] = -1 * A[i] BA[i][0] = ma[A[i] - 1] BA.sort() # 同じ本数使うものを消去 can = [] ii = 0 while ii < len(BA): if BA[ii][0] in can: BA.pop(ii) else: can.append(BA[ii][0]) ii += 1 M = len(BA) # Mの書き換え diff = [0] * M # 数字変更の際に追加で必要な本数 for i in range(M): diff[i] = BA[i][0] - BA[0][0] BA[i][1] = BA[i][1] * -1 # (必要本数,数字)に直しておく fi = BA[0] ### # BA.sort(key=lambda x: x[1]*-1)#数字の大きいもの順 p = [1] * (N + 1) for i in range(N): p[i + 1] = p[i] * 10 # 数字のセットL(sort済み)から作れる最大の数値を出力 def set_to_num(L): ans = 0 for i in range(len(L)): ans += L[i] * p[i] return ans # 2つの配列を合わせる def make_set(temp, L): ori = copy.deepcopy(temp) for i in range(len(L)): ori[i] = L[i] ori.sort() return ori # dd用hash def make_h(L): h = 0 for i in range(len(L)): h += p[i] * L[i] return h ans = -1 Max_dig = N // fi[0] for d in range(Max_dig): # 減らす桁数 dig = Max_dig - d rem = N - fi[0] * dig temp = [fi[1]] * dig dd = defaultdict(int) q = queue.Queue() q.put((rem, [])) # 残り本数,入れ替える数字 while not q.empty(): rem2, L = q.get() if rem2 == 0: # print(temp,L) LLL = make_set(temp, L) # print(LLL) ans = max(ans, set_to_num(LLL)) else: for i in range(1, M): # 変更候補の数字を見ていく.0番は自身のためのぞく if rem2 >= diff[i]: LL = copy.deepcopy(L) LL.append(BA[i][1]) if len(LL) <= len(temp): LL.sort() h = make_h(LL) if dd[h] == 0: q.put((rem2 - diff[i], LL)) dd[h] = 1 if ans != -1: break print(ans)
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s399736893
Accepted
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
#!/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 copy, 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, m = mi() A = lmi() # A の前処理 (同じ必要本数なのに値が小さいやつらが入っていたら削除しておく) if 6 in A and 9 in A: A.remove(6) if 2 in A and 5 in A: A.remove(2) if 3 in A and 5 in A: A.remove(3) if 2 in A and 3 in A: A.remove(2) # 各数字とマッチの必要本数の対応テーブル num_to_match = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} match_to_num = dict() for num in A: match_to_num[num_to_match[num]] = num needed_match = [num_to_match[num] for num in A] # dp[i] = (指定された数字を使い i 本全部を使って作れる最大桁数, 使用数字のカウンタ) dp = [[None, None] for _ in range(n + 1)] dp[0][0] = 0 dp[0][1] = Counter() def counter_gt(c1, c2): # print(f"{c1} {c2}") return sorted(tuple(c1.items()), key=lambda x: x[0], reverse=True) > sorted( tuple(c2.items()), key=lambda x: x[0], reverse=True ) for i in range(n + 1): digit_max = 0 counter_memo = None for match in needed_match: if i - match >= 0 and dp[i - match][0] is not None: tmp = copy(dp[i - match][1]) tmp[match_to_num[match]] += 1 if dp[i - match][0] + 1 > digit_max or ( dp[i - match][0] + 1 == digit_max and counter_gt(tmp, counter_memo) ): digit_max = dp[i - match][0] + 1 counter_memo = copy(dp[i - match][1]) counter_memo[match_to_num[match]] += 1 if digit_max != 0: dp[i][0] = digit_max dp[i][1] = counter_memo # print('') # for elm in dp: # print(elm) char_array = [None] * dp[n][0] cnt = 0 t = sorted(dp[n][1].items(), key=lambda x: x[0], reverse=True) for k, v in t: for i in range(v): char_array[i + cnt] = str(k) cnt += v print("".join(char_array)) if __name__ == "__main__": main()
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s211859747
Wrong Answer
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
n, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] move = [0, 0, 0, 0, 0, 0] for i in a: stick = match[i] move[stick - 2] = i dp = [[0, 0, 0, 0, 0, 0] for i in range(n + 10)] for i in range(n): if not any(dp[i]): if i: continue for k, v in enumerate(move, 2): if v: dp[i + k] = list() for k2, v2 in enumerate(dp[i]): if k - 2 == k2: v2 += 1 dp[i + k].append(v2) ANS = sorted([[i, j] for i, j in zip(move, dp[n])], reverse=True) ans = "" for i, j in ANS: ans += str(i) * j print(ans)
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s352281954
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
import numpy as np def judge(N, n, list_new, A, min): # judge if we can make the perfect match if n == 1: if N in list_new: s = np.where(N == list_new) s = s[0].tolist() l = [] for item in A[s]: l.append([item]) return l else: return [] listy = [] list_here = np.sort(list_new) list_h = list_here[::-1] for i in range(len(list_h)): item = list_new[i] M = N - item m = n - 1 if M < min * m or item * m < M: pass else: s = judge(M, m, list_new, A, min) if s != []: for sin in s: listy.append(np.append(sin, A[i])) if listy == []: return [] else: return listy list = [2, 5, 5, 4, 5, 6, 3, 7, 6] s = input() s = s.split() N = int(s[0]) M = int(s[1]) t = input() A = t.split() list_new = [] for i in range(M): A[i] = int(A[i]) A = np.array(A) for item in A: list_new.append(list[item - 1]) list_new = np.array(list_new) min = np.min(list_new) q, mod = divmod(N, min) a = np.where(list_new == min) a = a[0].tolist() num = A[a] digit = max(num) number = str(digit) * q while True: a = judge(N, q, list_new, A, min) if a != []: listofnumbers = [] for item in a: item.sort() string = "" for i in item: string = str(i) + string listofnumbers.append(int(string)) print(np.max(listofnumbers)) break else: q = q - 1
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s217302954
Wrong Answer
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
import numpy as np n, m = list(map(int, input().split())) a = list(map(int, input().split())) need_lis = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] use_lis = [need_lis[i] for i in a] use_lis.sort() use_num_lis = [] for i in use_lis: if i == 2: use_num_lis.append(1) if i == 3: use_num_lis.append(7) if i == 4: use_num_lis.append(4) if i == 5: if 5 in a: use_num_lis.append(5) elif 3 in a: use_num_lis.append(3) else: use_num_lis.append(2) if i == 6: if 9 in a: use_num_lis.append(9) else: use_num_lis.append(6) if i == 7: use_num_lis.append(8) ok_lis = [] for i in range(use_lis[0] ** (len(use_lis) - 1)): ind_lis = [] for j in range(len(use_lis) - 2, -1, -1): # print(j) ind_lis.append(i // (use_lis[0] ** j)) i -= (i // (use_lis[0] ** j)) * (use_lis[0] ** j) # print(ind_lis) count = 0 for i in range(len(use_lis) - 1): count += use_lis[i + 1] * ind_lis[i] # print(count) if (n - count) % use_lis[0] == 0: # print(n-count) rest = n - count ok_lis.append([int(rest / use_lis[0])] + ind_lis) res = [] for i in ok_lis: res.append(sum(i)) max_lis = [i for i in range(len(res)) if res[i] == max(res)] answers_lis = [] for i in max_lis: answer = "" use = ok_lis[i] num_lis = use_num_lis for k in range(len(use)): ind = np.argmax(np.array(num_lis)) # print(ind) if use[ind] > 0: count = 0 for j in range(use[ind]): # print(type(count)) count += (10**j) * num_lis[ind] count = str(count) # print(type(count)) answer += count num_lis[ind] = 0 answers_lis.append(answer) use_num_lis = [] for i in use_lis: if i == 2: use_num_lis.append(1) if i == 3: use_num_lis.append(7) if i == 4: use_num_lis.append(4) if i == 5: if 5 in a: use_num_lis.append(5) elif 3 in a: use_num_lis.append(3) else: use_num_lis.append(2) if i == 6: if 9 in a: use_num_lis.append(9) else: use_num_lis.append(6) if i == 7: use_num_lis.append(8) print(int(max(answers_lis)))
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s296772105
Wrong Answer
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
# coding: utf-8 # Your code here! from collections import defaultdict N, M = map(int, input().rstrip().split(" ")) A = sorted(list(map(int, input().rstrip().split(" "))))[::-1] numbers = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} temp = [False] * 8 temp_A = [] for a in A: if temp[numbers[a]] == False: temp_A.append(a) temp[numbers[a]] = True A = temp_A max_numbers = [] memo = defaultdict(lambda: defaultdict(lambda: [-1, -1])) memo2 = defaultdict(lambda: defaultdict(lambda: [])) def recursive(n, honsu, sum_numbers, i): if memo[n][i][0] != -1: return memo[n][i][0], memo[n][i][1], memo2[n][i] if n == 0: return honsu, sum_numbers, [0] * (len(A) - i) max_honsu = -1 max_sum_numbers = -1 max_k = [] for j in range(i, len(A)): a = A[j] for k in range(n // numbers[a] + 1): return_honsu, return_sum_numbers, return_ks = recursive( n - numbers[a] * k, honsu + k, sum_numbers + a * k, j + 1 ) if return_honsu > max_honsu: max_honsu = return_honsu max_sum_numbers = return_sum_numbers max_k = [k] + return_ks elif return_honsu == max_honsu: if return_sum_numbers > max_sum_numbers: max_sum_numbers = return_sum_numbers max_k = [k] + return_ks memo[n][i][0] = max_honsu memo[n][i][1] = max_sum_numbers memo2[n][i] = max_k return max_honsu, max_sum_numbers, max_k honsu, sum_numbers, _ = recursive(N, 0, 0, 0) honsu = sorted([[a, x] for a, x in zip(A, memo2[N][0])], key=lambda x: x[0])[::-1] for a, x in honsu: for _ in range(x): print(a, end="")
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s041483303
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
N, M = map(int, input().split()) A = list(map(int, input().split())) AtoH = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] H = [AtoH[a] for a in A] # print("H:", H) dp = [0] * (N + 1) dpl = [0] * (N + 1) for i in range(M): h, a = H[i], A[i] dp[N - h] = max(dp[N - h], dp[N] + a) dpl[N - h] = 1 for dpi in range(N - 1, -1, -1): if dp[dpi]: for m in range(M): h, a = H[m], A[m] if dpi - h >= 0: if dp[dpi - h] < dp[dpi] + 10 ** dpl[dpi] * a: dp[dpi - h] = dp[dpi] + 10 ** dpl[dpi] * a dpl[dpi - h] = dpl[dpi] + 1 print(dp[0])
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s317464163
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
n, m = map(int, input().split(" ")) useable_numbers = list(sorted(map(int, input().split(" ")))) required_maches = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} dp = dict() def evaluate(used_numbers): if used_numbers == []: return 0 return int("".join(map(str, sorted(used_numbers, reverse=True)))) def find(used_matches): if used_matches in dp: return dp[used_matches] if used_matches == 0: dp[used_matches] = [] return dp[used_matches] if used_matches < 0: dp[used_matches] = None return dp[used_matches] candidates = [ ai for ai in useable_numbers if find(used_matches - required_maches[ai]) is not None ] if candidates == []: dp[used_matches] = None return dp[used_matches] max_ai = max( candidates, key=lambda ai: evaluate(find(used_matches - required_maches[ai]) + [ai]), ) dp[used_matches] = find(used_matches - required_maches[max_ai]) + [max_ai] return dp[used_matches] print(evaluate(find(n)))
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s306618318
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
from sys import stdin N, M = [int(x) for x in stdin.readline().rstrip().split()] S = [2, 5, 5, 4, 5, 6, 3, 7, 6] A = [int(x) for x in stdin.readline().rstrip().split()] B = [(x, S[x - 1]) for x in A] B.sort(key=lambda x: x[1]) print(B) def solve(match, ans): if match == 0: return int(ans) if match < B[0][1]: return -1 return max([solve(match - B[k][1], ans + str(B[k][0])) for k in range(len(A))]) print(solve(N, ""))
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s255028408
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort() B = [[] for i in range(0, 10)] for i in range(0, M): if 1 in A: B[2].append(1) if 2 in A: B[5].append(2) if 3 in A: B[5].append(3) if 4 in A: B[4].append(4) if 5 in A: B[5].append(5) if 6 in A: B[6].append(6) if 7 in A: B[3].append(7) if 8 in A: B[7].append(8) if 9 in A: B[6].append(9) dp = ["n" for i in range(0, N + 1)] if 1 in A: dp[2] = 1 if 2 in A: dp[5] = 2 if 3 in A: dp[5] = 3 if 4 in A: dp[4] = 4 if 5 in A: dp[5] = 5 if 6 in A: dp[6] = 6 if 7 in A: dp[3] = 7 if 8 in A: dp[7] = 8 if 9 in A: dp[6] = 9 for i in range(4, N + 1): if i == 4: if B[2] != []: dp[4] = 11 if i == 5: if B[3] != [] and dp[2] != "n": dp[5] = 71 if i == 6: a = 0 b = 0 c = 0 if B[2] != [] and dp[4] != "n": a = 1 * 10 ** len(str(dp[4])) + dp[4] if B[3] != []: b = 77 if B[4] != [] and dp[2] != "n": c = 41 if dp[6] == "n": x = max(a, b, c) if x != 0: dp[6] = x else: dp[6] = max(a, b, c, dp[6]) if i == 7: a = 0 b = 0 c = 0 d = 0 if B[2] != [] and dp[5] != "n": a = 1 * 10 ** len(str(dp[5])) + dp[5] if B[3] != [] and dp[4] != "n": b = 7 * 10 ** len(str(dp[4])) + dp[4] if B[4] != [] and dp[3] != "n": c = 47 if B[5] != [] and dp[2] != "n": d = max(B[5]) * 10 + 1 if dp[7] == "n": x = max(a, b, c, d) if x != 0: dp[7] = x else: dp[7] = max(dp[7], a, b, c, d) if i > 7: a = 0 b = 0 c = 0 d = 0 e = 0 f = 0 if B[2] != [] and dp[i - 2] != "n": a = 1 * 10 ** (len(str(dp[i - 2]))) + dp[i - 2] if B[3] != [] and dp[i - 3] != "n": b = 7 * 10 ** (len(str(dp[i - 3]))) + dp[i - 3] if B[4] != [] and dp[i - 4] != "n": c = 4 * 10 ** (len(str(dp[i - 4]))) + dp[i - 4] if B[5] != [] and dp[i - 5] != "n": d = max(B[5]) * 10 ** (len(str(dp[i - 5]))) + dp[i - 5] if B[6] != [] and dp[i - 6] != "n": e = max(B[6]) * 10 ** (len(str(dp[i - 6]))) + dp[i - 6] if B[7] != [] and dp[i - 7] != "n": f = 8 * 10 ** (len(str(dp[i - 7]))) + dp[i - 7] x = max(a, b, c, d, e, f) if x == 0: dp[i] = "n" else: dp[i] = x print(dp[N])
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s464613942
Wrong Answer
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
n, m = map(int, input().split()) arr = list(map(int, input().split())) dic = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} cand = [[""] for _ in range(6)] for val in arr: cand[dic[val] - 2].append(str(val)) pos = 6 for i in range(5, -1, -1): cand[i] = sorted(cand[i], reverse=True) if len(cand[i]) > 1: pos = i ans = [] for c1 in range(n // (pos + 2), max(-1, n // (pos + 2) - 11), -1): tmp = [[cand[pos][0], c1]] if pos == 5 and (pos + 2) * c1 == n: t = "" tmp = sorted(tmp, reverse=True, key=lambda x: x[0]) for char, val in tmp: t += char * val ans.append(t) for c2 in range(11): if pos >= 5: continue tmp2 = tmp + [[cand[pos + 1][0], c2]] if pos == 4 and (pos + 2) * c1 + (pos + 2 + 1) * c2 == n: t = "" tmp2 = sorted(tmp2, reverse=True, key=lambda x: x[0]) for char, val in tmp2: t += char * val ans.append(t) for c3 in range(11): if pos >= 4: continue tmp3 = tmp2 + [[cand[pos + 2][0], c3]] if ( pos == 3 and (pos + 2) * c1 + (pos + 2 + 1) * c2 + (pos + 2 + 2) * c3 == n ): t = "" tmp3 = sorted(tmp3, reverse=True, key=lambda x: x[0]) for char, val in tmp3: t += char * val ans.append(t) for c4 in range(11): if pos >= 3: continue tmp4 = tmp3 + [[cand[pos + 3][0], c4]] if ( pos == 2 and (pos + 2) * c1 + (pos + 2 + 1) * c2 + (pos + 2 + 2) * c3 + (pos + 2 + 3) * c4 == n ): t = "" tmp4 = sorted(tmp4, reverse=True, key=lambda x: x[0]) for char, val in tmp4: t += char * val ans.append(t) for c5 in range(11): if pos >= 2: continue tmp5 = tmp4 + [[cand[pos + 4][0], c5]] if ( pos == 1 and (pos + 2) * c1 + (pos + 2 + 1) * c2 + (pos + 2 + 2) * c3 + (pos + 2 + 3) * c4 + (pos + 2 + 4) * c5 == n ): t = "" tmp5 = sorted(tmp5, reverse=True, key=lambda x: x[0]) for char, val in tmp5: t += char * val ans.append(t) for c6 in range(11): if pos >= 1: continue tmp6 = tmp5 + [[cand[pos + 5][0], c6]] if ( pos == 0 and (pos + 2) * c1 + (pos + 2 + 1) * c2 + (pos + 2 + 2) * c3 + (pos + 2 + 3) * c4 + (pos + 2 + 4) * c5 + (pos + 2 + 5) * c6 == n ): t = "" tmp6 = sorted(tmp6, reverse=True, key=lambda x: x[0]) for char, val in tmp6: t += char * val ans.append(t) ans = sorted(ans, reverse=True, key=lambda x: len(x)) print(ans[0])
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s893138486
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
n, m = map(int, input().split()) num = list(map(int, input().split())) num_dic = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} dp = [0] * (n + 1) def creat_num(original, num): # original=431,num=1 return 4311 if original == 0: return num new = list(map(int, list(str(original)))) + [num] new.sort() new.reverse() return int("".join(list(map(str, new)))) def match_dp(dp, num, num_dic, n): for i in num: if n - num_dic[i] >= 0: new_num = creat_num(dp[n], i) dp[n - num_dic[i]] = max(new_num, dp[n - num_dic[i]]) match_dp(dp, num, num_dic, n - num_dic[i]) match_dp(dp, num, num_dic, n) print(dp[0])
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s131532172
Wrong Answer
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
from itertools import permutations n, m = list(map(int, input().split())) aa = list(map(int, input().split())) match = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] minm = min(match[a] for a in aa) keta = n // minm if m == 1: print(str(aa[0]) * keta) elif m == 2: ans_best = 0 for a0, a1 in permutations(aa, 2): m0, m1 = match[a0], match[a1] for i in range(min(6, keta)): ans = int(str(a0) * i + str(a1) * (keta - i)) if m0 * i + m1 * (keta - i) == n: ans_best = max(ans_best, ans) ans = int(str(a0) * (keta - i) + str(a1) * i) if m0 * (keta - i) + m1 * i == n: ans_best = max(ans_best, ans) print(ans_best) else: ans_best = 0 for a0, a1, a2 in permutations(aa, 3): m0, m1, m2 = match[a0], match[a1], match[a2] for i in range(min(6, keta)): for j in range(min(6, keta) - i): ans = int(str(a0) * i + str(a1) * j + str(a2) * (keta - i - j)) if m0 * i + m1 * j + m2 * (keta - i - j) == n: ans_best = max(ans_best, ans) ans = int(str(a0) * i + str(a1) * (keta - i - j) + str(a2) * j) if m0 * i + m1 * (keta - i - j) + m2 * j == n: ans_best = max(ans_best, ans) ans = int(str(a0) * (keta - i - j) + str(a1) * i + str(a2) * j) if m0 * (keta - i - j) + m1 * i + m2 * j == n: ans_best = max(ans_best, ans) print(ans_best)
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s268502316
Wrong Answer
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
def examA(): A, B = LI() if B % A == 0: ans = A + B else: ans = B - A print(ans) return def examB(): N, M = LI() Flag = [0] * M for i in range(N): K = LI() for j in range(1, K[0] + 1): Flag[K[j] - 1] += 1 ans = 0 for i in Flag: if i == N: ans += 1 print(ans) return def gcd(x, y): if y == 0: return x while y != 0: x, y = y, x % y return x def examC(): N = I() A = LI() cur = A[0] for i in range(N - 1): cur = gcd(cur, A[i + 1]) ans = cur print(ans) return def examD(): N, M = LI() A = LI() A.sort() Matti = [2, 5, 5, 4, 5, 6, 3, 7, 6] D = {} for a in A: D[Matti[a - 1]] = a # print(D) dp = [-inf] * (N + 10) dp[0] = 0 for i in range(N): for matti, num in D.items(): dp[i + matti] = max(dp[i + matti], dp[i] + 1) # print(dp) used = [] i = N while i > 0: # print(i) # input() for matti, num in D.items(): if i - matti < 0: continue if dp[i - matti] == dp[i] - 1: used.append(num) i -= matti # print(used) used.sort(reverse=True) ans = "".join(map(str, used)) print(ans) return import sys, copy, bisect, itertools, heapq, math from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 alphabet = [chr(ord("a") + i) for i in range(26)] if __name__ == "__main__": examD() """ 31 2 5 8 """
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s830313631
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
import sys from bisect import bisect_left INF = 1 << 30 def main(): N, M = map(int, input().split()) A = set(map(str, input().split())) number = "174532968" necesary_match = (2, 3, 4, 5, 5, 5, 6, 6, 7) match = {i: j for i, j in zip(number, necesary_match)} if "1" in A: if N % 2 == 0: ans = ["1"] * (N // 2) else: for num in "75328": if num in A: ans = ["1"] * ((N - match[num]) // 2) + [num] break elif "7" in A: if N % 3 == 0: ans = ["7"] * (N // 3) elif N % 3 == 1: flag = False for num in "48": if num in A: flag = True ans = ["7"] * ((N - match[num]) // 3) + [num] break if not flag: for num in "532": if num in A: ans = ["7"] * ((N - 2 * match[num]) // 3) + [num] * 2 break else: flag = False for num in "532": if num in A: flag = True ans = ["7"] * ((N - match[num]) // 3) + [num] break if not flag: for num in "48": if num in A: ans = ["7"] * ((N - 2 * match[num]) // 3) + [num] * 2 break elif "4" in A: if N % 4 == 0: ans = ["4"] * (N // 4) elif N % 4 == 1: flag = False for num in "532": if num in A: flag = True ans = ["4"] * ((N - match[num]) // 4) + [num] break if not flag: for num in "96": if num in A: flag = True ans = ["4"] * ((N - match[num] - match["8"]) // 4) + [num, "8"] break if not flag: ans = ["4"] * ((N - match["8"] * 3) // 4) + ["8"] * 3 elif N % 4 == 2: flag = False for num in "96": if num in A: ans = ["4"] * ((N - match[num]) // 4) + [num] flag = True break if not flag: for num in "532": if num in A: ans = ["4"] * ((N - 2 * match[num]) // 4) + [num] * 2 flag = True break if not flag: ans = ["4"] * ((N - 2 * match["8"]) // 4) + ["8"] * 2 else: flag = False if "8" in A: flag = True ans = ["4"] * ((N - match["8"]) // 4) + ["8"] if not flag: x = "" for num in "96": if num in A: x = num break y = "" for num in "532": if num in A: y = num break if x: ans = ["4"] * ((N - match[x] - match[y]) // 4) + [x, y] else: ans = ["4"] * ((N - 3 * match[y]) // 4) + [y] * 3 else: x = "" for num in "532": if num in A: x = num break if x: if N % 5 == 0: ans = [x] * (N // 5) elif N & 5 == 1: flag = False for num in "96": if num in A: flag = True ans = [x] * ((N - match[num]) // 5) + [num] break if not flag: ans = [x] * ((N - 3 * match["8"]) // 5) + ["8"] * 3 elif N % 5 == 2: if "8" in A: ans = [x] * ((N - match["8"]) // 5) + ["8"] else: for num in "96": if num in A: ans = [x] * ((N - 2 * match[num]) // 5) + [num] * 2 break elif N % 5 == 3: if "8" in A: flag = False for num in "96": if num in A: flag = True ans = [x] * ((N - match[num] - match["8"]) // 5) + [ "8", num, ] break if not flag: ans = [x] * ((N - 4 * match["8"]) // 5) + ["8"] * 4 elif N % 5 == 4: if "8" in A: ans = [x] * ((N - 2 * match["8"]) // 5) + ["8"] * 2 else: for num in "96": if num in A: ans = [x] * ((N - 4 * match[num]) // 5) + [num] * 4 break else: y = "" for num in "96": if num in A: y = num break if y: if N % 6 == 0: ans = [y] * (N // 6) else: k = N % 6 ans = [y] * ((N - k * match["8"]) // 6) + ["8"] * k else: ans = ["8"] * (N // 7) ans.sort(reverse=True) print("".join(ans)) if __name__ == "__main__": main()
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s166195641
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def STR(): return input() def INT(): return int(input()) def MAP(): return map(int, input().split()) def S_MAP(): return map(str, input().split()) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) inf = sys.maxsize mod = 10**9 + 7 n, m = MAP() a = LIST() b = [2, 5, 5, 4, 5, 6, 3, 7, 6] arr = [[1, 2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]] arr2 = [] for i in range(9): if arr[i][0] in a: arr2.append(arr[i]) arr2.sort(key=lambda x: x[1]) # print('arr2', arr2) larr2 = len(arr2) ans = [] arr3 = [] arr4 = [] for i in range(larr2): for j in range(i + 1, larr2): if not arr2[i][1] + arr2[j][1] in arr3: arr3.append(arr2[i][1] + arr2[j][1]) arr4.append([arr2[i][0], arr2[j][0]]) else: index = arr3.index(arr2[i][1] + arr2[j][1]) arr4[index].sort(reverse=True) t = sorted([arr2[i][0], arr2[j][0]], reverse=True) flag = False if a[0] > arr4[index][0] or ( a[0] == arr4[index][0] and t[1] > arr4[index][1] ): arr4[index] = t # print('arr3', arr3) # print('arr4', arr4) maxarr3 = max(arr3) ii = 0 while n > 0: if n in arr3 and not n - arr2[ii][1] in arr3: index = arr3.index(n) ans.append(arr4[index][0]) ans.append(arr4[index][1]) n = 0 elif ii >= 0: n -= arr2[ii][1] ans.append(arr2[ii][0]) elif n < maxarr3 or ii < 0: index = arr2.index([ans[len(ans) - 1], b[ans[len(ans) - 1] - 1]]) n += arr2[index][1] del ans[len(ans) - 1] ii = index + 1 if ii >= larr2: ii = -1 # print(n) # print('ans', ans) ans.sort(reverse=True) anstr = "" for i in range(len(ans)): anstr += str(ans[i]) print(anstr) """ for i in range(len(arr2)): l = n // arr2[i][1] #同じ数字の桁数 m = n % arr2[i][1] #端数 print(l, m) if m != 0: while indexes = [] for j in range(len(arr2)): if m == arr2[j][1]: indexes.append(j) print(indexes) index = -1 mx = 0 for j in indexes: if mx < arr2[j][0]: mx = arr2[j][0] index = j if index >= 0: if arr2[index][0] > arr2[i][0]: ans = str(arr2[index][0]) + str(arr2[i][0]) * l print('a') print(ans) exit() else: ans = str(arr2[i][0]) * l + str(arr2[index][0]) print('b') print(ans) exit() elif m == 0: ans = str(arr2[index][0]) * l print('c') print(ans) exit() """
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s819433645
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
N, M = list(map(int, input().split())) A = list(map(int, input().split())) # len(A)=M _dict = {} num_matches = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} for a in A: _dict[num_matches[a]] = _dict.get(num_matches[a], []) + [a] # print(_dict) memo = [None for _ in range(N + 1)] # return memo[N] # Nほんのマッチを使って作れる整数の最大値.(作れなければ0) def max_int_with_match(n): if memo[n]: return memo[n] if n < min(_dict.keys()): memo[n] = 0 return memo[n] memo[n] = max( max(_dict.get(n, [0])), max( map( lambda x: max(_dict[x]) + 10 * max_int_with_match(n - x), list(filter(lambda x: x < n, _dict.keys())), ) ), ) return memo[n] print(max_int_with_match(N)) # print(memo)
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s142619817
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
n, m = [int(i) for i in input().split()] e = [[int(i) for i in input().split()] for i in range(n)] s = [] for t in e: b_list = 0 for x in t[1:]: b_list = b_list | pow(2, x - 1) s.append(b_list) result = pow(2, 30) - 1 for i in s: result = result & i cnt = 0 for i in range(30): if result & pow(2, i): cnt += 1 print(cnt)
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s167253908
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
n, m = map(int, input().split()) l = list(map(int, input().split())) if 1 in l: if n % 2 == 0: ans = "1" * (n / 2) else: if 7 in l: ans = "7" + "1" * (int(n / 2) - 1) elif 5 in l: ans = "5" + "1" * (int(n / 2) - 2) elif 3 in l: ans = "3" + "1" * (int(n / 2) - 2) elif 2 in l: ans = "2" + "1" * (int(n / 2) - 2) elif 8 in l: ans = "8" + "1" * (int(n / 2) - 3) else: ans = "0" print(ans)
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s255938254
Accepted
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
l = [[0, 0], [1, 2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]] n, m = map(int, input().split()) a = list(map(int, input().split())) l0 = [] for i in range(m): l0.append(l[a[i]]) l0.sort(key=lambda x: x[0], reverse=True) l0.sort(key=lambda x: x[1]) p, q = l0[0] count = n - (n // q) * q c = 1 ans = 0 for i in range(n // q): ans += p * c c *= 10 c = c // 10 l0.sort(key=lambda x: x[0], reverse=True) i = 0 while count > 0 and i < m: p1, q1 = l0[i] if q1 > q: q1 -= q # print(count) if p1 > p: while count >= q1: ans -= p * c ans += p1 * c count -= q1 c = c // 10 i += 1 else: i += 1 i = 0 c = 1 l0.sort(key=lambda x: x[1], reverse=True) while count > 0 and i < m: p1, q1 = l0[i] if q1 > q: q1 -= q if p1 < p: while count >= q1: ans -= p * c ans += p1 * c count -= q1 c *= 10 i += 1 else: i += 1 if count == 0: print(ans) else: x = n // q - 1 for i in range(n // q - 1): count = n - (x) * q c = 1 ans = 0 for i in range(x): ans += p * c c *= 10 c = c // 10 l0.sort(key=lambda x: x[0], reverse=True) i = 0 while count > 0 and i < m: p1, q1 = l0[i] if q1 > q: q1 -= q # print(count) if p1 > p: while count >= q1: ans -= p * c ans += p1 * c count -= q1 c = c // 10 i += 1 else: i += 1 i = 0 c = 1 l0.sort(key=lambda x: x[1], reverse=True) while count > 0 and i < m: p1, q1 = l0[i] if q1 > q: q1 -= q if p1 < p: while count >= q1: ans -= p * c ans += p1 * c count -= q1 c *= 10 i += 1 else: i += 1 if count == 0: print(ans) break else: x += 1
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s716839400
Wrong Answer
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
N, M = map(int, input().split()) A = list(input().split()) if "1" in A: if N % 2 == 0: print("1" * (N // 2)) else: if "7" in A: print("7" + "1" * (N // 2 - 1)) else: print("1" * (N // 2)) else: if "7" in A: if N % 3 == 0: print("7" * (N // 3)) elif N % 3 == 1: if "4" in A: print("7" * (N // 3 - 1) + "4") elif "8" in A: print("8" + "7" * (N // 3 - 2)) elif N % 3 == 2: if "5" in A: print("7" * (N // 3 - 1) + "5") elif "3" in A: print("7" * (N // 3 - 1) + "3") elif "2" in A: print("7" * (N // 3 - 1) + "2") elif "4" in A: if N % 3 == 3: if N >= 11 and "9" in A and "5" in A: print("95" + "4" * (N // 4 - 2)) elif N >= 11 and "9" in A and "3" in A: print("9" + "4" * (N // 4 - 2) + "3") elif N >= 11 and "9" in A and "2" in A: print("9" + "4" * (N // 4 - 2) + "2") elif "8" in A: print("8" + "4" * (N // 4 - 1)) elif N >= 11 and "6" in A and "5" in A: print("65" + "4" * (N // 4 - 2)) elif N >= 11 and "6" in A and "3" in A: print("6" + "4" * (N // 4 - 2) + "3") elif N >= 11 and "6" in A and "2" in A: print("6" + "4" * (N // 4 - 2) + "2") elif N % 4 == 2 and "9" in A: print("9" + "4" * (N // 4 - 1)) elif N % 4 == 2 and "6" in A: print("6" + "4" * (N // 4 - 1)) elif N % 4 != 0 and "5" in A: print("5" * min(N % 4, N // 5) + "4" * (N // 4 - min(N % 4, N // 5))) elif N % 4 != 0 and "3" in A: print("4" * (N // 4 - min(N % 4, N // 5)) + "3" * min(N % 4, N // 5)) elif N % 4 != 0 and "5" in A: print("4" * (N // 4 - min(N % 4, N // 5)) + "2" * min(N % 4, N // 5)) else: print("4" * (N // 4)) elif "5" in A: if N % 5 != 0 and "9" in A: print("9" * min(N % 5, N // 6) + "5" * (N // 5 - min(N % 5, N // 6))) elif N % 5 == 2 and "8" in A: print("8" + "5" * (N // 5 - 1)) elif N % 5 != 0 and "6" in A: print("6" * min(N % 5, N // 6) + "5" * (N // 5 - min(N % 5, N // 6))) else: print("5" * (N // 5)) elif "3" in A: if N % 5 != 0 and "9" in A: print("9" * min(N % 5, N // 6) + "3" * (N // 5 - min(N % 5, N // 6))) elif N % 5 == 2 and "8" in A: print("8" + "3" * (N // 5 - 1)) elif N % 5 != 0 and "6" in A: print("6" * min(N % 5, N // 6) + "3" * (N // 5 - min(N % 5, N // 6))) else: print("3" * (N // 5)) elif "2" in A: if N % 5 != 0 and "9" in A: print("9" * min(N % 5, N // 6) + "2" * (N // 5 - min(N % 5, N // 6))) elif N % 5 == 2 and "8" in A: print("8" + "2" * (N // 5 - 1)) elif N % 5 != 0 and "6" in A: print("6" * min(N % 5, N // 6) + "2" * (N // 5 - min(N % 5, N // 6))) else: print("2" * (N // 5)) elif "9" in A: print("9" * (N // 6)) elif "6" in A: if N % 6 != 0 and "8" in A: print("8" * min(N % 6, N // 7) + "6" * (N // 6 - min(N % 6, N // 7))) else: print("6" * (N // 6)) else: if "8" in A: print("8" * (N // 7))
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s310717185
Wrong Answer
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
from itertools import product e = [10, 2, 5, 5, 4, 5, 6, 3, 7, 6] n, m = map(int, input().split()) a = sorted(map(int, input().split())) d = {} for i in a: if e[i] not in d: d[e[i]] = i elif d[e[i]] < i: d[e[i]] = i dd = sorted( [[i[0] + j[0], i[1] * 10 + j[1]] for i, j in product(d.items(), d.items())] + [[k, v] for k, v in d.items()] ) d = {} for k, v in dd: if k not in d: d[k] = v elif d[k] < v: d[k] = v dd = [[k, v] for k, v in sorted(d.items())] # [print(k,v) for k,v in dd] # print() if 2 in d: kk = 2 vv = 1 elif 3 in d: kk = 3 vv = 7 else: kk = 10000 vv = 0 for match_num, num in dd: if kk >= match_num and vv < num: kk = match_num vv = num elif kk * 2 > match_num and vv * len(str(vv)) + vv < num: kk = match_num vv = num k = kk * 3 ans = [] while n - kk >= k: ans.append(vv) n -= kk vvv = 0 uu = 0 u = 0 # print(ans, n) for i, j, k in product(dd, dd, dd): k_len = len(str(k[1])) j_len = len(str(j[1])) # if i[0] + j[0] + k[0] == n: # print(i,j,k, i[1] * 10**(j_len+k_len) + j[1] * 10**k_len + k[1]) if ( i[0] + j[0] + k[0] == n and i[1] * 10 ** (j_len + k_len) + j[1] * 10**k_len + k[1] > vvv ): vvv = i[1] * 10 ** (j_len + k_len) + j[1] * 10**k_len + k[1] uu = i[1] * 10 ** (j_len) + j[1] u = k[1] if i[0] + j[0] == n and i[1] * 10 ** (j_len) + j[1] > vvv: vvv = i[1] * 10 ** (j_len) + j[1] uu = i[1] u = j[1] if i[0] == n and i[1] > vvv: vvv = i[1] uu = i[1] if u == 0: print(uu) else: tmp = "".join(map(str, ans)) if ans else "" print(str(uu) + tmp + str(u)) # print(vv,uu,u)
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s144243693
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
n, m = (int(i) for i in input().split()) a = list(int(i) for i in input().split()) use = [] t = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] for i in range(1, 9): if i in a: use.append([i, t[i]]) use = sorted(use, key=lambda x: x[1]) query = "" kaisuu = n // use[0][1] amari = int(n % use[0][1]) # 答えのベースを作る judge = [] for i in range(kaisuu): query += str(use[0][0]) if amari == 0: judge = [int(query)] # あまりに応じて最後尾を変えるか最初を変えるか else: # 先頭を変えた後のあまりで後ろを変える for j, k in enumerate(use): tmp2 = query amari = int(n % use[0][1]) if int(k[0]) > int(use[0][0]) and int(k[1]) <= amari + int(use[0][1]): tmp2 = str(k[0]) + query[1::] amari -= int(k[1]) amari += int(use[0][1]) if amari == 0: judge.append(int(tmp2)) # 後ろ側をあまりが0になるように調整する if amari > 0: for j, k in enumerate(use): if int(k[1]) == amari + int(use[0][1]): tmp2 = tmp2[:-1] + str(k[0]) judge.append(int(tmp2)) print(max(judge))
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s379492697
Wrong Answer
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
from sys import stdin n, m = [int(x) for x in stdin.readline().rstrip().split()] a = [int(x) for x in stdin.readline().rstrip().split()] if 1 in a: minm = 2 elif 7 in a: minm = 3 elif 4 in a: minm = 4 elif 2 in a: minm = 5 elif 3 in a: minm = 5 elif 5 in a: minm = 5 elif 6 in a: minm = 6 elif 9 in a: minm = 6 elif 8 in a: minm = 7 order = n // minm amari = n % minm output = "" for i in range(order - 1): amari += minm if amari >= 6 and 9 in a: output += "9" amari -= 6 elif amari >= 7 and 8 in a: output += "8" amari -= 7 elif amari >= 3 and 7 in a: output += "7" amari -= 3 elif amari >= 6 and 6 in a: output += "6" amari -= 6 elif amari >= 5 and 5 in a: output += "5" amari -= 5 elif amari >= 4 and 4 in a: output += "4" amari -= 4 elif amari >= 5 and 3 in a: output += "3" amari -= 5 elif amari >= 5 and 2 in a: output += "2" amari -= 5 elif amari >= 2 and 1 in a: output += "1" amari -= 2 amari += minm if amari == 6 and 9 in a: output += "9" amari -= 6 elif amari == 7 and 8 in a: output += "8" amari -= 7 elif amari == 3 and 7 in a: output += "7" amari -= 3 elif amari == 6 and 6 in a: output += "6" amari -= 6 elif amari == 5 and 5 in a: output += "5" amari -= 5 elif amari == 4 and 4 in a: output += "4" amari -= 4 elif amari == 5 and 3 in a: output += "3" amari -= 5 elif amari == 5 and 2 in a: output += "2" amari -= 5 elif amari == 2 and 1 in a: output += "1" amari -= 2 print(output)
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s969336050
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
#解答例 N,M=map(int,input().split()) A=list(map(int,input().split()))#使える数字の種類 weight=[0,2,5,5,4,5,6,3,7,6]#作るのに何本必要か、また0は作れないので0になっている dp=[-1]*(N+1)#とりあえずこれくらい確保しておけばok dp[0]=0#0本では0しか作れない #dp[i]はちょうどi本で作れる最高の数を入れることにする for i in range(N+1):#N本あるから、一本ずつ増やしていって最大N本 if dp[i] == -1:continue for a in A: if i+weight[a]<N+1:#今あるi本にa本を加えてもN本を超えないか dp[i+weight[a]]=max(dp[i+weight[a]],dp[i]*10+a)#今まで作ったi+weight[a]のときのdpの値と、今作ったdp[i]*10+aの値を比べ、大きい方を格納する #なぜdp[i]*10+aになるのかに関しては、右から数字を追加していく場合のみを考えることで、重複せずに全通り試せるから   #もし一通りもなかった場合、-1が格納されたままになるため問題がない print(dp[N])
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s024079609
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
N, M = map(int, input().split()) A = list(map(int, input().split())) def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) L = [2,5,5,4,5,6,3,7,6] l_A = [L[A[i] for i in range(len(A))] c_m = 0 mi = min(l_A) ma = max(l_A) if mi == 5: c_m = 5 elif mi == 6: c_m = 9 else: c_m = L.index(mi) + 1 s = list(set(l_A)).sort() if N % mi == 0: print(str(c_m)*(N//mi)) lest = (N % mi) + mi if lest in l_A: lest_c = l_A[l_A.index(lest)] if mi < lest_c: print(str(lest_c)+str(mi)*((N//mi)-1)) else: print(str(mi)*((N//mi)-1)+str(lest_c))
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s531856504
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
N, M = map(int, input().split()) A = list(map(int, input().split())) li = [[1, 2], [7, 3], [4, 4], [5, 5], [3, 5], [2, 5], [9, 6], [6, 6], [8, 7]] use = [] Q = [0] * 10 counter = 0 for i in li: Flag = False if i[0] in A: Flag = True for j in use: if j[1] == i[1]: Flag = False if Flag: use.append(i) Q[use[0][0]] = int(N // use[0][1]) R = N % use[0][1] while R != 0: if Q[use[counter][0]] == 0 or counter >= M - 1: counter -= 1 else: Q[use[counter][0]] -= 1 R += use[counter][1] counter += 1 Q[use[counter][0]] = int(R // use[counter][1]) R = R % use[counter][1] ans = "" for i in [9, 8, 7, 6, 5, 4, 3, 2, 1]: ans = ans + str(i) * Q[i] print(ans)
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s524866493
Wrong Answer
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
arr = [10, 2, 5, 5, 4, 5, 6, 3, 7, 6] N, M = map(int, input().split()) src = sorted(list(map(int, input().split())), key=lambda x: arr[x]) dim = 0 num = 0 min_num = 0 for i in src: if arr[min_num] > arr[i]: if min_num <= i: min_num = i for i in src: tmp = 1 + (N - arr[i]) // arr[min_num] if dim <= tmp and num < i: dim = tmp num = i s = str(num) cnt = N - arr[num] cnt_dim = 1 while cnt_dim + 1 < dim: s += str(min_num) cnt -= arr[min_num] cnt_dim += 1 for i in src: if cnt == arr[i]: if i <= min_num: s += str(i) break else: s = s[:1] + str(i) + s[1:] break print(s)
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s075987126
Accepted
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
N, M = map(int, input().split()) A = list(map(int, input().split())) d = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} D = {a: d[a] for a in A} m = min(D.values()) E = {} for k, v in D.items(): v -= m if v in E: E[v] = max(E[v], k) else: E[v] = k F = sorted(E.keys(), key=lambda f: (max(0, E[f] - E[0]), f), reverse=True) F.remove(0) K = N // m for k in range(K, 0, -1): B = [E[0]] * k R = N - k * m if not R: print("".join(map(str, sorted(B, reverse=True)))) break def rec(r, i, j): if i < 0: return for f in F[j:]: if r == f: B[i] = E[f] print("".join(map(str, sorted(B, reverse=True)))) exit() elif r > f: B[i], tmp = E[f], B[i] rec(r - f, i - 1, j) B[i] = tmp j += 1 rec(R, k - 1, 0)
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s347977501
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
## ABC068-D ## 途中だけど保存用 N, M = map(int, input().split()) A = list(map(int, input().split())) #cost = dict([(1,2),(2,5),(3,5),(4,4),(5,5),(6,6),(7,3),(8,7),(9,6)]) cost = [(1,2),(7,3),(4,4),(5,5),(3,5),(2,5),(9,6),(6,6),(8,7)] ## priority order ## 使う可能性のある数字だけを取り出す ## (5,3,2),(9,6) は上位数だけで十分 ## 2個の数字で代用できる場合はそちらを用いる: 4 --> 11 B = [] B_cost = [] for i in range(len(cost)): if cost[i][1] in B_cost: continue elif cost[i][1] == 4 and 2 in B_cost: continue elif cost[i][1] == 6 and (2 in B_cost or 3 in B_cost): continue else: B.append((cost[i])) B_cost.append(cost[i][1]) solver = [] n_num = 0 upper_n_num = (N + B[0][1]) // B[0][1] n_lowcost = upper_n_num while True:
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s026602230
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
N, M = list(map(int, input().split())) A = list(map(int, input().split())) #len(A)=M _dict={} num_matches={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} for a in A: _dict[num_matches[a]]=_dict.get(num_matches[a],[]) + [a] print(_dict) memo = [None for _ in range(N+1)] # return memo[N] # Nほんのマッチを使って作れる整数の最大値.(作れなければ0) def max_int_with_match(n): if memo[n]: return memo[n] if n in _dict.keys(): memo[n] = max(max(_dict[n]), max(map(lambda x: max(_dict[x]) + 10 * max_int_with_match(n-x), _dict.keys() ) ) ) return memo[n] if n < min(_dict.keys()): memo[n] = 0 return memo[n] memo[n] = max(map(lambda x: max(_dict[x]) + 10 * max_int_with_match(n-x), _dict.keys())) return memo[n] print(max_int_with_match(N))
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. * * *
s491710907
Runtime Error
p03128
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M
d=[0,2,5,5,4,5,6,3,7,6] N,M=map(int,input().split()) A=list(map(int,input().split())) l=[] for a in A: l.append([a,d[a]]) l.sort(key=lambda x:x[0],reverse=True) l.sort(key=lambda x:x[1]) min_val,min_match=l[0] ans=[] if N%min_match==0: ans.append(int(str(min_val)*(N//min_match))) from itertools import combinations_with_replacement for i in range(1,M): f = False r = 1 while not f: for p in combinations_with_replacement(l[1:],r): v=[] m_sum=0 for val,mat in p: v.append(str(val)) m_sum+=mat if (N-m_sum)%min_match==0: ans.append(int(''.join(sorted(v+ [str(min_val)]*((N-m_sum)//min_match),reverse=True)))) f = (len(ans) == 0) r += 1 print(max(ans))
Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.
[{"input": "20 4\n 3 7 8 4", "output": "777773\n \n\nThe integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks,\nand this is the largest integer that can be formed by 20 matchsticks under the\nconditions.\n\n* * *"}, {"input": "101 9\n 9 8 7 6 5 4 3 2 1", "output": "71111111111111111111111111111111111111111111111111\n \n\nThe output may not fit into a 64-bit integer type.\n\n* * *"}, {"input": "15 3\n 5 4 6", "output": "654"}]
Print the maximum possible positive integer that divides every element of A after the operations. * * *
s725064467
Accepted
p02955
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_{N-1} A_{N}
n, k, *l = map(int, open(0).read().split()) s = sum(l) L = [] for i in range(1, 30000): L += [i, s // i] * (s % i < 1) t = 1 for d in L: a = sorted([m % d for m in l]) t = max(t, d * (sum(a[: -sum(a) // d]) <= k)) print(t)
Statement We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): * Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element. Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
[{"input": "2 3\n 8 20", "output": "7\n \n\n7 will divide every element of A if, for example, we perform the following\noperation:\n\n * Choose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element\nof A.\n\n* * *"}, {"input": "2 10\n 3 5", "output": "8\n \n\nConsider performing the following five operations:\n\n * Choose i = 2, j = 1. A becomes (2, 6).\n * Choose i = 2, j = 1. A becomes (1, 7).\n * Choose i = 2, j = 1. A becomes (0, 8).\n * Choose i = 2, j = 1. A becomes (-1, 9).\n * Choose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We\ncannot reach the situation where 9 or greater integer divides every element of\nA.\n\n* * *"}, {"input": "4 5\n 10 1 2 22", "output": "7\n \n\n* * *"}, {"input": "8 7\n 1 7 5 6 8 2 6 5", "output": "5"}]
Print the maximum possible positive integer that divides every element of A after the operations. * * *
s753322613
Accepted
p02955
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_{N-1} A_{N}
n, k = map(int, input().split()) a = list(map(int, input().split())) sun = sum(a) cd = [] rcd = [] for i in range(1, int(sun**0.5) + 1): if sun % i == 0: cd.append(i) rcd.append(sun // i) rcd.reverse() if cd[-1] == rcd[0]: del cd[-1] gcd = cd + rcd gcd.reverse() count = 0 while True: g = gcd[count] b = list(map(lambda x: x % g, a)) moon = sum(b) // g b.sort() luna = sum(b[: n - moon]) if luna <= k: print(g) break count += 1
Statement We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): * Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element. Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
[{"input": "2 3\n 8 20", "output": "7\n \n\n7 will divide every element of A if, for example, we perform the following\noperation:\n\n * Choose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element\nof A.\n\n* * *"}, {"input": "2 10\n 3 5", "output": "8\n \n\nConsider performing the following five operations:\n\n * Choose i = 2, j = 1. A becomes (2, 6).\n * Choose i = 2, j = 1. A becomes (1, 7).\n * Choose i = 2, j = 1. A becomes (0, 8).\n * Choose i = 2, j = 1. A becomes (-1, 9).\n * Choose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We\ncannot reach the situation where 9 or greater integer divides every element of\nA.\n\n* * *"}, {"input": "4 5\n 10 1 2 22", "output": "7\n \n\n* * *"}, {"input": "8 7\n 1 7 5 6 8 2 6 5", "output": "5"}]
Print the maximum possible positive integer that divides every element of A after the operations. * * *
s820497250
Wrong Answer
p02955
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_{N-1} A_{N}
n, k = list(map(int, input().split(" "))) a = [int(i) for i in input().split(" ")] ave_a = sum(a) / n count = 0 sa = 0 for i in range(n): if a[i] != ave_a and a[i] % ave_a != 0: count += 1 if a[i] % ave_a != 0: sa += ave_a - a[i] if sa == 0 and count <= k: print(ave_a)
Statement We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): * Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element. Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
[{"input": "2 3\n 8 20", "output": "7\n \n\n7 will divide every element of A if, for example, we perform the following\noperation:\n\n * Choose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element\nof A.\n\n* * *"}, {"input": "2 10\n 3 5", "output": "8\n \n\nConsider performing the following five operations:\n\n * Choose i = 2, j = 1. A becomes (2, 6).\n * Choose i = 2, j = 1. A becomes (1, 7).\n * Choose i = 2, j = 1. A becomes (0, 8).\n * Choose i = 2, j = 1. A becomes (-1, 9).\n * Choose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We\ncannot reach the situation where 9 or greater integer divides every element of\nA.\n\n* * *"}, {"input": "4 5\n 10 1 2 22", "output": "7\n \n\n* * *"}, {"input": "8 7\n 1 7 5 6 8 2 6 5", "output": "5"}]
Print the maximum possible positive integer that divides every element of A after the operations. * * *
s399126033
Wrong Answer
p02955
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_{N-1} A_{N}
N, K = list(map(int, input().split())) A = [int(i) for i in input().split()] A_sum = sum(A) def prime_factors(n): i = 2 factors = [] while i * i <= n: if n % i: i += 1 else: n //= i factors.append(i) if n > 1: factors.append(n) return factors factors = prime_factors(A_sum) if min(A) < K: print(A_sum) else: print(max(factors))
Statement We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): * Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element. Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
[{"input": "2 3\n 8 20", "output": "7\n \n\n7 will divide every element of A if, for example, we perform the following\noperation:\n\n * Choose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element\nof A.\n\n* * *"}, {"input": "2 10\n 3 5", "output": "8\n \n\nConsider performing the following five operations:\n\n * Choose i = 2, j = 1. A becomes (2, 6).\n * Choose i = 2, j = 1. A becomes (1, 7).\n * Choose i = 2, j = 1. A becomes (0, 8).\n * Choose i = 2, j = 1. A becomes (-1, 9).\n * Choose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We\ncannot reach the situation where 9 or greater integer divides every element of\nA.\n\n* * *"}, {"input": "4 5\n 10 1 2 22", "output": "7\n \n\n* * *"}, {"input": "8 7\n 1 7 5 6 8 2 6 5", "output": "5"}]
Print the maximum possible positive integer that divides every element of A after the operations. * * *
s733101807
Wrong Answer
p02955
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_{N-1} A_{N}
import heapq as h def partions(M): # Mの約数列 O(n^(0.5+e)) import math d = [] i = 1 while math.sqrt(M) >= i: if M % i == 0: d.append(i) if i**2 != M: d.append(M // i) i = i + 1 d.sort() return d N, K = map(int, input().split()) A = list(map(int, input().split())) s = sum(A) candidate = partions(s) ans = 1 for i in range(0, len(candidate)): X = [A[j] % candidate[i] for j in range(0, N)] test = 0 h.heapify(X) for j in range(0, N - 1): s = h.heappop(X) X = [candidate[i] - X[j] for j in range(0, len(X))] t = h.heappop(X) X = [candidate[i] - X[j] for j in range(0, len(X))] if t > s: test += s h.heappush(X, (N - (t - s)) % candidate[i]) else: test += t h.heappush(X, s - t) if K >= test: ans = candidate[i] print(ans)
Statement We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): * Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element. Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
[{"input": "2 3\n 8 20", "output": "7\n \n\n7 will divide every element of A if, for example, we perform the following\noperation:\n\n * Choose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element\nof A.\n\n* * *"}, {"input": "2 10\n 3 5", "output": "8\n \n\nConsider performing the following five operations:\n\n * Choose i = 2, j = 1. A becomes (2, 6).\n * Choose i = 2, j = 1. A becomes (1, 7).\n * Choose i = 2, j = 1. A becomes (0, 8).\n * Choose i = 2, j = 1. A becomes (-1, 9).\n * Choose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We\ncannot reach the situation where 9 or greater integer divides every element of\nA.\n\n* * *"}, {"input": "4 5\n 10 1 2 22", "output": "7\n \n\n* * *"}, {"input": "8 7\n 1 7 5 6 8 2 6 5", "output": "5"}]
Print the maximum possible positive integer that divides every element of A after the operations. * * *
s851393029
Wrong Answer
p02955
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_{N-1} A_{N}
import sys sys.setrecursionlimit(10**7) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline().strip() INF = 10**18 MOD = 10**9 + 7 debug = True debug = False def dprint(*objects): if debug == True: print(*objects) def prime_factors(n): i = 2 factors = [] while i * i <= n: if n % i: i += 1 else: n //= i factors.append(i) if n > 1: factors.append(n) return factors def main(): N, K = LI() a_list = LI() a_list = sorted(a_list) total = sum(a_list) pfactors = prime_factors(total) from collections import Counter c = Counter(pfactors) dprint(c) factor_list = [] for f, c in c.items(): k_list = list(range(0, c + 1)) factor_list.append([f**k for k in k_list]) dprint(factor_list) ans_list = [] from itertools import product for tup in product(*factor_list): ans = 1 for t in tup: ans *= t ans_list.append(ans) ans_list = sorted(ans_list, reverse=True) dprint(ans_list) def check(ans): ope = 0 diff = 0 for a in a_list: if a % ans == 0: continue na = a // ans near_up = ans * (na + 1) near_down = ans * (na) dup = abs(a - near_up) ddn = abs(a - near_down) dope = min(dup, ddn) if dup <= ddn: diff += dope else: diff -= dope ope += dope dprint(a, dope, diff) ope /= 2 dprint(ans, ope, diff) if ope + abs(diff) % ans <= K: return True else: return False for ans in ans_list: flag = check(ans) dprint(ans, flag) dprint() if flag: print(ans) return main()
Statement We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): * Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element. Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
[{"input": "2 3\n 8 20", "output": "7\n \n\n7 will divide every element of A if, for example, we perform the following\noperation:\n\n * Choose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element\nof A.\n\n* * *"}, {"input": "2 10\n 3 5", "output": "8\n \n\nConsider performing the following five operations:\n\n * Choose i = 2, j = 1. A becomes (2, 6).\n * Choose i = 2, j = 1. A becomes (1, 7).\n * Choose i = 2, j = 1. A becomes (0, 8).\n * Choose i = 2, j = 1. A becomes (-1, 9).\n * Choose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We\ncannot reach the situation where 9 or greater integer divides every element of\nA.\n\n* * *"}, {"input": "4 5\n 10 1 2 22", "output": "7\n \n\n* * *"}, {"input": "8 7\n 1 7 5 6 8 2 6 5", "output": "5"}]
Print the maximum possible positive integer that divides every element of A after the operations. * * *
s296310182
Wrong Answer
p02955
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_{N-1} A_{N}
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n, k = map(int, input().split()) a = [int(i) for i in input().split()] def divisorize(fct): b, e = fct.pop() pre_div = divisorize(fct) if fct else [[]] suf_div = [[(b, k)] for k in range(e + 1)] return [pre + suf for pre in pre_div for suf in suf_div] def factorize(n): fct = [] b, e = 2, 0 while b * b <= n: while n % b == 0: n = n // b e = e + 1 if e > 0: fct.append((b, e)) b, e = b + 1, 0 if n > 1: fct.append((n, 1)) return fct def num(fct): a = 1 for base, exponent in fct: a = a * base**exponent return a c = [] fct = factorize(sum(a)) for div in divisorize(fct): c.append(num(div)) c.sort(reverse=True) ans = 1 from heapq import heapify, heappush, heappop for num in c: chk = 0 cnt = 0 pl = [] mi = [] heapify(pl) heapify(mi) for j in a: m = min(j % num, num - j % num) chk += m if m == j % num: cnt += m heappush(pl, -m) else: cnt -= m heappush(mi, -m) for i in range(abs(cnt) // num): if cnt < 0 and pl != []: p = heappop(pl) chk += p chk += num elif cnt > 0 and mi != []: q = heappop(mi) chk -= q chk -= num if chk <= 2 * k: ans = num break print(ans)
Statement We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): * Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element. Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
[{"input": "2 3\n 8 20", "output": "7\n \n\n7 will divide every element of A if, for example, we perform the following\noperation:\n\n * Choose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element\nof A.\n\n* * *"}, {"input": "2 10\n 3 5", "output": "8\n \n\nConsider performing the following five operations:\n\n * Choose i = 2, j = 1. A becomes (2, 6).\n * Choose i = 2, j = 1. A becomes (1, 7).\n * Choose i = 2, j = 1. A becomes (0, 8).\n * Choose i = 2, j = 1. A becomes (-1, 9).\n * Choose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We\ncannot reach the situation where 9 or greater integer divides every element of\nA.\n\n* * *"}, {"input": "4 5\n 10 1 2 22", "output": "7\n \n\n* * *"}, {"input": "8 7\n 1 7 5 6 8 2 6 5", "output": "5"}]
Print the maximum possible positive integer that divides every element of A after the operations. * * *
s009496137
Wrong Answer
p02955
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_{N-1} A_{N}
# ABC 136 E import math N, K = map(int, input().split()) A = list(map(int, input().split())) S = sum(A) P = [1, S] for k in range(2, math.floor(math.sqrt(S)) + 1): if S % k == 0: P.append(k) P.append(S // k) P = sorted(P)[::-1] for e in P: t = [] u = [] for a in A: if a % e != 0: t.append(a % e) u.append(e - a % e) t = sorted(t) if len(t) == 0: print(e) exit(0) else: p = [f for f in t] for k in range(1, len(t)): p[k] += p[k - 1] m = [e - f for f in t] print(m) for k in range(1, len(t)): m[-k - 1] += m[-k] for k in range(len(t) - 1): if p[k] == m[k + 1] and p[k] <= K: print(e) exit(0)
Statement We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): * Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element. Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
[{"input": "2 3\n 8 20", "output": "7\n \n\n7 will divide every element of A if, for example, we perform the following\noperation:\n\n * Choose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element\nof A.\n\n* * *"}, {"input": "2 10\n 3 5", "output": "8\n \n\nConsider performing the following five operations:\n\n * Choose i = 2, j = 1. A becomes (2, 6).\n * Choose i = 2, j = 1. A becomes (1, 7).\n * Choose i = 2, j = 1. A becomes (0, 8).\n * Choose i = 2, j = 1. A becomes (-1, 9).\n * Choose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We\ncannot reach the situation where 9 or greater integer divides every element of\nA.\n\n* * *"}, {"input": "4 5\n 10 1 2 22", "output": "7\n \n\n* * *"}, {"input": "8 7\n 1 7 5 6 8 2 6 5", "output": "5"}]
Print the maximum possible positive integer that divides every element of A after the operations. * * *
s528615188
Accepted
p02955
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_{N-1} A_{N}
n, k = list(map(int, input().split())) a = list(map(int, input().split())) candidate = set() result = 0 x = 1 while x**2 <= (sum(a) + 1): if sum(a) % x == 0: candidate.add(x) candidate.add(int(sum(a) / x)) x += 1 # print(candidate) for i in candidate: b = [0] * len(a) for j in range(len(a)): b[j] = int(a[j] % i) b.sort() if sum(b[: int(len(b) - sum(b) / i)]) <= k: result = max(result, i) # need=0 # need+=sum(b)/i # if need<=k: print(result)
Statement We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): * Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element. Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
[{"input": "2 3\n 8 20", "output": "7\n \n\n7 will divide every element of A if, for example, we perform the following\noperation:\n\n * Choose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element\nof A.\n\n* * *"}, {"input": "2 10\n 3 5", "output": "8\n \n\nConsider performing the following five operations:\n\n * Choose i = 2, j = 1. A becomes (2, 6).\n * Choose i = 2, j = 1. A becomes (1, 7).\n * Choose i = 2, j = 1. A becomes (0, 8).\n * Choose i = 2, j = 1. A becomes (-1, 9).\n * Choose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We\ncannot reach the situation where 9 or greater integer divides every element of\nA.\n\n* * *"}, {"input": "4 5\n 10 1 2 22", "output": "7\n \n\n* * *"}, {"input": "8 7\n 1 7 5 6 8 2 6 5", "output": "5"}]
Print the maximum possible positive integer that divides every element of A after the operations. * * *
s831991824
Accepted
p02955
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_{N-1} A_{N}
def e_max_gcd(N, K, A): def divisor_list(n): """n の正の約数のリスト""" ret = [] for k in range(1, int(n**0.5) + 1): if n % k == 0: ret.append(k) if k != n // k: ret.append(n // k) ret.sort() return ret ans = 1 # 任意の整数は1の倍数 for c in divisor_list(sum(A)): # sum(A)の約数が解の candidate r = sorted([a % c for a in A]) # rをある位置で左右に分けたとき、「左」には-1、「右」には+1する操作を # 行って全要素をcの倍数にしたい。このとき、「左」の要素の和の分だけ # 操作してよいが、それはKを超えてはならない。 # 最初、すべての要素を「左」に入れる。 # 「左」の要素の関数値A(-1してcの倍数にするための操作回数)は最初sum(r)とし、 # 「右」の要素の関数値B(+1してcの倍数にするための操作回数)は最初0とする。 # ここで「左」の要素eを右から順に「右」に入れていくとすると、1つ入れるごとに # A の値は e だけ減り、B の値は c - e だけ増える。 # よって A-B の値は1つ「右」に入れるごとに c だけ減る。 # ゆえに、「右」に何個の要素を入れるべきかは sum(r)//c からわかる。 if sum(r[: N - sum(r) // c]) <= K: ans = max(ans, c) return ans N, K = [int(i) for i in input().split()] A = [int(i) for i in input().split()] print(e_max_gcd(N, K, A))
Statement We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): * Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element. Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
[{"input": "2 3\n 8 20", "output": "7\n \n\n7 will divide every element of A if, for example, we perform the following\noperation:\n\n * Choose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element\nof A.\n\n* * *"}, {"input": "2 10\n 3 5", "output": "8\n \n\nConsider performing the following five operations:\n\n * Choose i = 2, j = 1. A becomes (2, 6).\n * Choose i = 2, j = 1. A becomes (1, 7).\n * Choose i = 2, j = 1. A becomes (0, 8).\n * Choose i = 2, j = 1. A becomes (-1, 9).\n * Choose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We\ncannot reach the situation where 9 or greater integer divides every element of\nA.\n\n* * *"}, {"input": "4 5\n 10 1 2 22", "output": "7\n \n\n* * *"}, {"input": "8 7\n 1 7 5 6 8 2 6 5", "output": "5"}]
Print the maximum possible positive integer that divides every element of A after the operations. * * *
s336208496
Accepted
p02955
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_{N-1} A_{N}
N, K = list(map(int, input().split())) As = list(map(int, input().split())) rs = [] a = sum(As) for i in range(a): i += 1 if a % i == 0: rs.append(i) rs.append(a // i) if a < i**2: break rs = sorted(rs)[::-1] for r in rs: Bs = sorted([A % r for A in As]) sum1 = 0 sum2 = r * N - sum(Bs) R = None for b in Bs: sum1 += b sum2 -= r - b if abs(sum1 - sum2) % r == 0: if max(sum1, sum2) > K: continue R = r break if R: break print(R)
Statement We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): * Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element. Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
[{"input": "2 3\n 8 20", "output": "7\n \n\n7 will divide every element of A if, for example, we perform the following\noperation:\n\n * Choose i = 2, j = 1. A becomes (7, 21).\n\nWe cannot reach the situation where 8 or greater integer divides every element\nof A.\n\n* * *"}, {"input": "2 10\n 3 5", "output": "8\n \n\nConsider performing the following five operations:\n\n * Choose i = 2, j = 1. A becomes (2, 6).\n * Choose i = 2, j = 1. A becomes (1, 7).\n * Choose i = 2, j = 1. A becomes (0, 8).\n * Choose i = 2, j = 1. A becomes (-1, 9).\n * Choose i = 1, j = 2. A becomes (0, 8).\n\nThen, 0 = 8 \\times 0 and 8 = 8 \\times 1, so 8 divides every element of A. We\ncannot reach the situation where 9 or greater integer divides every element of\nA.\n\n* * *"}, {"input": "4 5\n 10 1 2 22", "output": "7\n \n\n* * *"}, {"input": "8 7\n 1 7 5 6 8 2 6 5", "output": "5"}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s640547018
Accepted
p03647
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 getinputdata(): # 配列初期化 array_result = [] data = input() array_result.append(data.split(" ")) flg = True try: while flg: data = input() array_temp = [] if data != "": array_result.append(data.split(" ")) flg = True else: flg = False finally: return array_result arr_data = getinputdata() # 島数 n = arr_data[0][0] m = int(arr_data[0][1]) arr01 = [] arr02 = [] for i in range(1, 1 + m): if arr_data[i][0] == "1": arr01.append(arr_data[i][1]) if arr_data[i][1] == n: arr02.append(arr_data[i][0]) print("POSSIBLE" if len(list(set(arr01) & set(arr02))) == 1 else "IMPOSSIBLE")
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s661510138
Runtime Error
p03647
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 f(): n,m = map(int,input().split(" ")) s = [] w = [[] for i in range(n+2)] for i in range(m): a,b = map(int,input().split(" ")) if a==1: s.append(b) if b==1: s.append(a) w[a].append(b) w[b].append(a) for i in s: if n in w[i]: print("POSSIBLE") return 0 print("IMPOSSIBLE") return 0 f()
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s905427020
Accepted
p03647
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
# -*- coding: utf-8 -*- N, M = [int(n) for n in input().split()] islands = {n: [] for n in range(1, N + 1)} result = "IMPOSSIBLE" for m in range(M): a, b = [int(n) for n in input().split()] islands[a].append(b) islands[b].append(a) ok_isl = set() search_isl = [1] next_isl = set() loop = True for x in range(2): for i in search_isl: if N in islands[i]: loop = False result = "POSSIBLE" else: next_isl.update(islands[i]) ok_isl = ok_isl.union(search_isl) search_isl = next_isl.difference(ok_isl) if len(search_isl) == 0: break print(result)
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
Print the answer. * * *
s777224849
Wrong Answer
p03217
Input is given from Standard Input in the following format: N D x_1 y_1 : x_N y_N
n, d = [int(i) for i in input().split()] X, Y = zip(*[[int(i) for i in input().split()] for j in range(n)]) ans = int(1e9) for bx in range(d): for by in range(d): S = set() for x, y in zip(X, Y): x %= d x += d if x < bx else 0 y %= d y += d if y < by else 0 dy = 0 try: if x > y: while True: for dx in range(dy + 1): if not (x + dx * d, y + dy * d) in S: S.add((x + dx * d, y + dy * d)) raise () dx = dy for dy in range(dx + 1): if not (x + dx * d, y + dy * d) in S: S.add((x + dx * d, y + dy * d)) raise () dy += 1 else: while True: for ddy in range(dy + 1): if not (x + dy * d, y + ddy * d) in S: S.add((x + dy * d, y + ddy * d)) raise () for dx in range(dy + 1): if not (x + dx * d, y + dy * d) in S: S.add((x + dx * d, y + dy * d)) raise () dy += 1 except: pass X, Y = zip(*tuple(S)) ans = min(ans, max(abs(max(X) - min(X)), (max(Y) - min(Y)))) print(ans)
Statement Niwango-kun, an employee of Dwango Co., Ltd., likes Niconico TV-chan, so he collected a lot of soft toys of her and spread them on the floor. Niwango-kun has N black rare soft toys of Niconico TV-chan and they are spread together with ordinary ones. He wanted these black rare soft toys to be close together, so he decided to rearrange them. In an infinitely large two-dimensional plane, every lattice point has a soft toy on it. The coordinates (x_i,y_i) of N black rare soft toys are given. All soft toys are considered to be points (without a length, area, or volume). He may perform the following operation arbitrarily many times: * Put an axis-aligned square with side length D, rotate the square by 90 degrees with four soft toys on the four corners of the square. More specifically, if the left bottom corner's coordinate is (x, y), rotate four points (x,y) \rightarrow (x+D,y) \rightarrow (x+D,y+D) \rightarrow (x,y+D) \rightarrow (x,y) in this order. Each of the four corners of the square must be on a lattice point. Let's define the _scatteredness_ of an arrangement by the minimum side length of an axis-aligned square enclosing all black rare soft toys. Black rare soft toys on the edges or the vertices of a square are considered to be enclosed by the square. Find the minimum scatteredness after he performs arbitrarily many operations.
[{"input": "3 1\n 0 0\n 1 0\n 2 0", "output": "1\n \n\n* * *"}, {"input": "19 2\n 1 3\n 2 3\n 0 1\n 1 1\n 2 1\n 3 1\n 4 4\n 5 4\n 6 4\n 7 4\n 8 4\n 8 3\n 8 2\n 8 1\n 8 0\n 7 0\n 6 0\n 5 0\n 4 0", "output": "4\n \n\n* * *"}, {"input": "8 3\n 0 0\n 0 3\n 3 0\n 3 3\n 2 2\n 2 5\n 5 2\n 5 5", "output": "4"}]
Print the answer. * * *
s186666252
Wrong Answer
p03217
Input is given from Standard Input in the following format: N D x_1 y_1 : x_N y_N
n, d = map(int, input().split()) m = [[0] * d for i in range(d)] for i in range(n): bnm, jkl = map(int, input().split()) i = bnm % d j = jkl % d m[i][j] += 1 for i in range(d): for j in range(d): if m[i][j] != 0: l = 1 if i <= d - i: p = i p = min(i, abs(d - i)) q = min(j, abs(d - j)) g = 10**5 h = 0 for qqq in range(100): a = (g + h) // 2 c = ((a - p) // d + (a + p) // d + 1) * ( (a - q) // d + (a - q) // d + 1 ) if c > m[i][j]: g = a else: h = a a = h if ((a - p) // d + (a + p) // d + 1) * ( (a - q) // d + (a - q) // d + 1 ) >= m[i][j]: m[i][j] = a else: m[i][j] = g res = m[0][0] for i in range(d): for j in range(d): res = max(res, m[i][j]) print(res)
Statement Niwango-kun, an employee of Dwango Co., Ltd., likes Niconico TV-chan, so he collected a lot of soft toys of her and spread them on the floor. Niwango-kun has N black rare soft toys of Niconico TV-chan and they are spread together with ordinary ones. He wanted these black rare soft toys to be close together, so he decided to rearrange them. In an infinitely large two-dimensional plane, every lattice point has a soft toy on it. The coordinates (x_i,y_i) of N black rare soft toys are given. All soft toys are considered to be points (without a length, area, or volume). He may perform the following operation arbitrarily many times: * Put an axis-aligned square with side length D, rotate the square by 90 degrees with four soft toys on the four corners of the square. More specifically, if the left bottom corner's coordinate is (x, y), rotate four points (x,y) \rightarrow (x+D,y) \rightarrow (x+D,y+D) \rightarrow (x,y+D) \rightarrow (x,y) in this order. Each of the four corners of the square must be on a lattice point. Let's define the _scatteredness_ of an arrangement by the minimum side length of an axis-aligned square enclosing all black rare soft toys. Black rare soft toys on the edges or the vertices of a square are considered to be enclosed by the square. Find the minimum scatteredness after he performs arbitrarily many operations.
[{"input": "3 1\n 0 0\n 1 0\n 2 0", "output": "1\n \n\n* * *"}, {"input": "19 2\n 1 3\n 2 3\n 0 1\n 1 1\n 2 1\n 3 1\n 4 4\n 5 4\n 6 4\n 7 4\n 8 4\n 8 3\n 8 2\n 8 1\n 8 0\n 7 0\n 6 0\n 5 0\n 4 0", "output": "4\n \n\n* * *"}, {"input": "8 3\n 0 0\n 0 3\n 3 0\n 3 3\n 2 2\n 2 5\n 5 2\n 5 5", "output": "4"}]
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7. * * *
s983307996
Wrong Answer
p04028
The input is given from Standard Input in the following format: N s
# dp[i][j][k] := i 文字目まで見て、j 文字できてて、k 文字は余計に打ってて後で消す mod = 10**9 + 7 N = int(input()) if N > 300: exit() S = input() J = len(S) dp = [[0] * (N - J + 2) for _ in range(J + 1)] dp[0][0] = 1 for _ in range(N): dp_new = [[0] * (N - J + 2) for _ in range(J + 1)] for j in range(J + 1): for k in range(N - J + 1): dp_new[j][k] = dp[j][k + 1] if k == 0 and j != 0: dp_new[j][k] += dp[j - 1][k] if k != 0: dp_new[j][k] += dp[j][k - 1] << 1 if j == k == 0: dp_new[j][k] += dp[j][k] dp_new[j][k] %= mod dp = dp_new print(dp[J][0])
Statement Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
[{"input": "3\n 0", "output": "5\n \n\nWe will denote the backspace key by `B`. The following 5 ways to press the\nkeys will cause the editor to display the string `0` in the end: `00B`, `01B`,\n`0B0`, `1B0`, `BB0`. In the last way, nothing will happen when the backspace\nkey is pressed.\n\n* * *"}, {"input": "300\n 1100100", "output": "519054663\n \n\n* * *"}, {"input": "5000\n 01000001011101000100001101101111011001000110010101110010000", "output": "500886057"}]
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7. * * *
s326128023
Runtime Error
p04028
The input is given from Standard Input in the following format: N s
#include<bits/stdc++.h> #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) for(int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; //const int INF = 1e8; using namespace std; const long long M = 1000000007; //x^n mod M typedef long long ull; ull power(ull x, ull n){ ull res = 1; if(n > 0){ res = power(x, n / 2); if(n % 2 == 0) res = (res * res) % M; else res = (((res * res) % M) * x ) %M; } return res; } int main(){ int n; string s; cin >> n >> s; vector<long long> dp(n + 1, 0); dp[0] = 1; rep(i,n){ vector<long long> _dp(n + 1, 0); rep(j,n + 1){ if(j == 0) (_dp[j] += dp[j]) %= M; else (_dp[j - 1] += dp[j]) %= M; (_dp[j + 1] += dp[j] * 2LL) %= M; } dp = _dp; //for(auto j : dp){ for(auto k : j){ cout << k << ' '; } cout << endl; } cout << endl; } cout << dp[s.size()] * power(power(2,s.size()), M - 2) % M << endl; }
Statement Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
[{"input": "3\n 0", "output": "5\n \n\nWe will denote the backspace key by `B`. The following 5 ways to press the\nkeys will cause the editor to display the string `0` in the end: `00B`, `01B`,\n`0B0`, `1B0`, `BB0`. In the last way, nothing will happen when the backspace\nkey is pressed.\n\n* * *"}, {"input": "300\n 1100100", "output": "519054663\n \n\n* * *"}, {"input": "5000\n 01000001011101000100001101101111011001000110010101110010000", "output": "500886057"}]
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7. * * *
s189993940
Wrong Answer
p04028
The input is given from Standard Input in the following format: N s
n = int(input()) s = input() l = len(s) MOD = 10**9 + 7 dp = [[[0] * (j + 1) for j in range(n + 2)] for i in range(n + 1)] dp[0][0][0] = 1 for i in range(n): for j in range(i + 2): if j == 0: dp[i + 1][0][0] = dp[i][1][0] + dp[i][1][1] + dp[i][0][0] dp[i + 1][0][0] %= MOD else: for k in range(j + 1): if j == k: dp[i + 1][j][k] = ( dp[i][j - 1][k - 1] + dp[i][j + 1][k + 1] + dp[i][j + 1][k] ) else: dp[i + 1][j][k] = dp[i][j - 1][k] * 2 + dp[i][j + 1][k] dp[i + 1][j][k] %= MOD ans = dp[n][l][l] print(ans)
Statement Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
[{"input": "3\n 0", "output": "5\n \n\nWe will denote the backspace key by `B`. The following 5 ways to press the\nkeys will cause the editor to display the string `0` in the end: `00B`, `01B`,\n`0B0`, `1B0`, `BB0`. In the last way, nothing will happen when the backspace\nkey is pressed.\n\n* * *"}, {"input": "300\n 1100100", "output": "519054663\n \n\n* * *"}, {"input": "5000\n 01000001011101000100001101101111011001000110010101110010000", "output": "500886057"}]
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7. * * *
s864895483
Wrong Answer
p04028
The input is given from Standard Input in the following format: N s
N = int(input()) s = input() n = len(s) MOD = 10**9 + 7 dp = [[0] * (N + n + 1) for _ in range(2)] dp[0][0] = 1 for i in range(N): src = i % 2 tgt = (i + 1) % 2 dp[tgt][0] = sum(dp[src][0:2]) % MOD dp[tgt][-1] = (2 * dp[src][-2]) % MOD for j in range(1, N + n - 1): dp[tgt][j] = (dp[src][j - 1] * 2 + dp[src][j + 1]) % MOD tmp = pow(2**n, MOD - 2, MOD) res = (dp[N % 2][n] * tmp) % MOD print(res) # print(dp)
Statement Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
[{"input": "3\n 0", "output": "5\n \n\nWe will denote the backspace key by `B`. The following 5 ways to press the\nkeys will cause the editor to display the string `0` in the end: `00B`, `01B`,\n`0B0`, `1B0`, `BB0`. In the last way, nothing will happen when the backspace\nkey is pressed.\n\n* * *"}, {"input": "300\n 1100100", "output": "519054663\n \n\n* * *"}, {"input": "5000\n 01000001011101000100001101101111011001000110010101110010000", "output": "500886057"}]
For each input case, you have to print the height of the student in the class whose both hands are up. If there is no such student, then print 0 for that case.
s276515758
Wrong Answer
p00591
The input will consist of several cases. the first line of each case will be n(0 < n < 100), the number of rows and columns in the class. It will then be followed by a n-by-n matrix, each row of the matrix appearing on a single line. Note that the elements of the matrix may not be necessarily distinct. The input will be terminated by the case n = 0.
while True: n = int(input()) if not n: break print(max(min(map(int, input().split())) for i in range(n)))
Advanced Algorithm Class In the advanced algorithm class, n2 students sit in n rows and n columns. One day, a professor who teaches this subject comes into the class, asks the shortest student in each row to lift up his left hand, and the tallest student in each column to lift up his right hand. What is the height of the student whose both hands are up ? The student will become a target for professor’s questions. Given the size of the class, and the height of the students in the class, you have to print the height of the student who has both his hands up in the class.
[{"input": "1 2 3\n 4 5 6\n 7 8 9\n 3\n 1 2 3\n 7 8 9\n 4 5 6\n 0", "output": "7"}]
Print the output result of the above program for given integer n.
s831628058
Wrong Answer
p02406
An integer n is given in a line.
n = int(input()) x = 1 y = "" z = 1 while True: z = 1 x += 1 if x % 3 == 0: y += " " y += str(x) else: while True: b = int(x % 10 ** (z - 1)) a = int((x - b) / 10**z) c = a % 10**z d = a % 10 ** (z - 1) if a == 3 or b == 3 or c == 3 or d == 3: y += " " y += str(x) break z += 1 if a < 3: break if x >= n: break print(y)
Structured Programming In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
[{"input": "", "output": "6 9 12 13 15 18 21 23 24 27 30\n \n\nPut a single space character before each element."}]
Print the output result of the above program for given integer n.
s497226375
Accepted
p02406
An integer n is given in a line.
N = str(input()) S = "" for i in range(1, int(N) + 1): m = str(i) if i % 3 == 0 or "3" in m: S = S + " " + str(i) print(S)
Structured Programming In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
[{"input": "", "output": "6 9 12 13 15 18 21 23 24 27 30\n \n\nPut a single space character before each element."}]