output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the number of times the operation will be performed. * * *
s622709730
Accepted
p03649
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
import sys # sys.stdin = open('e1.in') def read_int_list(): return list(map(int, input().split())) def read_int(): return int(input()) def read_str_list(): return input().split() def read_str(): return input() def ceil_frac(a, b): return (a + b - 1) // b def solve(): n = read_int() a = read_int_list() s = sum(a) res = 0 x = s - n * n if x > 0: res += x for j in range(n): a[j] += x l = 0 r = 10**20 while r - l > 1: m = (l + r) // 2 decrements = 0 for j in range(n): if a[j] >= m: decrements += ceil_frac(a[j] - m, n + 1) possible = decrements <= x if possible: r = m else: l = m t = 0 for j in range(n): if a[j] >= r: u = ceil_frac(a[j] - r, n + 1) a[j] -= u * (n + 1) t += u for _ in range(x - t): j0 = 0 for j in range(n): if a[j] > a[j0]: j0 = j a[j0] -= n + 1 while max(a) >= n: for j in range(n): a[j] += 1 j0 = 0 for j in range(n): if a[j] > a[j0]: j0 = j a[j0] -= n + 1 res += 1 return res def main(): res = solve() print(res) if __name__ == "__main__": main()
Statement We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.) * Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1. It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given the sequence a_i. Find the number of times we will perform the above operation.
[{"input": "4\n 3 3 3 3", "output": "0\n \n\n* * *"}, {"input": "3\n 1 0 3", "output": "1\n \n\n* * *"}, {"input": "2\n 2 2", "output": "2\n \n\n* * *"}, {"input": "7\n 27 0 0 0 0 0 0", "output": "3\n \n\n* * *"}, {"input": "10\n 1000 193 256 777 0 1 1192 1234567891011 48 425", "output": "1234567894848"}]
Print the number of times the operation will be performed. * * *
s822510222
Wrong Answer
p03649
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
import math N = int(input()) a = list(map(int, input().split())) l = -1 r = sum(a) s = r flag = True for x in a: if x < N: continue else: flag = False break if flag: print(0) exit(0) while l + 1 < r: mid = (l + r) // 2 if (s - mid) / N > N - 1: l = mid else: tmp = 0 for x in a: tmp += math.ceil(((x + mid - N + 1) / (N + 1))) if tmp <= mid: r = mid else: l = mid print(r)
Statement We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.) * Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1. It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given the sequence a_i. Find the number of times we will perform the above operation.
[{"input": "4\n 3 3 3 3", "output": "0\n \n\n* * *"}, {"input": "3\n 1 0 3", "output": "1\n \n\n* * *"}, {"input": "2\n 2 2", "output": "2\n \n\n* * *"}, {"input": "7\n 27 0 0 0 0 0 0", "output": "3\n \n\n* * *"}, {"input": "10\n 1000 193 256 777 0 1 1192 1234567891011 48 425", "output": "1234567894848"}]
Print the number of times the operation will be performed. * * *
s440731958
Accepted
p03649
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
n = int(input()) + 1 a = list(map(int, input().split())) d, A, q = [0] * n, 0, 0 for i in range(n - 1): q += (a[i] + 1) // n d[(a[i] + 1) % n] += 1 A = q * n for r in range(1, n): q += d[n - r] - 1 A = min(A, max(q, 0) * n + r) print(A)
Statement We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.) * Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1. It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given the sequence a_i. Find the number of times we will perform the above operation.
[{"input": "4\n 3 3 3 3", "output": "0\n \n\n* * *"}, {"input": "3\n 1 0 3", "output": "1\n \n\n* * *"}, {"input": "2\n 2 2", "output": "2\n \n\n* * *"}, {"input": "7\n 27 0 0 0 0 0 0", "output": "3\n \n\n* * *"}, {"input": "10\n 1000 193 256 777 0 1 1192 1234567891011 48 425", "output": "1234567894848"}]
Print the number of times the operation will be performed. * * *
s223220099
Wrong Answer
p03649
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
#!/usr/bin/env pypy3 # -*- coding: UTF-8 -*- import sys import re import math import itertools import collections import bisect # sys.stdin=file('input.txt') # sys.stdout=file('output.txt','w') # 10**9+7 mod = 1000000007 # mod=1777777777 pi = 3.1415926535897932 IS = float("inf") xy = [(1, 0), (-1, 0), (0, 1), (0, -1)] bs = [(-1, -1), (-1, 1), (1, 1), (1, -1)] def niten(a, b): return ( abs(a - b) if a >= 0 and b >= 0 else a + abs(b) if a >= 0 else abs(a) + b if b >= 0 else abs(abs(a) - abs(b)) ) def fib(n): return [ (seq.append(seq[i - 2] + seq[i - 1]), seq[i - 2])[1] for seq in [[0, 1]] for i in range(2, n) ] def gcd(a, b): return a if b == 0 else gcd(b, a % b) def lcm(a, b): return a * b / gcd(a, b) def eucl(x1, y1, x2, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 def choco(xa, ya, xb, yb, xc, yc, xd, yd): return 1 if abs((yb - ya) * (yd - yc) + (xb - xa) * (xd - xc)) < 1.0e-10 else 0 def pscl(num, l=[1]): for i in range(num): l = map(lambda x, y: x + y, [0] + l, l + [0]) return l n = int(input()) # n,k=map(int,input().split()) l = [int(i) for i in input().split()] # ans=chk=0 if n % 2 == 0: tmp = (1 + n) * (n // 2) else: tmp = (1 + n) * (n // 2) + n // 2 + 1 print(sum(l) - tmp)
Statement We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.) * Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1. It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given the sequence a_i. Find the number of times we will perform the above operation.
[{"input": "4\n 3 3 3 3", "output": "0\n \n\n* * *"}, {"input": "3\n 1 0 3", "output": "1\n \n\n* * *"}, {"input": "2\n 2 2", "output": "2\n \n\n* * *"}, {"input": "7\n 27 0 0 0 0 0 0", "output": "3\n \n\n* * *"}, {"input": "10\n 1000 193 256 777 0 1 1192 1234567891011 48 425", "output": "1234567894848"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s062935381
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
s, h, c, d = [[0 for i in range(13)] for j in range(4)] n = int(input()) for i in range(n): m, num = [i for i in input().split()] if m == "S": s[int(num) - 1] += 1 if m == "H": h[int(num) - 1] += 1 if m == "C": c[int(num) - 1] += 1 if m == "D": d[int(num) - 1] += 1 for i in range(13): x1 = s[i] if x1 == 0: print("S", i + 1) for i in range(13): x2 = h[i] if x2 == 0: print("H", i + 1) for i in range(13): x3 = c[i] if x3 == 0: print("C", i + 1) for i in range(13): x4 = d[i] if x4 == 0: print("D", i + 1)
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s785115937
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
def Input(egara, rank): if egara == "S": S[rank] = True if egara == "H": H[rank] = True if egara == "C": C[rank] = True if egara == "D": D[rank] = True def Output(): for egara in ["S", "H", "C", "D"]: if egara == "S": for rank in range(13): if S[rank] == False: print("S " + str(rank + 1)) if egara == "H": for rank in range(13): if H[rank] == False: print("H " + str(rank + 1)) if egara == "C": for rank in range(13): if C[rank] == False: print("C " + str(rank + 1)) if egara == "D": for rank in range(13): if D[rank] == False: print("D " + str(rank + 1)) n = int(input()) S = 13 * [False] H = 13 * [False] C = 13 * [False] D = 13 * [False] for idx in range(n): Card = input().split() EGARA = Card[0] RANK = int(Card[1]) - 1 Input(EGARA, RANK) Output()
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s504293947
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
# -*- coding:utf-8 -*- n = int(input()) a = [""] * n b = [0] * n for i in range(n): a[i], b[i] = input().split() array_S = [] for i in range(14): count = 0 for j in range(n): if i == int(b[j]): if a[j] == "S": break count += 1 if count == n: array_S.append(i) array_H = [] for i in range(14): count = 0 for j in range(n): if i == int(b[j]): if a[j] == "H": break count += 1 if count == n: array_H.append(i) array_C = [] for i in range(14): count = 0 for j in range(n): if i == int(b[j]): if a[j] == "C": break count += 1 if count == n: array_C.append(i) array_D = [] for i in range(14): count = 0 for j in range(n): if i == int(b[j]): if a[j] == "D": break count += 1 if count == n: array_D.append(i) for i in range(1, len(array_S)): print("S", array_S[i], sep=" ") for i in range(1, len(array_H)): print("H", array_H[i], sep=" ") for i in range(1, len(array_C)): print("C", array_C[i], sep=" ") for i in range(1, len(array_D)): print("D", array_D[i], sep=" ")
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s912115435
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
line = int(input()) s_set = [x for x in range(1, 14)] h_set = s_set[:] c_set = s_set[:] d_set = s_set[:] taro_list = [] for i in range(line): taro_list.append(input()) for card in taro_list: suite = card.split(" ")[0] num = int(card.split(" ")[1]) if suite == "S": s_set.remove(num) if suite == "H": h_set.remove(num) if suite == "C": c_set.remove(num) if suite == "D": d_set.remove(num) for e in s_set: print("S " + str(e)) for e in h_set: print("H " + str(e)) for e in c_set: print("C " + str(e)) for e in d_set: print("D " + str(e))
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s775397655
Wrong Answer
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
# -*- coding:utf-8 -*- class Cards: trump = [ False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, ] def HaveCards(self, num): self.trump[num] = True def TransCards(self, s, num): if s == "H": num += 12 elif s == "C": num += 25 elif s == "D": num += 38 return num def CheckCards(self, num): if num <= 12: return "S", num + 1 elif num >= 13 and num <= 25: return "H", num - 12 elif num >= 26 and num <= 38: return "C", num - 25 elif num >= 39 and num <= 51: return "D", num - 38 n = int(input()) ob = Cards() for i in range(n): s, str_num = input().split() number = int(str_num) Num = ob.TransCards(s, number - 1) ob.HaveCards(Num) for i in range(len(Cards.trump)): if Cards.trump[i] == False: Str, Num = ob.CheckCards(i) print(Str, Num)
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s241256461
Wrong Answer
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
{ "source": [ 'd = {"S":[1,2,3,4,5,6,7,8,9,10,11,12,13],\n', ' "H":[1,2,3,4,5,6,7,8,9,10,11,12,13],\n', ' "D":[1,2,3,4,5,6,7,8,9,10,11,12,13],\n', ' "C":[1,2,3,4,5,6,7,8,9,10,11,12,13]}\n', "n = int(input())\n", "for i in range(n):\n", " N, M = map(str,input().split())\n", ' d[N][int(M)-1] ="None"\n', 'print("Answer")\n', "for j in range(len(d)):\n", " if j==1:\n", ' list_d = d["S"]\n', ' c = "S"\n', " elif j == 2:\n", ' list_d = d["H"]\n', ' c = "H"\n', " elif j == 3:\n", ' list_d = d["C"]\n', ' c = "C"\n', " else:\n", ' list_d = d["D"]\n', ' c = "D"\n', " for i in range(len(list_d)):\n", ' if(list_d[i] != "None"):\n', " print(c , list_d[i])", ] }
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s833085379
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
n = int(input()) sList = [0] * 13 hList = [0] * 13 cList = [0] * 13 dList = [0] * 13 for i in range(n): pat, num = input().split() num = int(num) if pat == "S": sList[num - 1] = 1 elif pat == "H": hList[num - 1] = 1 elif pat == "C": cList[num - 1] = 1 elif pat == "D": dList[num - 1] = 1 for i in range(13): if sList[i] == 0: print("S %d" % (i + 1)) for i in range(13): if hList[i] == 0: print("H %d" % (i + 1)) for i in range(13): if cList[i] == 0: print("C %d" % (i + 1)) for i in range(13): if dList[i] == 0: print("D %d" % (i + 1))
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s280287468
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
c = int(input()) d = {} e = {} for i in range(c): k, v = input().split() d.setdefault(k, []).append(int(v)) for k, v in d.items(): for i in range(1, 14): if not i in v: e.setdefault(k, []).append(int(i)) if e: for k in ["S", "H", "C", "D"]: for i in e[k]: print("{} {}".format(k, i))
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s290152959
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
n = int(input()) cards = ["{0} {1}".format(m, r) for m in ["S", "H", "C", "D"] for r in range(1, 14)] [cards.remove(input()) for i in range(n)] [print(c) for c in cards]
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s084897153
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
num = int(input()) trump = [] data = [] for x in range(0, num): trump = input().split() if trump[0][0] == "S": data.append(int(trump[1])) elif trump[0][0] == "H": data.append(int(trump[1]) + 13) elif trump[0][0] == "C": data.append(int(trump[1]) + 26) else: data.append(int(trump[1]) + 39) for x in range(1, 53): if x in data: pass else: if x < 14: print("S", x) elif x < 27: print("H", x - 13) elif x < 40: print("C", x - 26) else: print("D", x - 39)
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s084923304
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
if __name__ == "__main__": # ??????????????\??? my_cards = [] # ????????¶?????\??????????????????????????§ card_num = int(input()) for i in range(card_num): data = [x for x in input().split(" ")] suit = data[0] rank = int(data[1]) my_cards.append((suit, rank)) full_cards = [] # 52?????¨????????£?????????????????? for r in range(1, 13 + 1): full_cards.append(("S", r)) full_cards.append(("H", r)) full_cards.append(("D", r)) full_cards.append(("C", r)) # ??????????????¨???????¶??????????????¢???????????????°?????????????????? missing_cards = set(my_cards) ^ set(full_cards) missing_spades = [x for x in missing_cards if x[0] == "S"] missing_hearts = [x for x in missing_cards if x[0] == "H"] missing_clubs = [x for x in missing_cards if x[0] == "C"] missing_diamonds = [x for x in missing_cards if x[0] == "D"] missing_spades.sort(key=lambda x: x[1]) missing_hearts.sort(key=lambda x: x[1]) missing_clubs.sort(key=lambda x: x[1]) missing_diamonds.sort(key=lambda x: x[1]) # ????¶???????????????¨??? for s, r in missing_spades: print("{0} {1}".format(s, r)) for s, r in missing_hearts: print("{0} {1}".format(s, r)) for s, r in missing_clubs: print("{0} {1}".format(s, r)) for s, r in missing_diamonds: print("{0} {1}".format(s, r))
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s761786383
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
def create_card_set(): card_types = ["S", "H", "C", "D"] cart_nums = [i + 1 for i in range(13)] card_set = set() for ct in card_types: for cn in cart_nums: card_set = card_set | {(ct, cn)} return card_set def read_card(): n = int(input()) init_card_set = set() for i in range(n): ct, cn_s = tuple(input().split()) cn = int(cn_s) init_card_set = init_card_set | {(ct, cn)} return init_card_set def sort_card(left_card): # card typeをバケットソート spade_ls = [] heart_ls = [] club_ls = [] diamond_ls = [] for card in left_card: ct = card[0] if ct == "S": spade_ls.append(card) elif ct == "H": heart_ls.append(card) elif ct == "C": club_ls.append(card) elif ct == "D": diamond_ls.append(card) # カード毎の数字を昇順ソート spade_ls = sorted(spade_ls, key=lambda x: x[1]) heart_ls = sorted(heart_ls, key=lambda x: x[1]) club_ls = sorted(club_ls, key=lambda x: x[1]) diamond_ls = sorted(diamond_ls, key=lambda x: x[1]) return spade_ls + heart_ls + club_ls + diamond_ls def find_miss_card(): init_card_set = read_card() all_card = create_card_set() left_card = all_card - init_card_set result = sort_card(left_card) for ct, cn in result: print(f"{ct} {cn}") find_miss_card()
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s550750792
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
n = int(input()) s_card = [] h_card = [] c_card = [] d_card = [] for _ in range(n): card = str(input()) if "S" in card: s_card.append(card) elif "H" in card: h_card.append(card) elif "C" in card: c_card.append(card) elif "D" in card: d_card.append(card) for s in range(1, 14): S = "S " + str(s) if (S in s_card) == False: print(S) for h in range(1, 14): H = "H " + str(h) if (H in h_card) == False: print(H) for c in range(1, 14): C = "C " + str(c) if (C in c_card) == False: print(C) for d in range(1, 14): D = "D " + str(d) if (D in d_card) == False: print(D)
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s399384355
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
check_list_S = [0] * 13 check_list_H = [0] * 13 check_list_C = [0] * 13 check_list_D = [0] * 13 input_number = int(input()) for i in range(input_number): input_data = list(input().split()) check_mark = str(input_data[0]) check_number = int(input_data[1]) if check_mark == "S": check_list_S[check_number - 1] += 1 elif check_mark == "H": check_list_H[check_number - 1] += 1 elif check_mark == "C": check_list_C[check_number - 1] += 1 elif check_mark == "D": check_list_D[check_number - 1] += 1 for i in range(13): if check_list_S[i] == 0: print(f"S {i+1}") for i in range(13): if check_list_H[i] == 0: print(f"H {i+1}") for i in range(13): if check_list_C[i] == 0: print(f"C {i+1}") for i in range(13): if check_list_D[i] == 0: print(f"D {i+1}")
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s152281847
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
n = int(input()) count = 0 lst = [] while count < n: value = input().split() for i in value: if i.isdecimal(): lst.append(int(i)) continue lst.append(i) count += 1 S_lst = [] H_lst = [] C_lst = [] D_lst = [] for s in range(2 * n): if lst[s] == "S": S_lst.append(lst[s]) S_lst.append(lst[s + 1]) for h in range(2 * n): if lst[h] == "H": H_lst.append(lst[h]) H_lst.append(lst[h + 1]) for c in range(2 * n): if lst[c] == "C": C_lst.append(lst[c]) C_lst.append(lst[c + 1]) for d in range(2 * n): if lst[d] == "D": D_lst.append(lst[d]) D_lst.append(lst[d + 1]) if 1 not in S_lst: print("S", 1) if 2 not in S_lst: print("S", 2) if 3 not in S_lst: print("S", 3) if 4 not in S_lst: print("S", 4) if 5 not in S_lst: print("S", 5) if 6 not in S_lst: print("S", 6) if 7 not in S_lst: print("S", 7) if 8 not in S_lst: print("S", 8) if 9 not in S_lst: print("S", 9) if 10 not in S_lst: print("S", 10) if 11 not in S_lst: print("S", 11) if 12 not in S_lst: print("S", 12) if 13 not in S_lst: print("S", 13) if 1 not in H_lst: print("H", 1) if 2 not in H_lst: print("H", 2) if 3 not in H_lst: print("H", 3) if 4 not in H_lst: print("H", 4) if 5 not in H_lst: print("H", 5) if 6 not in H_lst: print("H", 6) if 7 not in H_lst: print("H", 7) if 8 not in H_lst: print("H", 8) if 9 not in H_lst: print("H", 9) if 10 not in H_lst: print("H", 10) if 11 not in H_lst: print("H", 11) if 12 not in H_lst: print("H", 12) if 13 not in H_lst: print("H", 13) if 1 not in C_lst: print("C", 1) if 2 not in C_lst: print("C", 2) if 3 not in C_lst: print("C", 3) if 4 not in C_lst: print("C", 4) if 5 not in C_lst: print("C", 5) if 6 not in C_lst: print("C", 6) if 7 not in C_lst: print("C", 7) if 8 not in C_lst: print("C", 8) if 9 not in C_lst: print("C", 9) if 10 not in C_lst: print("C", 10) if 11 not in C_lst: print("C", 11) if 12 not in C_lst: print("C", 12) if 13 not in C_lst: print("C", 13) if 1 not in D_lst: print("D", 1) if 2 not in D_lst: print("D", 2) if 3 not in D_lst: print("D", 3) if 4 not in D_lst: print("D", 4) if 5 not in D_lst: print("D", 5) if 6 not in D_lst: print("D", 6) if 7 not in D_lst: print("D", 7) if 8 not in D_lst: print("D", 8) if 9 not in D_lst: print("D", 9) if 10 not in D_lst: print("D", 10) if 11 not in D_lst: print("D", 11) if 12 not in D_lst: print("D", 12) if 13 not in D_lst: print("D", 13)
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s335704021
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
# 11-Array-Finding_Missing_Cards.py # ????¶??????????????????????????????? # ???????????±?????¨?????????????????????????????????????????¨????????¨?????????52?????????????????????????????? n ???????????????????????????????????????????????? # ???????????? n ????????????????????\?????¨??????????¶??????????????????????????????????????????°????????????????????????????????? # ???????????????????????£?????????????????????????????§??????????????????52?????????????????§?????? # 52??????????????????????????????????????????????????????????????????????????????????????????????????????????????? # ???????????????13?????????????????????????????? # Input # ?????????????????????????????£??????????????????????????° n (n ??? 52)???????????????????????? # ?¶??????? n ???????????????????????????????????????????????????????????? # ??????????????????????????§???????????????????????¨??´??°??§?????? # ????????????????????????????????¨?????????????????????'S'???????????????'H'???????????????'C'???????????????'D'??§??¨????????????????????? # ??´??°??????????????????????????????(1 ??? 13)?????¨?????????????????? # Output # ?¶??????????????????????????????????1?????????????????????????????? # ?????????????????\?????¨????§?????????????????????§???????????????????????¨??´??°??§?????? # ???????????????????????????????????\????????¨????????¨???????????? # ????????????????????????????????????????????????????????????????????§??????????????????????????? # ?????????????????´??????????????????????°???????????????????????????? # Sample Input # 47 # S 10 # S 11 # S 12 # S 13 # H 1 # H 2 # S 6 # S 7 # S 8 # S 9 # H 6 # H 8 # H 9 # H 10 # H 11 # H 4 # H 5 # S 2 # S 3 # S 4 # S 5 # H 12 # H 13 # C 1 # C 2 # D 1 # D 2 # D 3 # D 4 # D 5 # D 6 # D 7 # C 3 # C 4 # C 5 # C 6 # C 7 # C 8 # C 9 # C 10 # C 11 # C 13 # D 9 # D 10 # D 11 # D 12 # D 13 # Sample Output # S 1 # H 3 # H 7 # C 12 # D 8 pair = [] no_cards = [] hand = int(input()) for i in range(hand): pair.append(input().split()) # ????????§????¶?????????????????????????????????????????????????????????? for i in ["S", "H", "C", "D"]: for j in range(13): if [i, str(j + 1)] not in pair: no_cards.append([i, str(j + 1)]) for i in range(len(no_cards)): print("{0} {1}".format(no_cards[i][0], no_cards[i][1]))
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s894500183
Wrong Answer
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
n = int(input()) list = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"] S_list = list.copy() H_list = list.copy() C_list = list.copy() D_list = list.copy() # print(S_list) for i in range(n): a = input() b = a.split(" ") print(b[1]) if b[0] == "S": S_list.remove("%s" % (b[1])) elif b[0] == "H": H_list.remove("%s" % (b[1])) elif b[0] == "C": C_list.remove("%s" % (b[1])) elif b[0] == "D": D_list.remove("%s" % (b[1])) for i in S_list: print("S " + i) for e in H_list: print("H " + e) for f in C_list: print("C " + f) for g in D_list: print("D " + g)
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s982976867
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
sym = ["S", "H", "C", "D"] rnk = range(1, 14) crds = [] for i in sym: for j in rnk: crds.append([i, j]) n = int(input()) for i in range(n): wrds = input().split() wrds[1] = int(wrds[1]) crds.remove(wrds) for i in crds: print(i[0], i[1])
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s243509995
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
a = int(input()) b = [] for n in range(a): aa = input() b.append(aa) head = ["S", "H", "C", "D"] body = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] card = [] for i in head: for j in body: k = i + " " + str(j) if k not in b: card.append(k) for m in card: print(m)
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s121371623
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
n = int(input()) inp = [] for i in range(n): inp.append(input().split()) cllist = list(range(1, 53)) for i in inp: cl, rank = i[0], int(i[1]) if cl == "S": cllist.remove(rank) elif cl == "H": cllist.remove(rank + 13) elif cl == "C": cllist.remove(rank + 26) elif cl == "D": cllist.remove(rank + 39) for i in cllist: if 0 < i and i < 14: print(f"S {i}") elif 13 < i and i < 27: print(f"H {i-13}") elif 26 < i and i < 40: print(f"C {i-26}") elif 39 < i: print(f"D {i-39}")
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s071653282
Wrong Answer
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
S = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] H = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] C = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] D = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] for i in range(int(input())): a,b = input().split() b = int(b) if a == 'S': S[b] = 1 elif a == 'H' : H[b] = 1 elif a == 'C': C[b] = 1 elif a == 'D': D[b] = 1 for k in range(1,13): if not S[k] : print('S',k) for k in range(1,13): if not H[k] : print('H',k) for k in range(1,13): if not C[k] : print('C',k) for k in range(1,13): if not D[k] : print('D',k)
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s146993363
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
m = int(input()) deck = [(suit, num) for suit in ["S", "H", "C", "D"] for num in range(1, 14)] for _ in range(m): s, n = input().split() if (s, int(n)) in deck: deck.remove((s, int(n))) for item in deck: print(item[0], str(item[1]))
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s425933357
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
i = input l = {i() for _ in [0] * int(i())} for j in [f"{a} {b}" for a in "SHCD" for b in range(1, 14) if f"{a} {b}" not in l]: print(j)
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s633768537
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
number_of_cards = int(input()) suits_of_cards = [input().split(" ") for i in range(number_of_cards)] spade = [] heart = [] club = [] diamond = [] for j in range(0, number_of_cards): suits_of_cards[j][1] = int(suits_of_cards[j][1]) for k in suits_of_cards: if "S" in k: spade.append(k) elif "H" in k: heart.append(k) elif "C" in k: club.append(k) else: diamond.append(k) for l in range(1, 14): if ["S", l] not in spade: print("S", l) for l2 in range(1, 14): if ["H", l2] not in heart: print("H", l2) for l3 in range(1, 14): if ["C", l3] not in club: print("C", l3) for l4 in range(1, 14): if ["D", l4] not in diamond: print("D", l4)
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s277267795
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
x = int(input()) data = [] data_dict = {} data_dict["S"] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] data_dict["H"] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] data_dict["C"] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] data_dict["D"] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] for i in range(x): a, b = input().split() for i in data_dict[a]: if i == int(b): data_dict[a].remove(i) for n in data_dict["S"]: print("S", n) for m in data_dict["H"]: print("H", m) for l in data_dict["C"]: print("C", l) for k in data_dict["D"]: print("D", k)
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s835038368
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
x = int(input()) list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] list2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] list3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] list4 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] for i in range(x): a, b = map(str, input().split()) b = int(b) if a == "S": list1.remove(b) if a == "H": list2.remove(b) if a == "C": list3.remove(b) if a == "D": list4.remove(b) for j in range(len(list1)): print("S", list1[j]) for j in range(len(list2)): print("H", list2[j]) for j in range(len(list3)): print("C", list3[j]) for j in range(len(list4)): print("D", list4[j])
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s464426713
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
n = int(input()) cnt = 0 ml = ["S", "H", "C", "D"] s = [[i + 1 for i in range(13)] for i in range(4)] while cnt < n: M, N = list(input().split()) N = int(N) if M == ml[0]: s[0][N - 1] = False elif M == ml[1]: s[1][N - 1] = False elif M == ml[2]: s[2][N - 1] = False elif M == ml[3]: s[3][N - 1] = False cnt += 1 for i in range(len(ml)): for j in range(len(s[i])): if s[i][j] != False: print("{} {}".format(ml[i], s[i][j]))
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s199448304
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
card_dict = {"S": [], "H": [], "C": [], "D": []} s_key = ["S", "H", "C", "D"] number = input() for i in range(int(number)): card = input() card = card.split() s, n = card card_dict[s].append(int(n)) else: ori = set(list(range(1, 14))) for key in s_key: c = set(card_dict[key]) d = list(ori - c) d.sort() for i in d: print("{} {}".format(key, i))
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: * Print cards of spades, hearts, clubs and diamonds in this order. * If the suits are equal, print cards with lower ranks first.
s410630014
Accepted
p02408
In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
inCount = int(input()) cards = [input() for i in range(inCount)] for mark in ["S", "H", "C", "D"]: for number in range(1, 14): checkMarkNumber = mark + " " + str(number) if not (checkMarkNumber in cards): print(checkMarkNumber)
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
[{"input": "S 10\n S 11\n S 12\n S 13\n H 1\n H 2\n S 6\n S 7\n S 8\n S 9\n H 6\n H 8\n H 9\n H 10\n H 11\n H 4\n H 5\n S 2\n S 3\n S 4\n S 5\n H 12\n H 13\n C 1\n C 2\n D 1\n D 2\n D 3\n D 4\n D 5\n D 6\n D 7\n C 3\n C 4\n C 5\n C 6\n C 7\n C 8\n C 9\n C 10\n C 11\n C 13\n D 9\n D 10\n D 11\n D 12\n D 13", "output": "S 1\n H 3\n H 7\n C 12\n D 8"}]
Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K. * * *
s328480599
Wrong Answer
p03560
Input is given from Standard Input in the following format: K
a = int(input()) while a % 2 == 0: a //= 2 while a % 5 == 0: a //= 5 s = 0 while a > 0: s += a % 10 a //= 10 print(s)
Statement Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.
[{"input": "6", "output": "3\n \n\n12=6\u00d72 yields the smallest sum.\n\n* * *"}, {"input": "41", "output": "5\n \n\n11111=41\u00d7271 yields the smallest sum.\n\n* * *"}, {"input": "79992", "output": "36"}]
Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K. * * *
s144580693
Accepted
p03560
Input is given from Standard Input in the following format: K
#!/usr/bin/python3 # -*- coding: utf-8 -*- from queue import * class Edge(object): def __init__(self, dst, len_): self.dst = dst self.len = len_ MAX_K = int(1e5 + 5) INF = int(1e9) K = 0 dis = [INF for i in range(0, MAX_K)] vis = [False for i in range(0, MAX_K)] edge = [[] for i in range(0, MAX_K)] q = PriorityQueue() def add(s, t, d): edge[s].append(Edge(t, d)) def build(): for i in range(1, K): add(i, i * 10 % K, 0) add(i, (i + 1) % K, 1) def dij(s): dis[s] = 0 q.put((0, s)) while not q.empty(): x = q.get()[1] if vis[x]: continue vis[x] = True for e in edge[x]: if dis[e.dst] > dis[x] + e.len: dis[e.dst] = dis[x] + e.len q.put((dis[e.dst], e.dst)) if __name__ == "__main__": K = int(input()) build() dij(1) print(dis[0] + 1)
Statement Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.
[{"input": "6", "output": "3\n \n\n12=6\u00d72 yields the smallest sum.\n\n* * *"}, {"input": "41", "output": "5\n \n\n11111=41\u00d7271 yields the smallest sum.\n\n* * *"}, {"input": "79992", "output": "36"}]
Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K. * * *
s318898376
Accepted
p03560
Input is given from Standard Input in the following format: K
class Dijkstra: """ダイクストラ法 重み付きグラフにおける単一始点最短路アルゴリズム * 使用条件 - 負のコストがないこと - 有向グラフ、無向グラフともにOK * 計算量はO(E*log(V)) * ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい """ class Edge: """重み付き有向辺""" def __init__(self, _to, _cost): self.to = _to self.cost = _cost def __init__(self, V): """重み付き有向辺 無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい Args: V(int): 頂点の数 """ self.G = [[] for i in range(V)] # 隣接リストG[u][i] := 頂点uのi個目の隣接辺 self._E = 0 # 辺の数 self._V = V # 頂点の数 @property def E(self): """辺数 無向グラフのときは、辺数は有向グラフの倍になる """ return self._E @property def V(self): """頂点数""" return self._V def add(self, _from, _to, _cost): """2頂点と、辺のコストを追加する""" self.G[_from].append(self.Edge(_to, _cost)) self._E += 1 def shortest_path(self, s): """始点sから頂点iまでの最短路を格納したリストを返す Args: s(int): 始点s Returns: d(list): d[i] := 始点sから頂点iまでの最短コストを格納したリスト。 到達不可の場合、値はfloat("inf") """ import heapq que = [] # プライオリティキュー(ヒープ木) d = [10**15] * self.V d[s] = 0 heapq.heappush(que, (0, s)) # 始点の(最短距離, 頂点番号)をヒープに追加する while len(que) != 0: cost, v = heapq.heappop(que) # キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ if d[v] < cost: continue for i in range(len(self.G[v])): # 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する e = self.G[v][i] # vのi個目の隣接辺e if d[e.to] > d[v] + e.cost: d[e.to] = d[v] + e.cost # dの更新 heapq.heappush( que, (d[e.to], e.to) ) # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush return d K = int(input()) pro = Dijkstra(K) for i in range(0, K): pro.add(i, (i + 1) % K, 1) pro.add(i, (10 * i) % K, 0) ans = pro.shortest_path(1)[0] print(ans + 1)
Statement Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.
[{"input": "6", "output": "3\n \n\n12=6\u00d72 yields the smallest sum.\n\n* * *"}, {"input": "41", "output": "5\n \n\n11111=41\u00d7271 yields the smallest sum.\n\n* * *"}, {"input": "79992", "output": "36"}]
Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K. * * *
s683156226
Accepted
p03560
Input is given from Standard Input in the following format: K
# --*-coding:utf-8-*-- import heapq def sumOfDigits(n): a = 0 while n > 0: a += n % 10 n //= 10 return a def f(n): while n % 2 == 0: n //= 2 while n % 5 == 0: n //= 5 vs = [None] * n qs = [] x = sumOfDigits(n) for i in range(1, min(n, 10)): vs[i] = i heapq.heappush(qs, (i, i)) while len(qs) > 0: _, q = heapq.heappop(qs) q2 = q * 10 v = vs[q] for i in range(0, min(x - v, 10)): q3 = (q2 + i) % n v2 = v + i v3 = vs[q3] if v3 == None or v2 < v3: vs[q3] = v2 heapq.heappush(qs, (v2, q3)) if q3 == 0 and v2 < x: x = v2 return x def test(): assert f(6) == 3 assert f(41) == 5 assert f(79992) == 36 def main(): n = int(input()) print(f(n)) if __name__ == "__main__": main()
Statement Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.
[{"input": "6", "output": "3\n \n\n12=6\u00d72 yields the smallest sum.\n\n* * *"}, {"input": "41", "output": "5\n \n\n11111=41\u00d7271 yields the smallest sum.\n\n* * *"}, {"input": "79992", "output": "36"}]
Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K. * * *
s656513264
Accepted
p03560
Input is given from Standard Input in the following format: K
n = int(input()) while n % 2 == 0: n //= 2 while n % 5 == 0: n //= 5 if n == 1: print(1) else: X = [n for i in range(n)] j = 1 s = 1 post = [] m = 0 while True: s *= 10 s %= n post.append(s) X[s] = min(j, X[s]) m += 1 if s == 1: break ans = 0 while True: if ans > 0: break pre = post post = [] j += 1 for p in pre: pp = (p + 1) % n if pp == 0: X[0] = j ans = j break if X[pp] == n: for i in range(m): post.append(pp) X[pp] = j pp *= 10 pp %= n print(ans)
Statement Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.
[{"input": "6", "output": "3\n \n\n12=6\u00d72 yields the smallest sum.\n\n* * *"}, {"input": "41", "output": "5\n \n\n11111=41\u00d7271 yields the smallest sum.\n\n* * *"}, {"input": "79992", "output": "36"}]
Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K. * * *
s595236701
Wrong Answer
p03560
Input is given from Standard Input in the following format: K
import sys cin = sys.stdin # cin = open("in.txt", "r") def line2N(): return map(int, cin.readline().split()) (K,) = line2N() t = 0 rMin = 0x7FFF7FFF for i in range(1, K + 1): t += K d = sum(map(int, str(t))) rMin = min(rMin, d) print(rMin)
Statement Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.
[{"input": "6", "output": "3\n \n\n12=6\u00d72 yields the smallest sum.\n\n* * *"}, {"input": "41", "output": "5\n \n\n11111=41\u00d7271 yields the smallest sum.\n\n* * *"}, {"input": "79992", "output": "36"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s172630154
Accepted
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
t = sorted(map(int, open(0).read().split())) print(["YES", "NO"][max([t.count(i) for i in range(1, 5)]) > 2])
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s026769410
Wrong Answer
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
print("YES")
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s168779307
Accepted
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
#!usr/bin/env python3 from collections import defaultdict import math def LI(): return list(map(int, input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def IIR(n): return [II() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] mod = 1000000007 # A """ n,k = LI() if 2*(k-1) < n: print("YES") else: print("NO") """ # B c = LIR(3) v = [[] for i in range(4)] for i in range(3): c[i][0] -= 1 c[i][1] -= 1 v[c[i][0]].append(c[i][1]) v[c[i][1]].append(c[i][0]) for i in range(4): li = [True for i in range(4)] li[i] = False q = [i] c = 0 while q: x = q.pop(-1) k = 0 for j in v[x]: if li[j]: li[j] = False q.append(j) if k == 0: c += 1 k += 1 if c == 3: print("YES") quit() print("NO") # C # D # E # F # G # H # I # J # K # L # M # N # O # P # Q # R # S # T
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s217217569
Accepted
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b # aとbの最大公約数 def gcd(a, b): if b == 0: return a return gcd(b, a % b) # aとbの最小公倍数 def lcm(a, b): g = gcd(a, b) return a / g * b def main(): g = defaultdict(list) for _ in range(3): a, b = map(int, input().split()) g[a].append(b) g[b].append(a) for p in permutations([1, 2, 3, 4]): ok = True for i in range(3): a, b = p[i], p[i + 1] if b not in g[a]: ok = False if ok: print(YES) return print(NO) if __name__ == "__main__": main()
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s608512197
Wrong Answer
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
# -*- 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 # ############# SET = set() for _ in range(3): SET |= set(IL()) if len(SET) == 4: print("YES") else: print("NO")
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s506407787
Accepted
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
# みんなのプロコン 2019: B – Path a, b = [], [] for _ in range(3): tmp = input().split() a.append(int(tmp[0])) b.append(int(tmp[1])) paths = a + b passed_cities = [] for city in range(1, 5): passed_cities.append(paths.count(city)) print("NO" if max(passed_cities) == 3 else "YES")
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s251608225
Wrong Answer
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
a = input().split() b = a[0] c = a[1] d = input().split() e = d[0] f = d[1] g = input().split() h = g[0] i = g[1] L = [b, c, e, f, h, i] if L.count("1") or L.count("2") or L.count("3") or L.count("4") == 3: print("NO") else: print("YES")
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s273772744
Accepted
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
# -*- coding: utf-8 -*- """ https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_a """ from collections import defaultdict def sol(a1, b1, a2, b2, a3, b3): S = [a1, b1, a2, b2, a3, b3] d = defaultdict(int) for s in S: d[s] += 1 if len(d) == 4: num2 = 0 for k, v in d.items(): if v == 2: num2 += 1 if num2 == 2: return "YES" return "NO" test = False # test = True if test: print(sol(4, 2, 1, 3, 2, 3)) print(sol(3, 2, 2, 4, 1, 2)) print(sol(2, 1, 3, 2, 4, 3)) # n, k = 5, 5 # #S =list( map(int, "7 4 0 3".split())) # print(sol(n, k)) # # # n, k = 31, 10 # #S =list( map(int, "1000000000000".split())) # print(sol(n, k)) # # n, k = 10, 90 # #S =list( map(int, "1000000000000".split())) # print(sol(n, k)) else: # n, k = map(int, input().split()) a1, b1 = list(map(int, input().split())) a2, b2 = list(map(int, input().split())) a3, b3 = list(map(int, input().split())) print(sol(a1, b1, a2, b2, a3, b3))
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s092343372
Accepted
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
a = [0, 0, 0, 0, 0, 0] a[0], a[1] = map(int, input().split()) a[2], a[3] = map(int, input().split()) a[4], a[5] = map(int, input().split()) n1 = a.count(1) n2 = a.count(2) n3 = a.count(3) n4 = a.count(4) if n1 < 3: if n1 > 0: if n2 < 3: if n2 > 0: if n3 < 3: if n3 > 0: if n4 < 3: if n4 > 0: print("YES") exit() print("NO")
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s402135467
Runtime Error
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
A = [] B = [] for i in range(3): a, b = [int(n) for n in input().split()] A.append(a) B.append(b) counter = [0] * 4 for i in range(3): counter[A[i] - 1] += 1 counter[B[i] - 1] += 1 oddscounter = 0 for i in range(4): if counter[i] % 2 == 1: oddscounter += 1 answer = "" if oddscounter >= 3: answer = "NO" else: answer = "YES" print(answer)
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s112915209
Accepted
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
print("NYOE S"[sum(map(int, open(0).read().split())) % 2 :: 2])
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s339282439
Wrong Answer
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
I = input s = I() + I() + I() print("YNEOS"[any(s.count(x) > 1 for x in "1234") :: 2])
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s578709754
Wrong Answer
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
print("YNEOS"[sum(map(int, open(0).read().split())) < 15 :: 2])
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s263890721
Runtime Error
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
edges = [map(int, input().split()) for _ in range(3)] flattened = [i for sub in edges for i in sub] cont = sorted([flattened.count(i) for i in range(4)]) ans = 'YES' if cont = [1,1,2,2] else 'NO'
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s565142092
Runtime Error
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
a = [0]*5 for i in range(3): x,y = map(int,input().split()) a[x] += 1 a[y] += 1 if sorted(a) = [0,1,1,2,2]: print("YES") else: print("NO")
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s660276423
Runtime Error
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
#失恋してメンタル死んでるのでコードもシンデマス dic = {} key = [] item = [] res_flag = True for i in range(3): a,b = map(int,input().split()) dic[a] = b key.append(a) item.append(b) for i in key: flag = True tmp_key = key tmp_item = item a = i while flag: if a in key: a = dic[a] tmp_key.remove(a) tmp_item.remove(dic[a]) else: flag = False if len(tmp_item) == 0 and len(tmp_key) == 0: res = "YES" res_flag = False if res_flag: res = "NO" print(res)
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s865412887
Runtime Error
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
= [[0 for x in range(1)]for y in range(3)] one_count = 0 two_count = 0 three_count = 0 four_count = 0 for i in range(3): A[i] = [int(x) for x in input().split()] if(A[i][0]==1 or A[i][1]==1): one_count += 1 if(A[i][0]==2 or A[i][1]==2): two_count += 1 if(A[i][0]==3 or A[i][1]==3): three_count += 1 if(A[i][0]==1 or A[i][1]==1): four_count += 1 if(one_count >= 3 or two_count >= 3 or three_count >= 3 or four_count >= 3): print("NO") else: print("YES")
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s687936890
Runtime Error
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
lista = [] for i in range(3): a,b = map(int,input().split())) lista.append(a) lista.append(b) l1 = 0 l2 = 0 l3 = 0 l4 = 0 for j in lista: if j == 1: l1 += 1 if j == 2: l2 += 1 if j == 3: l3 += 1 if j == 4: l4 += 1 c = l1%2 + l2%2 + l3%2 + l4%2 if c%2 == 0: print('YES') else: print('NO')
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. * * *
s798350662
Runtime Error
p03130
Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3
# coding: utf-8 # Your code here! import sys num =[] for i in range(3): x,y = map(int,input().split(" ")) num.append(x) num.append(y) for i in range(1,4): if num.count(i)=3: print("NO") sys.exit() print("YES")
Statement There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
[{"input": "4 2\n 1 3\n 2 3", "output": "YES\n \n\nWe can visit all the towns in the order 1,3,2,4.\n\n* * *"}, {"input": "3 2\n 2 4\n 1 2", "output": "NO\n \n\n* * *"}, {"input": "2 1\n 3 2\n 4 3", "output": "YES"}]
Print the sum of the evaluated value over all possible formulas. * * *
s011856812
Accepted
p03999
The input is given from Standard Input in the following format: S
# C 解3 S = input() n = len(S) - 1 # 間の数 Sum = 0 for i in range(2**n): # print('%05d' % i)# pl = "" for j in range(n): pl += S[j] # print(j)# if format(i, "0" + str(n) + "b")[j] == "1": pl += "+" pl += S[n] # print(pl,end=',')# Sum += sum([int(x) for x in pl.split("+")]) print(Sum)
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s597651447
Wrong Answer
p03999
The input is given from Standard Input in the following format: S
s = input() if s == "125": exit() n = len(s) - 1 if n == 0: print(s) else: l = [] a = len(bin(1 << n)) - 3 for i in range(1 << n): l.append(str(bin(i))[2:].zfill(a)) su = 0 for i in l: ind = 0 st = s[ind] for j in i: if j == "0": pass else: st += "+" ind += 1 st += s[ind] su += eval(st) print(su)
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s198999640
Accepted
p03999
The input is given from Standard Input in the following format: S
# in1 = '125' #176 # in1 = '9999999999' #12656242944 in1 = input() len = len(in1) in_array = [""] * ((len * 2) - 1) for idx1 in range(len): in_array[idx1 * 2] = in1[idx1] RC = 0 for idx1 in range(2 ** (len - 1)): pos = format(idx1, "0" + str(len - 1) + "b") for idx2 in range(len - 1): if pos[idx2] == "1": in_array[idx2 * 2 + 1] = "+" else: in_array[idx2 * 2 + 1] = "" RC += eval("".join(in_array)) print(RC)
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s884097258
Wrong Answer
p03999
The input is given from Standard Input in the following format: S
( lambda nums: ( lambda index, itertools=__import__("itertools"): print( sum( [ eval( "".join( (lambda t: [[t.insert(j, "+") for j in reversed(i)], t][1])( list(nums) ) ) ) for i in itertools.chain( *[ itertools.combinations(index, x) for x in range(len(index) + 1) ] ) ] ) ) )(range(1, len(nums))) )("1234")
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s063443485
Accepted
p03999
The input is given from Standard Input in the following format: S
# @oj: atcoder # @id: hitwanyang # @email: 296866643@qq.com # @date: 2020-08-14 15:33 # @url:https://atcoder.jp/contests/abc045/tasks/arc061_a import sys, os from io import BytesIO, IOBase import collections, itertools, bisect, heapq, math, string from decimal import * # region fastio BUFSIZE = 8192 BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ def main(): s = str(input()) d = [int(x) for x in s[::-1]] cnt = [2 ** (len(s) - 1)] ans = 0 for i in range(len(d)): if i != 0: cnt[-1] = cnt[-1] // 2 cnt.append(cnt[-1]) for j in range(len(cnt)): ans += d[i] * (10**j) * (cnt[j]) print(ans) if __name__ == "__main__": main()
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s023270911
Runtime Error
p03999
The input is given from Standard Input in the following format: S
from sys import stdin n = int(stdin.readline().rstrip()) li = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)] point = 0 for i in range(101): for j in range(101): flag = True kizyun = False count = 0 for a, b, c in li: if c != 0: count += 1 if kizyun == False: h = c + abs(a - i) + abs(b - j) if h - abs(a - i) - abs(b - j) != c: flag = False kizyun = True else: k = c + abs(a - i) + abs(b - j) if h != k and kizyun == True: flag = False if count == 1: print(a, b, c) exit() if flag == True: point += 1 print(i, j, h)
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s741844693
Runtime Error
p03999
The input is given from Standard Input in the following format: S
from copy import * from sys import * import math import queue from collections import defaultdict, Counter, deque from fractions import Fraction as frac setrecursionlimit(1000000) # dp[i][j]: iまでからj枚えらんで和がkになるのは何通り def main(): s = input() ans = 0 for i in range(0, 2 ** (len(s) - 1)): temp = [] ix2 = base_10_to_n(i, 2) for i in range(len(s) - len(ix2) - 1): ix2 = "0" + ix2 tmp = s[0] for j in range(len(ix2)): if ix2[j] == "1": temp.append(tmp) tmp = s[j + 1] else: tmp = tmp + s[j + 1] temp.append(tmp) for i in temp: ans += int(i) print(ans) def zip(a): mae = a[0] ziparray = [mae] for i in range(1, len(a)): if mae != a[i]: ziparray.append(a[i]) mae = a[i] return ziparray def is_prime(n): if n < 2: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True def list_replace(n, f, t): return [t if i == f else i for i in n] def base_10_to_n(X, n): X_dumy = X out = "" while X_dumy > 0: out = str(X_dumy % n) + out X_dumy = int(X_dumy / n) if out == "": return "0" return out def gcd(m, n): x = max(m, n) y = min(m, n) while x % y != 0: z = x % y x = y y = z return y class queue: def __init__(self): self.q = deque([]) def push(self, i): self.q.append(i) def pop(self): return self.q.popleft() def size(self): return len(self.q) def debug(self): return self.q class stack: def __init__(self): self.q = [] def push(self, i): self.q.append(i) def pop(self): return self.q.pop() def size(self): return len(self.q) def debug(self): return self.q class graph: def __init__(self): self.graph = defaultdict(list) def addnode(self, l): f, t = l[0], l[1] self.graph[f].append(t) self.graph[t].append(f) def rmnode(self, l): f, t = l[0], l[1] self.graph[f].remove(t) self.graph[t].remove(f) def linked(self, f): return self.graph[f] class dgraph: def __init__(self): self.graph = defaultdict(set) def addnode(self, l): f, t = l[0], l[1] self.graph[f].append(t) def rmnode(self, l): f, t = l[0], l[1] self.graph[f].remove(t) def linked(self, f): return self.graph[f] main()
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s615545214
Accepted
p03999
The input is given from Standard Input in the following format: S
import copy s = input() n = len(s) ints = int(s) # くっつけるか、数値としてたすパターンを再帰関数で回せばいい all_sum = [0] num = [] # 各桁のそれぞれの数字を出力するアルゴリズム while ints != 0: # print(num) num.append(str(ints % 10)) ints //= 10 num.reverse() def DFS(num, count, sum): if count == n: # print(num) # print(sum) all_sum[0] += sum return num_coppy = copy.deepcopy(num) # そのまま足しちゃう sum += int(num_coppy[count]) # print(int(num_coppy[count])) count += 1 DFS(num_coppy, count, sum) count -= 1 #  一個後とくっつける if count <= n - 2: num_coppy[count + 1] = num_coppy[count] + num_coppy[count + 1] sum -= int(num_coppy[count]) count += 1 DFS(num_coppy, count, sum) return DFS(num, 0, 0) print(all_sum[0])
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s184888115
Accepted
p03999
The input is given from Standard Input in the following format: S
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(S): ans = 0 N = len(S) for i in range(N): for j in range(i + 1, N + 1): l = 2 ** (max(0, i - 1)) r = 2 ** (max(0, N - j - 1)) ans += int(S[i:j]) * l * r return ans def main(): S = read_str() print(slv(S)) if __name__ == "__main__": main()
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s969819657
Runtime Error
p03999
The input is given from Standard Input in the following format: S
S = input() def res(S, A, B): if not S: B.append(sum(list(map(int, A)))) return None A += [S[0]] res(S[1:], A, B) A.pop() A[-1] += S[0] res(S[1:], A, B) return B B = res(S[1:], [S[0]], []) print(sum(B))
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s325466606
Runtime Error
p03999
The input is given from Standard Input in the following format: S
S = input() stack = [S] ans = int(S) checked = [] while True: str_num = stack.pop() if len(str_num) <= 1: continue for i in range(len(str_num)): str1 = str_num[:i] str2 = str_num[i:] if not str1 in checked: checked.append(str1) ans += int(str1) stack.append(str1) if not str2 in checked: checked.append(str2) ans += int(str2) stack.append(str2) print(ans)
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s229987157
Accepted
p03999
The input is given from Standard Input in the following format: S
a, b, k = 0, 0, 1 for d in input(): a, b = 2 * a + b, 10 * b + int(d) * k k *= 2 print(a + b)
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s207318713
Runtime Error
p03999
The input is given from Standard Input in the following format: S
s=input() count=0 for i in range(1<<len(s)-1): t="" for j s: if i%2==1: t+="+" i//=2 count+=eval(t) print(count)
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s638308110
Runtime Error
p03999
The input is given from Standard Input in the following format: S
ss=input() ans=0 for i in range(2**(len(ss)-1)): temp=ss[0] for j in range(len(ss)-1): if i&(1<<j)!=0: temp+="+" temp+=ss[j+1] ans+=eval(temp) print(ans)
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s208562937
Runtime Error
p03999
The input is given from Standard Input in the following format: S
print(dfs(0, s[0]))
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the sum of the evaluated value over all possible formulas. * * *
s683515114
Runtime Error
p03999
The input is given from Standard Input in the following format: S
def dfs(i, f): if i == len(s) - 1: return sum(list(map(int, f.split("+")))) return dfs(i + 1, f + s[i + 1]) + \ dfs(i + 1, f + "+" + s[i + 1]) s = input() print(dfs(0, s[0]))
Statement You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
[{"input": "125", "output": "176\n \n\nThere are 4 formulas that can be obtained: `125`, `1+25`, `12+5` and `1+2+5`.\nWhen each formula is evaluated,\n\n * 125\n * 1+25=26\n * 12+5=17\n * 1+2+5=8\n\nThus, the sum is 125+26+17+8=176.\n\n* * *"}, {"input": "9999999999", "output": "12656242944"}]
Print the diameter of the tree in a line.
s904130062
Accepted
p02371
n s1 t1 w1 s2 t2 w2 : sn-1 tn-1 wn-1 The first line consists of an integer n which represents the number of nodes in the tree. Every node has a unique ID from 0 to n-1 respectively. In the following n-1 lines, edges of the tree are given. si and ti represent end-points of the i-th edge (undirected) and wi represents the weight (distance) of the i-th edge.
import sys input = sys.stdin.readline class Tree: def __init__(self, n, edge): self.n = n self.tree = [[] for _ in range(n)] for e in edge: self.tree[e[0]].append((e[1], e[2])) self.tree[e[1]].append((e[0], e[2])) def setroot(self, root): self.root = root self.parent = [None for _ in range(self.n)] self.parent[root] = -1 self.depth = [None for _ in range(self.n)] self.depth[root] = 0 self.distance = [None for _ in range(self.n)] self.distance[root] = 0 stack = [root] while stack: node = stack.pop() for adj, cost in self.tree[node]: if self.parent[adj] is None: self.parent[adj] = node self.depth[adj] = self.depth[node] + 1 self.distance[adj] = self.distance[node] + cost stack.append(adj) def diam(self): u = self.distance.index(max(self.distance)) dist_u = [None for _ in range(N)] dist_u[u] = 0 stack = [u] while stack: node = stack.pop() for adj, cost in self.tree[node]: if dist_u[adj] is None: dist_u[adj] = dist_u[node] + cost stack.append(adj) return max(dist_u) N = int(input()) E = [list(map(int, input().split())) for _ in range(N - 1)] t = Tree(N, E) t.setroot(0) print(t.diam())
Diameter of a Tree Given a tree T with non-negative weight, find the diameter of the tree. The diameter of a tree is the maximum distance between two nodes in a tree.
[{"input": "4\n 0 1 2\n 1 2 1\n 1 3 3", "output": "5"}, {"input": "4\n 0 1 1\n 1 2 2\n 2 3 4", "output": "7"}]
Print Joisino's maximum possible eventual happiness. * * *
s359522755
Wrong Answer
p03833
The input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N-1} B_{1,1} B_{1,2} ... B_{1,M} B_{2,1} B_{2,2} ... B_{2,M} : B_{N,1} B_{N,2} ... B_{N,M}
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import defaultdict import time def main(): s = time.time() n, m = map(int, readline().split()) a = list(map(int, readline().split())) b = list(map(int, read().split())) query = [defaultdict(int) for _ in range(n + 2)] for i in range(m): left = list(range(-1, n + 1)) right = list(range(1, n + 3)) bi = [(val, j) for j, val in enumerate(b[i::m], 1)] bi.sort() for val, j in bi: l = left[j] r = right[j] query[l + 1][j] += val query[l + 1][r] -= val query[j + 1][j] -= val query[j + 1][r] += val right[l] = r left[r] = l imos = [0] * (n + 2) for i, ai in enumerate(a, 2): imos[i] = imos[i - 1] - ai query[i][i] += ai ans = 0 for i in range(1, n + 1): next = [0] * (n + 2) for j, val in query[i].items(): next[j] += val for j in range(i - 1, n + 1): next[j + 1] += next[j] imos[j] += next[j] ans = max(ans, max(imos[i : n + 1])) if time.time() - s > 1.9: print(ans) exit() print(ans) if __name__ == "__main__": main() """ 嘘解答です """
Statement There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i. Joisino has M tickets, numbered 1 through M. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant i offers a meal of _deliciousness_ B_{i,j} in exchange for ticket j. Each ticket can only be used once, but any number of tickets can be used at a restaurant. Joisino wants to have M barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual _happiness_ is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness.
[{"input": "3 4\n 1 4\n 2 2 5 1\n 1 3 3 2\n 2 2 5 1", "output": "11\n \n\nThe eventual happiness can be maximized by the following strategy: start from\nrestaurant 1 and use tickets 1 and 3, then move to restaurant 2 and use\ntickets 2 and 4.\n\n* * *"}, {"input": "5 3\n 1 2 3 4\n 10 1 1\n 1 1 1\n 1 10 1\n 1 1 1\n 1 1 10", "output": "20"}]
Print Joisino's maximum possible eventual happiness. * * *
s876537427
Wrong Answer
p03833
The input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N-1} B_{1,1} B_{1,2} ... B_{1,M} B_{2,1} B_{2,2} ... B_{2,M} : B_{N,1} B_{N,2} ... B_{N,M}
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x + "\n") # 二分探索木の代わり BST HST # 存在しない要素に対するremoveはこないことを仮定している from heapq import heappop as hpp, heappush as hp class HST: def __init__(self, ascending=True): self._h = [] self._q = [] self.ascending = ascending def push(self, v): if not self.ascending: v *= -1 hp(self._h, v) def remove(self, v): if not self.ascending: v *= -1 hp(self._q, v) def top(self): while self._q and self._q[0] == self._h[0]: hpp(self._q) hpp(self._h) if not self._h: res = None else: res = self._h[0] if not self.ascending: res *= -1 return res # inputna n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = [list(map(int, input().split())) for _ in range(n)] ans = 0 hs = [HST(ascending=False) for _ in range(m)] j = 0 val = 0 prv = 0 def sub(): return sum(hs[i].top() for i in range(m)) for i in range(n): if i >= 1: val += a[i - 1] for k in range(m): hs[k].push(b[i][k]) ans = sub() - val l = 0 r = n - 1 for _ in range(n - 1): for k in range(m): hs[k].remove(b[l][k]) val -= a[l] v1 = sub() - val for k in range(m): hs[k].push(b[l][k]) val += a[l] val -= a[r - 1] for k in range(m): hs[k].remove(b[r][k]) v2 = sub() - val if v1 > v2: for k in range(m): hs[k].push(b[r][k]) val += a[r - 1] val -= a[l] for k in range(m): hs[k].remove(b[l][k]) l += 1 else: r -= 1 ans = max(ans, v1, v2) print(ans)
Statement There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i. Joisino has M tickets, numbered 1 through M. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant i offers a meal of _deliciousness_ B_{i,j} in exchange for ticket j. Each ticket can only be used once, but any number of tickets can be used at a restaurant. Joisino wants to have M barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual _happiness_ is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness.
[{"input": "3 4\n 1 4\n 2 2 5 1\n 1 3 3 2\n 2 2 5 1", "output": "11\n \n\nThe eventual happiness can be maximized by the following strategy: start from\nrestaurant 1 and use tickets 1 and 3, then move to restaurant 2 and use\ntickets 2 and 4.\n\n* * *"}, {"input": "5 3\n 1 2 3 4\n 10 1 1\n 1 1 1\n 1 10 1\n 1 1 1\n 1 1 10", "output": "20"}]
Print Joisino's maximum possible eventual happiness. * * *
s919076424
Runtime Error
p03833
The input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N-1} B_{1,1} B_{1,2} ... B_{1,M} B_{2,1} B_{2,2} ... B_{2,M} : B_{N,1} B_{N,2} ... B_{N,M}
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,M = map(int,readline().split()) A = [0]+list(map(int,readline().split())) B = list(map(int,read().split())) for i in range(1,N): A[i] += A[i-1] ticket_sum = [0]*(N*N) # 各区間 [L,R] に対して、採用される点数を見る for n in range(M): arr = B[n::M] # 安いチケットから入れていく -> 連結成分上で採用される left = list(range(N)) right = list(range(N)) filled = [False]*(N+1) for i in sorted(range(N), key=arr.__getitem__): filled[i] = True l = i if (not filled[i-1]) else left[i-1] r = i if (not filled[i+1]) else right[i+1] left[r] = l; right[l] = r # [l,i] x [i,r] に arr[i] を加える x = arr[i] ticket_sum[l*N+i]+=x if i<N-1: ticket_sum[(i+1)*N+i]-=x if r<N-1: ticket_sum[l*N+r+1]-=x if i<N-1: ticket_sum[(i+1)*N+r+1]+=x # 2d累積和 for i in range(N,N*N): ticket_sum[i] += ticket_sum[i-N] for i in range(N*N): if i%N: ticket_sum[i] += ticket_sum[i-1] answer = 0 for i in range(N): x = A[i] for y,t in zip(A[i:],ticket_sum[N*i+i:N*i+N]): happy = x-y+t if answer < happy: answer = happy print(answer)
Statement There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i. Joisino has M tickets, numbered 1 through M. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant i offers a meal of _deliciousness_ B_{i,j} in exchange for ticket j. Each ticket can only be used once, but any number of tickets can be used at a restaurant. Joisino wants to have M barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual _happiness_ is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness.
[{"input": "3 4\n 1 4\n 2 2 5 1\n 1 3 3 2\n 2 2 5 1", "output": "11\n \n\nThe eventual happiness can be maximized by the following strategy: start from\nrestaurant 1 and use tickets 1 and 3, then move to restaurant 2 and use\ntickets 2 and 4.\n\n* * *"}, {"input": "5 3\n 1 2 3 4\n 10 1 1\n 1 1 1\n 1 10 1\n 1 1 1\n 1 1 10", "output": "20"}]
Print Joisino's maximum possible eventual happiness. * * *
s060310643
Runtime Error
p03833
The input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N-1} B_{1,1} B_{1,2} ... B_{1,M} B_{2,1} B_{2,2} ... B_{2,M} : B_{N,1} B_{N,2} ... B_{N,M}
a, b = map(str, input(), split()) if a.lower() == b: print("Yes") else: print("No")
Statement There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i. Joisino has M tickets, numbered 1 through M. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant i offers a meal of _deliciousness_ B_{i,j} in exchange for ticket j. Each ticket can only be used once, but any number of tickets can be used at a restaurant. Joisino wants to have M barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual _happiness_ is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness.
[{"input": "3 4\n 1 4\n 2 2 5 1\n 1 3 3 2\n 2 2 5 1", "output": "11\n \n\nThe eventual happiness can be maximized by the following strategy: start from\nrestaurant 1 and use tickets 1 and 3, then move to restaurant 2 and use\ntickets 2 and 4.\n\n* * *"}, {"input": "5 3\n 1 2 3 4\n 10 1 1\n 1 1 1\n 1 10 1\n 1 1 1\n 1 1 10", "output": "20"}]
Print all days on which Takahashi is bound to work in ascending order, one per line. * * *
s814655156
Runtime Error
p02721
Input is given from Standard Input in the following format: N K C S
k = int(input()) lunluns = list(map(str, range(1, 10))) new = list(map(str, range(1, 10))) new_fueta = 9 end = False while len(lunluns) < k: new_new_fueta = 0 for x in lunluns[-new_fueta:]: str_x = str(x) if str_x[-1] == "0": lunluns += [int(str_x + "0"), int(str_x + "1")] new_new_fueta += 2 elif str_x[-1] == "9": lunluns += [int(str_x + "8"), int(str_x + "9")] new_new_fueta += 2 else: l = int(str_x[-1]) lunluns += [ int(str_x + str(l - 1)), int(str_x + str(l)), int(str_x + str(l + 1)), ] new_new_fueta += 3 if end: break new_fueta = new_new_fueta print(lunluns[k - 1])
Statement Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S. Takahashi will choose his workdays as follows: * After working for a day, he will refrain from working on the subsequent C days. * If the i-th character of S is `x`, he will not work on Day i, where Day 1 is tomorrow, Day 2 is the day after tomorrow, and so on. Find all days on which Takahashi is bound to work.
[{"input": "11 3 2\n ooxxxoxxxoo", "output": "6\n \n\nTakahashi is going to work on 3 days out of the 11 days. After working for a\nday, he will refrain from working on the subsequent 2 days.\n\nThere are four possible choices for his workdays: Day 1,6,10, Day 1,6,11, Day\n2,6,10, and Day 2,6,11.\n\nThus, he is bound to work on Day 6.\n\n* * *"}, {"input": "5 2 3\n ooxoo", "output": "1\n 5\n \n\nThere is only one possible choice for his workdays: Day 1,5.\n\n* * *"}, {"input": "5 1 0\n ooooo", "output": "There may be no days on which he is bound to work.\n\n* * *"}, {"input": "16 4 3\n ooxxoxoxxxoxoxxo", "output": "11\n 16"}]
Print all days on which Takahashi is bound to work in ascending order, one per line. * * *
s999400611
Runtime Error
p02721
Input is given from Standard Input in the following format: N K C S
# -*- coding: utf-8 -*- def f(n): C = [[1 for i in range(10)]] while sum(d for c in C for d in c[1:]) < n: C.append([sum(C[-1][max(0, i - 1) : min(i + 2, 10)]) for i in range(10)]) return C def solve(): n = int(input()) C = f(n) X = [] m = sum(d for c in C[:-1] for d in c[1:]) x = 1 for x in range(1, 10): if m + C[-1][x] < n: m += C[-1][x] else: break X.append(x) C = C[:-1] for c in C[::-1]: for x in range(max(0, X[-1] - 1), min(10, X[-1] + 2)): if m + c[x] < n: m += c[x] else: break X.append(x) return "".join(map(str, X)) if __name__ == "__main__": print(solve())
Statement Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S. Takahashi will choose his workdays as follows: * After working for a day, he will refrain from working on the subsequent C days. * If the i-th character of S is `x`, he will not work on Day i, where Day 1 is tomorrow, Day 2 is the day after tomorrow, and so on. Find all days on which Takahashi is bound to work.
[{"input": "11 3 2\n ooxxxoxxxoo", "output": "6\n \n\nTakahashi is going to work on 3 days out of the 11 days. After working for a\nday, he will refrain from working on the subsequent 2 days.\n\nThere are four possible choices for his workdays: Day 1,6,10, Day 1,6,11, Day\n2,6,10, and Day 2,6,11.\n\nThus, he is bound to work on Day 6.\n\n* * *"}, {"input": "5 2 3\n ooxoo", "output": "1\n 5\n \n\nThere is only one possible choice for his workdays: Day 1,5.\n\n* * *"}, {"input": "5 1 0\n ooooo", "output": "There may be no days on which he is bound to work.\n\n* * *"}, {"input": "16 4 3\n ooxxoxoxxxoxoxxo", "output": "11\n 16"}]
Print all days on which Takahashi is bound to work in ascending order, one per line. * * *
s979799675
Accepted
p02721
Input is given from Standard Input in the following format: N K C S
import sys sys.setrecursionlimit(100000000) def main(): N, K, C = map(int, input().split()) S = input() def forward(k): i = 0 day = 0 days = [-1] * k l = len(S) while day < k and i < l: while S[i] == "x": i += 1 if i >= l: return None days[day] = i day += 1 i += 1 + C if day < k: return None return days def backward(k): day = k days = [-1] * k l = len(S) i = l - 1 while day > 0 and i >= 0: while S[i] == "x": i -= 1 if i < 0: return None day -= 1 days[day] = i i -= 1 + C if day > 0: return None return days left = forward(K) if left is None: return right = backward(K) for i, j in zip(left, right): if i == j: print(i + 1) main()
Statement Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S. Takahashi will choose his workdays as follows: * After working for a day, he will refrain from working on the subsequent C days. * If the i-th character of S is `x`, he will not work on Day i, where Day 1 is tomorrow, Day 2 is the day after tomorrow, and so on. Find all days on which Takahashi is bound to work.
[{"input": "11 3 2\n ooxxxoxxxoo", "output": "6\n \n\nTakahashi is going to work on 3 days out of the 11 days. After working for a\nday, he will refrain from working on the subsequent 2 days.\n\nThere are four possible choices for his workdays: Day 1,6,10, Day 1,6,11, Day\n2,6,10, and Day 2,6,11.\n\nThus, he is bound to work on Day 6.\n\n* * *"}, {"input": "5 2 3\n ooxoo", "output": "1\n 5\n \n\nThere is only one possible choice for his workdays: Day 1,5.\n\n* * *"}, {"input": "5 1 0\n ooooo", "output": "There may be no days on which he is bound to work.\n\n* * *"}, {"input": "16 4 3\n ooxxoxoxxxoxoxxo", "output": "11\n 16"}]
Print all days on which Takahashi is bound to work in ascending order, one per line. * * *
s835398174
Wrong Answer
p02721
Input is given from Standard Input in the following format: N K C S
exit()
Statement Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S. Takahashi will choose his workdays as follows: * After working for a day, he will refrain from working on the subsequent C days. * If the i-th character of S is `x`, he will not work on Day i, where Day 1 is tomorrow, Day 2 is the day after tomorrow, and so on. Find all days on which Takahashi is bound to work.
[{"input": "11 3 2\n ooxxxoxxxoo", "output": "6\n \n\nTakahashi is going to work on 3 days out of the 11 days. After working for a\nday, he will refrain from working on the subsequent 2 days.\n\nThere are four possible choices for his workdays: Day 1,6,10, Day 1,6,11, Day\n2,6,10, and Day 2,6,11.\n\nThus, he is bound to work on Day 6.\n\n* * *"}, {"input": "5 2 3\n ooxoo", "output": "1\n 5\n \n\nThere is only one possible choice for his workdays: Day 1,5.\n\n* * *"}, {"input": "5 1 0\n ooooo", "output": "There may be no days on which he is bound to work.\n\n* * *"}, {"input": "16 4 3\n ooxxoxoxxxoxoxxo", "output": "11\n 16"}]
Print all days on which Takahashi is bound to work in ascending order, one per line. * * *
s824282186
Accepted
p02721
Input is given from Standard Input in the following format: N K C S
n, k, c = map(int, input().split()) s = "?" + input() fwd = set() now = 1 while now <= n: if s[now] == "o": fwd.add(now) now += c + 1 else: now += 1 bwd = set() now = n while now >= 1: if s[now] == "o": bwd.add(now) now -= c + 1 else: now -= 1 if len(fwd) == k: print(*sorted(list(fwd & bwd)), sep="\n") else: exit()
Statement Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S. Takahashi will choose his workdays as follows: * After working for a day, he will refrain from working on the subsequent C days. * If the i-th character of S is `x`, he will not work on Day i, where Day 1 is tomorrow, Day 2 is the day after tomorrow, and so on. Find all days on which Takahashi is bound to work.
[{"input": "11 3 2\n ooxxxoxxxoo", "output": "6\n \n\nTakahashi is going to work on 3 days out of the 11 days. After working for a\nday, he will refrain from working on the subsequent 2 days.\n\nThere are four possible choices for his workdays: Day 1,6,10, Day 1,6,11, Day\n2,6,10, and Day 2,6,11.\n\nThus, he is bound to work on Day 6.\n\n* * *"}, {"input": "5 2 3\n ooxoo", "output": "1\n 5\n \n\nThere is only one possible choice for his workdays: Day 1,5.\n\n* * *"}, {"input": "5 1 0\n ooooo", "output": "There may be no days on which he is bound to work.\n\n* * *"}, {"input": "16 4 3\n ooxxoxoxxxoxoxxo", "output": "11\n 16"}]
Print all days on which Takahashi is bound to work in ascending order, one per line. * * *
s941457545
Wrong Answer
p02721
Input is given from Standard Input in the following format: N K C S
a = 0
Statement Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S. Takahashi will choose his workdays as follows: * After working for a day, he will refrain from working on the subsequent C days. * If the i-th character of S is `x`, he will not work on Day i, where Day 1 is tomorrow, Day 2 is the day after tomorrow, and so on. Find all days on which Takahashi is bound to work.
[{"input": "11 3 2\n ooxxxoxxxoo", "output": "6\n \n\nTakahashi is going to work on 3 days out of the 11 days. After working for a\nday, he will refrain from working on the subsequent 2 days.\n\nThere are four possible choices for his workdays: Day 1,6,10, Day 1,6,11, Day\n2,6,10, and Day 2,6,11.\n\nThus, he is bound to work on Day 6.\n\n* * *"}, {"input": "5 2 3\n ooxoo", "output": "1\n 5\n \n\nThere is only one possible choice for his workdays: Day 1,5.\n\n* * *"}, {"input": "5 1 0\n ooooo", "output": "There may be no days on which he is bound to work.\n\n* * *"}, {"input": "16 4 3\n ooxxoxoxxxoxoxxo", "output": "11\n 16"}]
Print all days on which Takahashi is bound to work in ascending order, one per line. * * *
s360462252
Accepted
p02721
Input is given from Standard Input in the following format: N K C S
n, k, c = map(int, input().split()) c += 1 a = input() b = a[::-1] form = [0] lat = [0] for i in range(n): if a[i] == "x": form.append(form[-1]) else: try: form.append(max(form[-c] + 1, form[-1])) except: form.append(1) if b[i] == "x": lat.append(lat[-1]) else: try: lat.append(max(lat[-c] + 1, lat[-1])) except: lat.append(1) form.append(form[-1]) lat.append(lat[-1]) lat.reverse() # print(form) # print(lat) # print(len(form)) for i in range(n): if form[i] + lat[i + 2] == k - 1: print(i + 1)
Statement Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S. Takahashi will choose his workdays as follows: * After working for a day, he will refrain from working on the subsequent C days. * If the i-th character of S is `x`, he will not work on Day i, where Day 1 is tomorrow, Day 2 is the day after tomorrow, and so on. Find all days on which Takahashi is bound to work.
[{"input": "11 3 2\n ooxxxoxxxoo", "output": "6\n \n\nTakahashi is going to work on 3 days out of the 11 days. After working for a\nday, he will refrain from working on the subsequent 2 days.\n\nThere are four possible choices for his workdays: Day 1,6,10, Day 1,6,11, Day\n2,6,10, and Day 2,6,11.\n\nThus, he is bound to work on Day 6.\n\n* * *"}, {"input": "5 2 3\n ooxoo", "output": "1\n 5\n \n\nThere is only one possible choice for his workdays: Day 1,5.\n\n* * *"}, {"input": "5 1 0\n ooooo", "output": "There may be no days on which he is bound to work.\n\n* * *"}, {"input": "16 4 3\n ooxxoxoxxxoxoxxo", "output": "11\n 16"}]
Print all days on which Takahashi is bound to work in ascending order, one per line. * * *
s878394061
Wrong Answer
p02721
Input is given from Standard Input in the following format: N K C S
class SegmentTree: """Segment Tree (Point Update & Range Query) Query 1. update(i, val): update i-th value to val 2. query(low, high): find f(value) in [low, high) Complexity time complexity: O(log n) space complexity: O(n) """ def __init__(self, N, f, default): self.N = 1 << (N - 1).bit_length() self.default = default self.f = f self.segtree = [self.default] * ((self.N << 1) - 1) @classmethod def create_from_array(cls, arr, f, default): N = len(arr) self = cls(N, f, default) for i in range(N): self.segtree[self.N - 1 + i] = arr[i] for i in reversed(range(self.N - 1)): self.segtree[i] = self.f( self.segtree[(i << 1) + 1], self.segtree[(i << 1) + 2] ) return self def update(self, i, val): i += self.N - 1 self.segtree[i] = val while i > 0: i = (i - 1) >> 1 self.segtree[i] = self.f( self.segtree[(i << 1) + 1], self.segtree[(i << 1) + 2] ) def __getitem__(self, k): return self.segtree[self.N - 1 + k] def query(self, low, high): # query [l, r) low, high = low + self.N, high + self.N left_ret, right_ret = self.default, self.default while low < high: if low & 1: left_ret = self.f(left_ret, self.segtree[low - 1]) low += 1 if high & 1: high -= 1 right_ret = self.f(self.segtree[high - 1], right_ret) low, high = low >> 1, high >> 1 return self.f(left_ret, right_ret) def main() -> None: N, K, C = map(int, input().split()) S = [1 if s == "o" else 0 for s in input()] left, right = [-1] * N, [-1] * N max_v = -1 for i in range(N): if i - C - 1 >= 0: max_v = max(max_v, left[i - C - 1]) if S[i] == 1: left[i] = max_v + 1 max_v = -1 for i in reversed(range(N)): if i + C + 1 <= N - 1: max_v = max(max_v, right[i + C + 1]) if S[i] == 1: right[i] = max_v + 1 work_day = [max(0, left[i] + right[i] + 1) for i in range(N)] # print(work_day) if max(work_day) > K: return segt = SegmentTree.create_from_array(work_day, max, 0) ans = [] for i in range(N): m = max(segt.query(max(0, i - C), i), segt.query(i + 1, min(i + 1 + C, N))) if m >= K: continue # m = max(segt.query(0, max(0, i - C)), segt.query(min(N, i + 1 + C), N)) # if m >= K + 1: # continue ans.append(i + 1) print(*ans, sep="\n") if __name__ == "__main__": main()
Statement Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S. Takahashi will choose his workdays as follows: * After working for a day, he will refrain from working on the subsequent C days. * If the i-th character of S is `x`, he will not work on Day i, where Day 1 is tomorrow, Day 2 is the day after tomorrow, and so on. Find all days on which Takahashi is bound to work.
[{"input": "11 3 2\n ooxxxoxxxoo", "output": "6\n \n\nTakahashi is going to work on 3 days out of the 11 days. After working for a\nday, he will refrain from working on the subsequent 2 days.\n\nThere are four possible choices for his workdays: Day 1,6,10, Day 1,6,11, Day\n2,6,10, and Day 2,6,11.\n\nThus, he is bound to work on Day 6.\n\n* * *"}, {"input": "5 2 3\n ooxoo", "output": "1\n 5\n \n\nThere is only one possible choice for his workdays: Day 1,5.\n\n* * *"}, {"input": "5 1 0\n ooooo", "output": "There may be no days on which he is bound to work.\n\n* * *"}, {"input": "16 4 3\n ooxxoxoxxxoxoxxo", "output": "11\n 16"}]
Print all days on which Takahashi is bound to work in ascending order, one per line. * * *
s257336244
Wrong Answer
p02721
Input is given from Standard Input in the following format: N K C S
n, k, c = map(int, input().split()) sl = list(input()) # 前貪欲 ansl = [] before = -float("inf") for idx, s in enumerate(sl): if s == "o" and before + c < idx: before = idx ansl.append(idx) if len(ansl) > k: print() exit() # 後貪欲 ansl2 = [] before = -float("inf") for idx, s in enumerate(sl[::-1]): if s == "o" and before + c < idx: before = idx ansl2.append(n - idx - 1) for a in list(set(ansl) & set(ansl2)): print(a + 1)
Statement Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S. Takahashi will choose his workdays as follows: * After working for a day, he will refrain from working on the subsequent C days. * If the i-th character of S is `x`, he will not work on Day i, where Day 1 is tomorrow, Day 2 is the day after tomorrow, and so on. Find all days on which Takahashi is bound to work.
[{"input": "11 3 2\n ooxxxoxxxoo", "output": "6\n \n\nTakahashi is going to work on 3 days out of the 11 days. After working for a\nday, he will refrain from working on the subsequent 2 days.\n\nThere are four possible choices for his workdays: Day 1,6,10, Day 1,6,11, Day\n2,6,10, and Day 2,6,11.\n\nThus, he is bound to work on Day 6.\n\n* * *"}, {"input": "5 2 3\n ooxoo", "output": "1\n 5\n \n\nThere is only one possible choice for his workdays: Day 1,5.\n\n* * *"}, {"input": "5 1 0\n ooooo", "output": "There may be no days on which he is bound to work.\n\n* * *"}, {"input": "16 4 3\n ooxxoxoxxxoxoxxo", "output": "11\n 16"}]
Print the minimum number of scalar multiplication in a line.
s231868366
Accepted
p02234
In the first line, an integer $n$ is given. In the following $n$ lines, the dimension of matrix $M_i$ ($i = 1...n$) is given by two integers $r$ and $c$ which respectively represents the number of rows and columns of $M_i$.
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) N = int(input()) RC = [list(map(int, input().split())) for _ in range(N)] memo = [[-1] * (N + 1) for _ in range(N + 1)] inf = 10**18 def mult(l, r): """ 半開区間[l, r) """ if memo[l][r] != -1: return memo[l][r] if r - l <= 1: memo[l][r] = 0 return 0 res = inf for m in range(l + 1, r): prod = RC[l][0] * RC[m - 1][1] * RC[r - 1][1] tmp = mult(l, m) + mult(m, r) + prod res = min(res, tmp) memo[l][r] = res return res ans = mult(0, N) print(ans)
Matrix-chain Multiplication The goal of the matrix-chain multiplication problem is to find the most efficient way to multiply given $n$ matrices $M_1, M_2, M_3,...,M_n$. Write a program which reads dimensions of $M_i$, and finds the minimum number of scalar multiplications to compute the maxrix-chain multiplication $M_1M_2...M_n$.
[{"input": "6\n 30 35\n 35 15\n 15 5\n 5 10\n 10 20\n 20 25", "output": "15125"}]
Print the minimum number of scalar multiplication in a line.
s001944724
Accepted
p02234
In the first line, an integer $n$ is given. In the following $n$ lines, the dimension of matrix $M_i$ ($i = 1...n$) is given by two integers $r$ and $c$ which respectively represents the number of rows and columns of $M_i$.
def matrix_chmul(matrices): length = len(matrices) dp = [[0 for n in range(length)] for m in range(length)] rowcol = [] for i in range(length): rowcol.extend(matrices[i]) for i in range(1, length): for j in range(length - i): if i == 1: dp[j][i + j] = ( rowcol[j * 2] * rowcol[(i + j) * 2] * rowcol[(i + j) * 2 + 1] ) else: temp_min = float("inf") for k in range(0, i): # print(i, j, k, dp[j][j + k], dp[j + k + 1][i + j]) dp[j][i + j] = min( temp_min, ( dp[j][j + k] + dp[j + k + 1][i + j] + rowcol[j * 2] * rowcol[(j + k + 1) * 2] * rowcol[(i + j) * 2 + 1] ), ) temp_min = dp[j][i + j] # print(dp) return dp[0][length - 1] length = int(input()) matrices = [[0 for n in range(2)] for m in range(length)] for _ in range(length): x, y = [int(n) for n in input().split(" ")] matrices[_] = x, y print(matrix_chmul(matrices))
Matrix-chain Multiplication The goal of the matrix-chain multiplication problem is to find the most efficient way to multiply given $n$ matrices $M_1, M_2, M_3,...,M_n$. Write a program which reads dimensions of $M_i$, and finds the minimum number of scalar multiplications to compute the maxrix-chain multiplication $M_1M_2...M_n$.
[{"input": "6\n 30 35\n 35 15\n 15 5\n 5 10\n 10 20\n 20 25", "output": "15125"}]
Print the minimum number of scalar multiplication in a line.
s940614807
Accepted
p02234
In the first line, an integer $n$ is given. In the following $n$ lines, the dimension of matrix $M_i$ ($i = 1...n$) is given by two integers $r$ and $c$ which respectively represents the number of rows and columns of $M_i$.
global memo def find_memo(m, l): # memoのm行l列の値を返す.data # data[l]から続くm+1個の要素からなる部分リスト if memo[m][l] != 0: return memo[m][l] if m < 2: return memo[m][l] tmp_min = 999999999 for i in range(1, m): left = find_memo(i, l) right = find_memo(m - i, l + i) middle = memo[0][l] * memo[0][l + i] * memo[0][l + m] if left + right + middle < tmp_min: tmp_min = left + right + middle memo[m][l] = tmp_min return tmp_min tmp_min = 9999999999 n = int(input()) memo = [ [0] * (n + 1 - i) for i in range(n + 1) ] # memo[i][j]はdata[j]から続くi+1個の要素からなる部分リストの最小計算コストを表す memo[0][0], memo[0][1] = map(int, input().split()) for i in range(2, n + 1): dummy, memo[0][i] = map(int, input().split()) for i in range(n - 1): memo[2][i] = memo[0][i] * memo[0][i + 1] * memo[0][i + 2] print(find_memo(n, 0))
Matrix-chain Multiplication The goal of the matrix-chain multiplication problem is to find the most efficient way to multiply given $n$ matrices $M_1, M_2, M_3,...,M_n$. Write a program which reads dimensions of $M_i$, and finds the minimum number of scalar multiplications to compute the maxrix-chain multiplication $M_1M_2...M_n$.
[{"input": "6\n 30 35\n 35 15\n 15 5\n 5 10\n 10 20\n 20 25", "output": "15125"}]
Print the minimum number of scalar multiplication in a line.
s733758246
Accepted
p02234
In the first line, an integer $n$ is given. In the following $n$ lines, the dimension of matrix $M_i$ ($i = 1...n$) is given by two integers $r$ and $c$ which respectively represents the number of rows and columns of $M_i$.
INF = 10**20 n = int(input()) nlist = [] all_mat = [] for i in range(n): a, b = map(int, input().split()) all_mat.append((a, b)) if i == 0: nlist = [a, b] else: nlist.append(b) def cost1(nlist): if len(nlist) == 0: return 0 m = min(nlist) cost = 0 mid = nlist.index(m) a = nlist[:mid] b = nlist[mid + 1 :] while len(a) > 1 and len(a) != 0: for i in range(len(a) - 1): cost += a.pop() * a[-1] # print(a) while len(b) > 1 and len(b) != 0: b.reverse() for i in range(len(b) - 1): cost += b.pop() * b[-1] # print(b) if len(a) == 1 and len(b) == 1: cost += a.pop() * b.pop() # print(a,b) cost *= m return cost # [34, 44, 13, 30] def cost2(nlist, mm): if len(nlist) == 0: return 0 m = min(nlist) cost = 0 mid = nlist.index(m) a = nlist[: mid + 1] # print(a) b = nlist[mid:] # print(b) while len(a) > 1 and len(a) != 0: a.reverse() for i in range(len(a) - 1): cost += a.pop() * a[-1] # print(a) while len(b) > 1 and len(b) != 0: for i in range(len(b) - 1): cost += b.pop() * b[-1] # print(b) if len(a) == 1 and len(b) == 1: cost += m * mm # print(a,b) cost *= mm return cost copy = nlist[:] m = min(nlist) # print(nlist) c = nlist.count(m) cost = 0 if c == 1: cost = cost1(nlist) elif c >= 2: cc = 1 cut_index = [0] mcount = nlist.count(m) for i in range(mcount): cut_index.append(nlist.index(m)) nlist.remove(m) cut = [] for i in range(mcount): cut.append(nlist[cut_index[i] : cut_index[i + 1]]) cut.append(nlist[cut_index[-1] :]) # print(cut) co1 = cut[0] + [m] + cut[-1] cost += cost1(co1) for co2 in cut[1:-1]: # print(co2) cost += cost2(co2, m) co3 = cut[0] + cut[-1] if len(co3) > 1: cost += (len(cut) - 2) * m * min(co3) print(cost)
Matrix-chain Multiplication The goal of the matrix-chain multiplication problem is to find the most efficient way to multiply given $n$ matrices $M_1, M_2, M_3,...,M_n$. Write a program which reads dimensions of $M_i$, and finds the minimum number of scalar multiplications to compute the maxrix-chain multiplication $M_1M_2...M_n$.
[{"input": "6\n 30 35\n 35 15\n 15 5\n 5 10\n 10 20\n 20 25", "output": "15125"}]
Print the maximum number of KUPCs that can be held on one line. * * *
s963923908
Wrong Answer
p03976
The input is given from Standard Input in the following format: N K P_1 : P_N
n, k = map(int, input().split()) p = [input() for _ in range(n)] p_ini = [0] * 26 for _p in p: p_ini[ord(_p[0]) - ord("A")] += 1 res = 0 while p_ini.count(0) <= 26 - k: tmp = 0 for i in range(26): if p_ini[i] != 0: p_ini[i] -= 1 tmp += 1 if tmp == k: break res += 1 print(res)
Statement > Kyoto University Programming Contest is a programming contest voluntarily > held by some Kyoto University students. This contest is abbreviated as **K** > yoto **U** niversity **P** rogramming **C** ontest and called KUPC. > > source: _Kyoto University Programming Contest Information_ The problem-preparing committee met to hold this year's KUPC and N problems were proposed there. The problems are numbered from 1 to N and the name of i-th problem is P_i. However, since they proposed too many problems, they decided to divide them into some sets for several contests. They decided to divide this year's KUPC into several KUPCs by dividing problems under the following conditions. * One KUPC provides K problems. * Each problem appears at most once among all the KUPCs. * All the first letters of the problem names in one KUPC must be different. You, one of the committee members, want to hold as many KUPCs as possible. Write a program to find the maximum number of KUPCs that can be held this year.
[{"input": "9 3\n APPLE\n ANT\n ATCODER\n BLOCK\n BULL\n BOSS\n CAT\n DOG\n EGG\n \n\nFor example, three KUPCs can be held by dividing the problems as follows.\n\n * First: `APPLE`, `BLOCK`, `CAT`\n * Second: `ANT`, `BULL`, `DOG`\n * Third: `ATCODER`, `BOSS`, `EGG`", "output": "3"}, {"input": "3 2\n KU\n KYOUDAI\n KYOTOUNIV", "output": "0\n \n\nNo KUPC can be held."}]
Print the maximum number of KUPCs that can be held on one line. * * *
s582708043
Wrong Answer
p03976
The input is given from Standard Input in the following format: N K P_1 : P_N
n, K = [int(x) for x in input().split()] ans = 0 from collections import defaultdict d = defaultdict(int) for i in [0] * n: d[input()[0]] += 1 while True: for j, _ in zip(sorted(d.items(), key=lambda x: x[1], reverse=True), [0] * K): k, v = j if v == 0 or len(d) < K: print(ans // K) import sys sys.exit() print(k, v) ans += 1 d[k] -= 1
Statement > Kyoto University Programming Contest is a programming contest voluntarily > held by some Kyoto University students. This contest is abbreviated as **K** > yoto **U** niversity **P** rogramming **C** ontest and called KUPC. > > source: _Kyoto University Programming Contest Information_ The problem-preparing committee met to hold this year's KUPC and N problems were proposed there. The problems are numbered from 1 to N and the name of i-th problem is P_i. However, since they proposed too many problems, they decided to divide them into some sets for several contests. They decided to divide this year's KUPC into several KUPCs by dividing problems under the following conditions. * One KUPC provides K problems. * Each problem appears at most once among all the KUPCs. * All the first letters of the problem names in one KUPC must be different. You, one of the committee members, want to hold as many KUPCs as possible. Write a program to find the maximum number of KUPCs that can be held this year.
[{"input": "9 3\n APPLE\n ANT\n ATCODER\n BLOCK\n BULL\n BOSS\n CAT\n DOG\n EGG\n \n\nFor example, three KUPCs can be held by dividing the problems as follows.\n\n * First: `APPLE`, `BLOCK`, `CAT`\n * Second: `ANT`, `BULL`, `DOG`\n * Third: `ATCODER`, `BOSS`, `EGG`", "output": "3"}, {"input": "3 2\n KU\n KYOUDAI\n KYOTOUNIV", "output": "0\n \n\nNo KUPC can be held."}]
Print the maximum number of KUPCs that can be held on one line. * * *
s327619133
Wrong Answer
p03976
The input is given from Standard Input in the following format: N K P_1 : P_N
print("test")
Statement > Kyoto University Programming Contest is a programming contest voluntarily > held by some Kyoto University students. This contest is abbreviated as **K** > yoto **U** niversity **P** rogramming **C** ontest and called KUPC. > > source: _Kyoto University Programming Contest Information_ The problem-preparing committee met to hold this year's KUPC and N problems were proposed there. The problems are numbered from 1 to N and the name of i-th problem is P_i. However, since they proposed too many problems, they decided to divide them into some sets for several contests. They decided to divide this year's KUPC into several KUPCs by dividing problems under the following conditions. * One KUPC provides K problems. * Each problem appears at most once among all the KUPCs. * All the first letters of the problem names in one KUPC must be different. You, one of the committee members, want to hold as many KUPCs as possible. Write a program to find the maximum number of KUPCs that can be held this year.
[{"input": "9 3\n APPLE\n ANT\n ATCODER\n BLOCK\n BULL\n BOSS\n CAT\n DOG\n EGG\n \n\nFor example, three KUPCs can be held by dividing the problems as follows.\n\n * First: `APPLE`, `BLOCK`, `CAT`\n * Second: `ANT`, `BULL`, `DOG`\n * Third: `ATCODER`, `BOSS`, `EGG`", "output": "3"}, {"input": "3 2\n KU\n KYOUDAI\n KYOTOUNIV", "output": "0\n \n\nNo KUPC can be held."}]
Print the maximum number of KUPCs that can be held on one line. * * *
s970689352
Runtime Error
p03976
The input is given from Standard Input in the following format: N K P_1 : P_N
afrom collections import Counter n, k = map(int, input().split()) ps = [input() for _ in range(n)] heads = Counter((p[0] for p in ps)) ans = 0 while len(heads) >= k: ans += 1 for h, c in heads.most_common()[:k]: if c==1: heads.pop(h) else: heads[h] -= 1 print(ans)
Statement > Kyoto University Programming Contest is a programming contest voluntarily > held by some Kyoto University students. This contest is abbreviated as **K** > yoto **U** niversity **P** rogramming **C** ontest and called KUPC. > > source: _Kyoto University Programming Contest Information_ The problem-preparing committee met to hold this year's KUPC and N problems were proposed there. The problems are numbered from 1 to N and the name of i-th problem is P_i. However, since they proposed too many problems, they decided to divide them into some sets for several contests. They decided to divide this year's KUPC into several KUPCs by dividing problems under the following conditions. * One KUPC provides K problems. * Each problem appears at most once among all the KUPCs. * All the first letters of the problem names in one KUPC must be different. You, one of the committee members, want to hold as many KUPCs as possible. Write a program to find the maximum number of KUPCs that can be held this year.
[{"input": "9 3\n APPLE\n ANT\n ATCODER\n BLOCK\n BULL\n BOSS\n CAT\n DOG\n EGG\n \n\nFor example, three KUPCs can be held by dividing the problems as follows.\n\n * First: `APPLE`, `BLOCK`, `CAT`\n * Second: `ANT`, `BULL`, `DOG`\n * Third: `ATCODER`, `BOSS`, `EGG`", "output": "3"}, {"input": "3 2\n KU\n KYOUDAI\n KYOTOUNIV", "output": "0\n \n\nNo KUPC can be held."}]
Print the maximum number of KUPCs that can be held on one line. * * *
s560463178
Runtime Error
p03976
The input is given from Standard Input in the following format: N K P_1 : P_N
n, k = map(lambda x: int(x), input().split()) p = [] for i in range(n): p.append(input()) count = 0 while True: if len(p) == 0: break head = [] dummy = p[:] for item in dummy: if not item[0] in head: head.append(item[0]) p.remove(item) if len(head) == k: count += 1 break if len(p) == 0: break if len(head) != k: break print(count) ~ ~
Statement > Kyoto University Programming Contest is a programming contest voluntarily > held by some Kyoto University students. This contest is abbreviated as **K** > yoto **U** niversity **P** rogramming **C** ontest and called KUPC. > > source: _Kyoto University Programming Contest Information_ The problem-preparing committee met to hold this year's KUPC and N problems were proposed there. The problems are numbered from 1 to N and the name of i-th problem is P_i. However, since they proposed too many problems, they decided to divide them into some sets for several contests. They decided to divide this year's KUPC into several KUPCs by dividing problems under the following conditions. * One KUPC provides K problems. * Each problem appears at most once among all the KUPCs. * All the first letters of the problem names in one KUPC must be different. You, one of the committee members, want to hold as many KUPCs as possible. Write a program to find the maximum number of KUPCs that can be held this year.
[{"input": "9 3\n APPLE\n ANT\n ATCODER\n BLOCK\n BULL\n BOSS\n CAT\n DOG\n EGG\n \n\nFor example, three KUPCs can be held by dividing the problems as follows.\n\n * First: `APPLE`, `BLOCK`, `CAT`\n * Second: `ANT`, `BULL`, `DOG`\n * Third: `ATCODER`, `BOSS`, `EGG`", "output": "3"}, {"input": "3 2\n KU\n KYOUDAI\n KYOTOUNIV", "output": "0\n \n\nNo KUPC can be held."}]
Print one string with the maximum possible doctoral and postdoctoral quotient among the strings that can be obtained by replacing each `?` in T with `P` or `D`. If there are multiple such strings, you may print any of them. * * *
s151571039
Wrong Answer
p02664
Input is given from Standard Input in the following format: T
t = input() u = list(t) if u[0] == "?": u[0] = "D" if u[-1] == "?": u[-1] = "D" for i in range(1, len(u) - 1): if u[i] == "?": if u[i - 1] == "P": u[i] = "D" elif u[i + 1] == "D": u[i] = "P"
Statement For a string S consisting of the uppercase English letters `P` and `D`, let the _doctoral and postdoctoral quotient_ of S be the total number of occurrences of `D` and `PD` in S as contiguous substrings. For example, if S = `PPDDP`, it contains two occurrences of `D` and one occurrence of `PD` as contiguous substrings, so the doctoral and postdoctoral quotient of S is 3. We have a string T consisting of `P`, `D`, and `?`. Among the strings that can be obtained by replacing each `?` in T with `P` or `D`, find one with the maximum possible doctoral and postdoctoral quotient.
[{"input": "PD?D??P", "output": "PDPDPDP\n \n\nThis string contains three occurrences of `D` and three occurrences of `PD` as\ncontiguous substrings, so its doctoral and postdoctoral quotient is 6, which\nis the maximum doctoral and postdoctoral quotient of a string obtained by\nreplacing each `?` in T with `P` or `D`.\n\n* * *"}, {"input": "P?P?", "output": "PDPD"}]
Print one string with the maximum possible doctoral and postdoctoral quotient among the strings that can be obtained by replacing each `?` in T with `P` or `D`. If there are multiple such strings, you may print any of them. * * *
s758837073
Runtime Error
p02664
Input is given from Standard Input in the following format: T
text = list(input()) if text[0] == "?": if text[1] == "D": text[0] = "P" else: text[0] = "D" if text[len(text) - 1] == "?": if text[len(text) - 2] == "?" and text[len(text) - 3] == "P": text[len(text) - 2] = "D" text[len(text) - 1] = "D" elif text[len(text) - 2] == "?" and text[len(text) - 3] != "P": text[len(text) - 2] = "P" text[len(text) - 1] = "D" for i in range(1, len(text)): if text[i] == "?": if text[i - 1] == "P" or text[i - 1] == "D" or text[i + 1] == "P": text[i] = "D" elif text[i + 1] == "D": text[i] = "P" elif text[i + 1] == "?": text[i + 1] = "D" text[i] = "P" if text[i + 2] == "?": text[i + 1] = "D" text[i] = "P" print("".join(text))
Statement For a string S consisting of the uppercase English letters `P` and `D`, let the _doctoral and postdoctoral quotient_ of S be the total number of occurrences of `D` and `PD` in S as contiguous substrings. For example, if S = `PPDDP`, it contains two occurrences of `D` and one occurrence of `PD` as contiguous substrings, so the doctoral and postdoctoral quotient of S is 3. We have a string T consisting of `P`, `D`, and `?`. Among the strings that can be obtained by replacing each `?` in T with `P` or `D`, find one with the maximum possible doctoral and postdoctoral quotient.
[{"input": "PD?D??P", "output": "PDPDPDP\n \n\nThis string contains three occurrences of `D` and three occurrences of `PD` as\ncontiguous substrings, so its doctoral and postdoctoral quotient is 6, which\nis the maximum doctoral and postdoctoral quotient of a string obtained by\nreplacing each `?` in T with `P` or `D`.\n\n* * *"}, {"input": "P?P?", "output": "PDPD"}]
Print one string with the maximum possible doctoral and postdoctoral quotient among the strings that can be obtained by replacing each `?` in T with `P` or `D`. If there are multiple such strings, you may print any of them. * * *
s151868983
Runtime Error
p02664
Input is given from Standard Input in the following format: T
PD = input() print(PD.replase("?", "D"))
Statement For a string S consisting of the uppercase English letters `P` and `D`, let the _doctoral and postdoctoral quotient_ of S be the total number of occurrences of `D` and `PD` in S as contiguous substrings. For example, if S = `PPDDP`, it contains two occurrences of `D` and one occurrence of `PD` as contiguous substrings, so the doctoral and postdoctoral quotient of S is 3. We have a string T consisting of `P`, `D`, and `?`. Among the strings that can be obtained by replacing each `?` in T with `P` or `D`, find one with the maximum possible doctoral and postdoctoral quotient.
[{"input": "PD?D??P", "output": "PDPDPDP\n \n\nThis string contains three occurrences of `D` and three occurrences of `PD` as\ncontiguous substrings, so its doctoral and postdoctoral quotient is 6, which\nis the maximum doctoral and postdoctoral quotient of a string obtained by\nreplacing each `?` in T with `P` or `D`.\n\n* * *"}, {"input": "P?P?", "output": "PDPD"}]