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 maximum possible sum of the values of items that Taro takes home. * * *
s477159195
Accepted
p03164
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
##################################################################################################### ##### ナップサック問題 (価値が小さい場合) ##################################################################################################### """ 経路を状態の添え字に取るような事は無い 経路の末端の情報のみを横軸の添え字に取ることが多い 例:一年生 ⇒ k項目までの総和 パスタ ⇒ k日目に食べたパスタ 暑い日々⇒ k日目に着た服 DPテーブルにおいて、ある値以降の全てで 1 となる場合、 その値でDPテーブルを切ってしまって、 indexがその値を超えるごとに、DPテーブルの上限に +1 をしていくというアイデアで計算量を減らせる 例: https://atcoder.jp/contests/tdpc/submissions/14958104 初期条件を常に意識するように! ベンチマーク (重複なし) http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4641577#1 (重複あり) http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4641577#1 """ import sys input = sys.stdin.readline M, W = map(int, input().split()) # M: 品物の種類 W: 重量制限 single = True # True = 重複なし price_list = [0] weight_list = [0] for _ in range(M): weight, price = map(int, input().split()) price_list.append(price) weight_list.append(weight) ################################################################################################################################################ V = sum(price_list) dp_max = W + 1 # 総和重量の最大値 dp = [ [dp_max] * (V + 1) for _ in range(M + 1) ] # 左端と上端の境界条件で W, M を一個ずつ多めに取る """ dp[item <= M ][weight <= V] = 価値を固定した時の"最小"重量 """ for item in range(M + 1): # 左端の境界条件 dp[item][0] = 0 # 価値 0 を実現するのに必要な品物の個数は 0 個 # for weight in range(W+1): # 上端の境界条件 # dp[0][weight] = dp_min # 0 種類の品物で実現できる価値総額は存在しない (dpの初期化で自動的に課せる場合が多い) for item in range( 1, M + 1 ): # 境界条件を除いた M 回のループ(※ f[item] = g.f[item-i] の漸化式なので、list index out of range となる) for price in range(1, V + 1): if ( price < price_list[item] ): # price (総価値) < price_list[item] (品物の価値) の時は無視してよい dp[item][price] = dp[item - 1][price] else: temp = ( dp[item - single][price - price_list[item]] + weight_list[item] ) # single = True: 重複なし if temp < dp[item - 1][price]: # min(dp[item-1][price], temp) dp[item][price] = temp else: dp[item][price] = dp[item - 1][price] print(max(price for price in range(V + 1) if dp[M][price] <= W))
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "1 1000000000\n 1000000000 10", "output": "10\n \n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s657125616
Accepted
p03164
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
# -*- coding: utf-8 -*- import numpy as np EDPC = "https://atcoder.jp/contests/DP/" TDPC = "https://atcoder.jp/contests/tdpc/tasks" ############### TESTCASE ############### test = "" # test = \ """ 3 8 3 3 4 5 5 6 ans 9 """ """ 6 15 6 5 5 6 6 4 6 6 3 5 7 2 ans 17 """ """ N<100, W<10*9 wi<10**9, vi<10**3 """ ######################################## test = list(reversed(test.strip().splitlines())) if test: def input2(): return test.pop() else: def input2(): return input() ######################################## # np.maximum(*arrays) == np.max(np.vstack(*arrays), axis=0) # (np.maximum(np.array([1,3,2]), np.array([2, 1, 3])) == # np.max(np.vstack([np.array([1,3,2]), np.array([2, 1, 3])]), axis=0)).all() ################# MAIN ################# N, W = map(int, input2().split()) WV = np.array([tuple(map(int, input2().split())) for _ in range(N)], dtype="int64") Wsum = np.sum(WV[:, 0]) Vsum = np.sum(WV[:, 1]) dp = np.full(Vsum + 1, Wsum, dtype="int64") for w, v in WV: dp[: Vsum - v + 1] = np.min(np.vstack([dp[: Vsum - v + 1], dp[v:] - w]), axis=0) print(np.where(dp < W + 1)[0][-1])
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "1 1000000000\n 1000000000 10", "output": "10\n \n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s386386076
Wrong Answer
p03164
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
import sys import heapq import re from heapq import heapify, heappop, heappush from itertools import permutations from bisect import bisect_left, bisect_right from collections import Counter, deque from fractions import gcd from math import factorial, sqrt, ceil from functools import lru_cache, reduce INF = 1 << 60 MOD = 1000000007 sys.setrecursionlimit(10**7) # UnionFind class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) # ダイクストラ def dijkstra_heap(s, edge, n): # 始点sから各頂点への最短距離 d = [10**20] * n used = [True] * n # True:未確定 d[s] = 0 used[s] = False edgelist = [] for a, b in edge[s]: heapq.heappush(edgelist, a * (10**6) + b) while len(edgelist): minedge = heapq.heappop(edgelist) # まだ使われてない頂点の中から最小の距離のものを探す if not used[minedge % (10**6)]: continue v = minedge % (10**6) d[v] = minedge // (10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1]) return d # 素因数分解 def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr # 2数の最小公倍数 def lcm(x, y): return (x * y) // gcd(x, y) # リストの要素の最小公倍数 def lcm_list(numbers): return reduce(lcm, numbers, 1) # リストの要素の最大公約数 def gcd_list(numbers): return reduce(gcd, numbers) # 素数判定 def is_prime(n): if n <= 1: return False p = 2 while True: if p**2 > n: break if n % p == 0: return False p += 1 return True # limit以下の素数を列挙 def eratosthenes(limit): A = [i for i in range(2, limit + 1)] P = [] while True: prime = min(A) if prime > sqrt(limit): break P.append(prime) i = 0 while i < len(A): if A[i] % prime == 0: A.pop(i) continue i += 1 for a in A: P.append(a) return P # 同じものを含む順列 def permutation_with_duplicates(L): if L == []: return [[]] else: ret = [] # set(集合)型で重複を削除、ソート S = sorted(set(L)) for i in S: data = L[:] data.remove(i) for j in permutation_with_duplicates(data): ret.append([i] + j) return ret # ここから書き始める n, w = map(int, input().split()) dp = [[INF for j in range(10**5 + 1)] for i in range(n)] for i in range(n): weight, value = map(int, input().split()) if i == 0: dp[i][value] = weight continue for j in range(10**5 + 1): dp[i][j] = dp[i - 1][j] if 0 <= j - value: dp[i][j] = min(dp[i][j], dp[i - 1][j - value] + weight) ans = 0 # print(dp) for i in reversed(range(10**5 + 1)): if dp[-1][i] <= w: ans = i break print(ans)
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "1 1000000000\n 1000000000 10", "output": "10\n \n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s216080976
Wrong Answer
p03164
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
# coding: utf-8 # Your code here! [n, w] = list(map(int, input().split())) vl = [] wl = [] maxval = 1000 * n INF = 10**9 * n dp = [[INF for j in range(n + 1)] for val in range(maxval + 1)] for item in range(n + 1): dp[0][item] = 0 for _ in range(n): [t1, t2] = list(map(int, input().split())) wl.append(t1) vl.append(t2) vmax = -1 for val in range(1, maxval + 1): for item in range(1, item + 1): if val < vl[item - 1]: dp[val][item] = dp[val][item - 1] else: dp[val][item] = min( dp[val - vl[item - 1]][item - 1] + wl[item - 1], dp[val][item - 1] ) if dp[val][item] <= w: vmax = val print(vmax)
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "1 1000000000\n 1000000000 10", "output": "10\n \n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s089234415
Wrong Answer
p03164
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
###################################################### ############Created by Devesh Kumar################### #############devesh1102@gmail.com#################### ##########For CodeForces(Devesh1102)################# #####################2020############################# ###################################################### import sys input = sys.stdin.readline # import sys import heapq import copy import math import decimal # import sys.stdout.flush as flush # from decimal import * # heapq.heapify(li) # # heapq.heappush(li,4) # # heapq.heappop(li) # # & Bitwise AND Operator 10 & 7 = 2 # | Bitwise OR Operator 10 | 7 = 15 # ^ Bitwise XOR Operator 10 ^ 7 = 13 # << Bitwise Left Shift operator 10<<2 = 40 # >> Bitwise Right Shift Operator # '''############ ---- Input Functions ---- #######Start#####''' def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return list(s[: len(s) - 1]) def insr2(): s = input() return s[: len(s) - 1] def invr(): return map(int, input().split()) ############ ---- Input Functions ---- #######End # ##### def pr_list(a): print(*a, sep=" ") def main(): # tests = inp() tests = 1 mod = 998244353 limit = 10**18 ans = 0 for test in range(tests): [n, w] = inlt() val = [] maxi = 0 for i in range(n): a = inlt() maxi = maxi + a[0] val.append(a) if w >= maxi: print(maxi) continue dp = [[-1 for i in range(w + 3)] for j in range(2)] dp[0][0] = 0 ans = 0 for i in range(n): for j in range(w + 3): dp[(i + 1) % 2][j] = max(dp[(i + 1) % 2][j], dp[(i) % 2][j]) if dp[i % 2][j] != -1 and j + val[i][0] <= w: dp[(i + 1) % 2][j + val[i][0]] = max( dp[(i) % 2][j + val[i][0]], dp[(i) % 2][j] + val[i][1] ) ans = max(ans, dp[(i + 1) % 2][j + val[i][0]]) print(ans) if __name__ == "__main__": main()
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "1 1000000000\n 1000000000 10", "output": "10\n \n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
If the objective is achievable, print `YES`; if it is unachievable, print `NO`. * * *
s235924624
Accepted
p03534
Input is given from Standard Input in the following format: S
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**15 mod = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): s = S() c = collections.Counter(s) if len(c) == 1: if len(s) == 1: return "YES" return "NO" if len(c) == 2: if len(s) <= 2: return "YES" return "NO" if max(c.values()) - min(c.values()) <= 1: return "YES" return "NO" print(main())
Statement Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
[{"input": "abac", "output": "YES\n \n\nAs it stands now, S contains a palindrome `aba`, but we can permute the\ncharacters to get `acba`, for example, that does not contain a palindrome of\nlength 2 or more.\n\n* * *"}, {"input": "aba", "output": "NO\n \n\n* * *"}, {"input": "babacccabab", "output": "YES"}]
If the objective is achievable, print `YES`; if it is unachievable, print `NO`. * * *
s956795678
Runtime Error
p03534
Input is given from Standard Input in the following format: S
#!/usr/bin/env python3 A, B = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) dp = [[0] * (B + 1) for _ in range(A + 1)] for i in range(A)[::-1]: dp[i][B] = dp[i + 1][B] + a[i] if (i + B) % 2 == 0 else dp[i + 1][B] for j in range(B)[::-1]: dp[A][j] = dp[A][j + 1] + b[j] if (A + j) % 2 == 0 else dp[A][j + 1] for i in range(A)[::-1]: for j in range(B)[::-1]: dp[i][j] = ( max(dp[i + 1][j] + a[i], dp[i][j + 1] + b[j]) if (i + j) % 2 == 0 else min(dp[i + 1][j], dp[i][j + 1]) ) print(dp[0][0])
Statement Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
[{"input": "abac", "output": "YES\n \n\nAs it stands now, S contains a palindrome `aba`, but we can permute the\ncharacters to get `acba`, for example, that does not contain a palindrome of\nlength 2 or more.\n\n* * *"}, {"input": "aba", "output": "NO\n \n\n* * *"}, {"input": "babacccabab", "output": "YES"}]
If the objective is achievable, print `YES`; if it is unachievable, print `NO`. * * *
s771936914
Runtime Error
p03534
Input is given from Standard Input in the following format: S
rom collections import Counter s = input().strip() c = Counter(s) v = list(c.values()) if max(v) - min(v) > 1: print("NO") else: print("YES")
Statement Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
[{"input": "abac", "output": "YES\n \n\nAs it stands now, S contains a palindrome `aba`, but we can permute the\ncharacters to get `acba`, for example, that does not contain a palindrome of\nlength 2 or more.\n\n* * *"}, {"input": "aba", "output": "NO\n \n\n* * *"}, {"input": "babacccabab", "output": "YES"}]
For each input positive integer, output a line containing two integers separated by a space. The first integer should be the least number of tetrahedral numbers to represent the input integer as their sum. The second integer should be the least number of odd tetrahedral numbers to represent the input integer as their sum. No extra characters should appear in the output.
s961865082
Runtime Error
p00748
The input is a sequence of lines each of which contains a single positive integer less than 106. The end of the input is indicated by a line containing a single zero.
while True: target = int(input()) if target == 0: break pascal = [] tmp = 1 nexpas = 1 oddpas = [] while target >= nexpas: pascal.append(nexpas) if nexpas % 2 == 1: oddpas.append(nexpas) tmp += 1 nexpas = (tmp * (tmp + 1) * (tmp + 2)) // 6 length = len(pascal) dp = [float("inf") for n in range(target + 1)] ans = -1 for i in range(length): dp[pascal[i]] = 1 if pascal[i] == target: ans = 1 cnt = 0 while cnt < 10: # print(dp) cnt += 1 tmpdp = dp[:] if ans != -1: break else: for outer in range(target + 1): if dp[outer] != float("inf"): nowcnt = dp[outer] for i in range(length): nextnum = outer + pascal[i] if nextnum > target: break elif nextnum == target: ans = nowcnt + 1 break tmpdp[nextnum] = min(dp[nextnum], nowcnt + 1) # print(dp,tmpdb) dp = tmpdp oddlen = len(oddpas) odddp = [float("inf") for n in range(target + 1)] oddans = -1 for i in range(oddlen): odddp[oddpas[i]] = 1 if oddpas[i] == target: oddans = 1 cnt = 0 # print(oddpas) while cnt < 50: # print(odddp) cnt += 1 tmpdp = odddp[:] if oddans != -1: break else: for outer in range(target + 1): if odddp[outer] != float("inf"): nowcnt = odddp[outer] for i in range(oddlen): nextnum = outer + oddpas[i] # print(nextnum) if nextnum > target: break elif nextnum == target: oddans = nowcnt + 1 break tmpdp[nextnum] = min(odddp[nextnum], nowcnt + 1) odddp = tmpdp print(str(ans) + " " + str(oddans)) # print(odddp,oddpas,oddans,target) # print(dp,pascal,ans,target)
C: Pollock's conjecture The _n_ th triangular number is defined as the sum of the first _n_ positive integers. The _n_ th tetrahedral number is defined as the sum of the first _n_ triangular numbers. It is easy to show that the _n_ th tetrahedral number is equal to _n_(_n_ +1)(_n_ +2) ⁄ 6\. For example, the 5th tetrahedral number is 1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+3+4+5) = 5×6×7 ⁄ 6 = 35. The first 5 triangular numbers 1, 3, 6, 10, 15 ![Tr\[1\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-11) ![Tr\[2\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-12) ![Tr\[3\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-13) ![Tr\[4\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-14) ![Tr\[5\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-15) The first 5 tetrahedral numbers 1, 4, 10, 20, 35 ![Tet\[1\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-1) ![Tet\[2\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-2) ![Tet\[3\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-3) ![Tet\[4\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-4) ![Tet\[5\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-5) In 1850, Sir Frederick Pollock, 1st Baronet, who was not a professional mathematician but a British lawyer and Tory (currently known as Conservative) politician, conjectured that every positive integer can be represented as the sum of at most five tetrahedral numbers. Here, a tetrahedral number may occur in the sum more than once and, in such a case, each occurrence is counted separately. The conjecture has been open for more than one and a half century. Your mission is to write a program to verify Pollock's conjecture for individual integers. Your program should make a calculation of the least number of tetrahedral numbers to represent each input integer as their sum. In addition, for some unknown reason, your program should make a similar calculation with only odd tetrahedral numbers available. For example, one can represent 40 as the sum of 2 tetrahedral numbers, 4×5×6 ⁄ 6 + 4×5×6 ⁄ 6, but 40 itself is not a tetrahedral number. One can represent 40 as the sum of 6 odd tetrahedral numbers, 5×6×7 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6, but cannot represent as the sum of fewer odd tetrahedral numbers. Thus, your program should report 2 and 6 if 40 is given.
[{"input": "14\n 5\n 165\n 120\n 103\n 106\n 139\n 0", "output": "6\n 2 14\n 2 5\n 1 1\n 1 18\n 5 35\n 4 4\n 3 37"}]
For each input positive integer, output a line containing two integers separated by a space. The first integer should be the least number of tetrahedral numbers to represent the input integer as their sum. The second integer should be the least number of odd tetrahedral numbers to represent the input integer as their sum. No extra characters should appear in the output.
s092798434
Accepted
p00748
The input is a sequence of lines each of which contains a single positive integer less than 106. The end of the input is indicated by a line containing a single zero.
import copy item = [i * (i + 1) * (i + 2) // 6 for i in range(1, 181)] q = [] while True: in_ = int(input()) if in_ == 0: break q.append(in_) INIT = 1000 MAX = max(q) + 10 ans = [INIT] * MAX ans[0] = 0 odd_item = [i for i in item if i % 2 == 0] even_item = [i for i in item if not (i % 2 == 0)] for i in even_item: for j in range(0, MAX - i): if ans[j + i] > ans[j] + 1: ans[j + i] = ans[j] + 1 ans_ = copy.deepcopy(ans) for i in odd_item: for j in range(0, MAX - i): if ans[j + i] > ans[j] + 1: ans[j + i] = ans[j] + 1 for i in q: print(ans[i], ans_[i])
C: Pollock's conjecture The _n_ th triangular number is defined as the sum of the first _n_ positive integers. The _n_ th tetrahedral number is defined as the sum of the first _n_ triangular numbers. It is easy to show that the _n_ th tetrahedral number is equal to _n_(_n_ +1)(_n_ +2) ⁄ 6\. For example, the 5th tetrahedral number is 1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+3+4+5) = 5×6×7 ⁄ 6 = 35. The first 5 triangular numbers 1, 3, 6, 10, 15 ![Tr\[1\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-11) ![Tr\[2\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-12) ![Tr\[3\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-13) ![Tr\[4\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-14) ![Tr\[5\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-15) The first 5 tetrahedral numbers 1, 4, 10, 20, 35 ![Tet\[1\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-1) ![Tet\[2\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-2) ![Tet\[3\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-3) ![Tet\[4\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-4) ![Tet\[5\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-5) In 1850, Sir Frederick Pollock, 1st Baronet, who was not a professional mathematician but a British lawyer and Tory (currently known as Conservative) politician, conjectured that every positive integer can be represented as the sum of at most five tetrahedral numbers. Here, a tetrahedral number may occur in the sum more than once and, in such a case, each occurrence is counted separately. The conjecture has been open for more than one and a half century. Your mission is to write a program to verify Pollock's conjecture for individual integers. Your program should make a calculation of the least number of tetrahedral numbers to represent each input integer as their sum. In addition, for some unknown reason, your program should make a similar calculation with only odd tetrahedral numbers available. For example, one can represent 40 as the sum of 2 tetrahedral numbers, 4×5×6 ⁄ 6 + 4×5×6 ⁄ 6, but 40 itself is not a tetrahedral number. One can represent 40 as the sum of 6 odd tetrahedral numbers, 5×6×7 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6, but cannot represent as the sum of fewer odd tetrahedral numbers. Thus, your program should report 2 and 6 if 40 is given.
[{"input": "14\n 5\n 165\n 120\n 103\n 106\n 139\n 0", "output": "6\n 2 14\n 2 5\n 1 1\n 1 18\n 5 35\n 4 4\n 3 37"}]
For each input positive integer, output a line containing two integers separated by a space. The first integer should be the least number of tetrahedral numbers to represent the input integer as their sum. The second integer should be the least number of odd tetrahedral numbers to represent the input integer as their sum. No extra characters should appear in the output.
s960899134
Runtime Error
p00748
The input is a sequence of lines each of which contains a single positive integer less than 106. The end of the input is indicated by a line containing a single zero.
while True: pass
C: Pollock's conjecture The _n_ th triangular number is defined as the sum of the first _n_ positive integers. The _n_ th tetrahedral number is defined as the sum of the first _n_ triangular numbers. It is easy to show that the _n_ th tetrahedral number is equal to _n_(_n_ +1)(_n_ +2) ⁄ 6\. For example, the 5th tetrahedral number is 1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+3+4+5) = 5×6×7 ⁄ 6 = 35. The first 5 triangular numbers 1, 3, 6, 10, 15 ![Tr\[1\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-11) ![Tr\[2\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-12) ![Tr\[3\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-13) ![Tr\[4\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-14) ![Tr\[5\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-15) The first 5 tetrahedral numbers 1, 4, 10, 20, 35 ![Tet\[1\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-1) ![Tet\[2\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-2) ![Tet\[3\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-3) ![Tet\[4\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-4) ![Tet\[5\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-5) In 1850, Sir Frederick Pollock, 1st Baronet, who was not a professional mathematician but a British lawyer and Tory (currently known as Conservative) politician, conjectured that every positive integer can be represented as the sum of at most five tetrahedral numbers. Here, a tetrahedral number may occur in the sum more than once and, in such a case, each occurrence is counted separately. The conjecture has been open for more than one and a half century. Your mission is to write a program to verify Pollock's conjecture for individual integers. Your program should make a calculation of the least number of tetrahedral numbers to represent each input integer as their sum. In addition, for some unknown reason, your program should make a similar calculation with only odd tetrahedral numbers available. For example, one can represent 40 as the sum of 2 tetrahedral numbers, 4×5×6 ⁄ 6 + 4×5×6 ⁄ 6, but 40 itself is not a tetrahedral number. One can represent 40 as the sum of 6 odd tetrahedral numbers, 5×6×7 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6, but cannot represent as the sum of fewer odd tetrahedral numbers. Thus, your program should report 2 and 6 if 40 is given.
[{"input": "14\n 5\n 165\n 120\n 103\n 106\n 139\n 0", "output": "6\n 2 14\n 2 5\n 1 1\n 1 18\n 5 35\n 4 4\n 3 37"}]
For each input positive integer, output a line containing two integers separated by a space. The first integer should be the least number of tetrahedral numbers to represent the input integer as their sum. The second integer should be the least number of odd tetrahedral numbers to represent the input integer as their sum. No extra characters should appear in the output.
s341430311
Runtime Error
p00748
The input is a sequence of lines each of which contains a single positive integer less than 106. The end of the input is indicated by a line containing a single zero.
INIT = 100 query = [] ans = [] while True: q = int(input()) if q == 0: break query.append(q) MAX = max(query) table = [INIT] * (MAX + 1) table[0] = 0 all_item = [i * (i + 1) * (i + 2) // 6 for i in range(1, 181)] odd_item = [i for i in all_item if i % 2] eve_item = [i for i in all_item if not i % 2] for v in odd_item: for j in range(v, MAX + 1): if table[j] > table[j - v] + 1: table[j] = table[j - v] + 1 for q in query: ans.append(table[q]) for v in eve_item: for j in range(v, MAX + 1): if table[j] > table[j - v] + 1: table[j] = table[j - v] + 1 for i, q in enumerate(query): print(table[q], ans[i])
C: Pollock's conjecture The _n_ th triangular number is defined as the sum of the first _n_ positive integers. The _n_ th tetrahedral number is defined as the sum of the first _n_ triangular numbers. It is easy to show that the _n_ th tetrahedral number is equal to _n_(_n_ +1)(_n_ +2) ⁄ 6\. For example, the 5th tetrahedral number is 1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+3+4+5) = 5×6×7 ⁄ 6 = 35. The first 5 triangular numbers 1, 3, 6, 10, 15 ![Tr\[1\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-11) ![Tr\[2\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-12) ![Tr\[3\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-13) ![Tr\[4\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-14) ![Tr\[5\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-15) The first 5 tetrahedral numbers 1, 4, 10, 20, 35 ![Tet\[1\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-1) ![Tet\[2\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-2) ![Tet\[3\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-3) ![Tet\[4\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-4) ![Tet\[5\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-5) In 1850, Sir Frederick Pollock, 1st Baronet, who was not a professional mathematician but a British lawyer and Tory (currently known as Conservative) politician, conjectured that every positive integer can be represented as the sum of at most five tetrahedral numbers. Here, a tetrahedral number may occur in the sum more than once and, in such a case, each occurrence is counted separately. The conjecture has been open for more than one and a half century. Your mission is to write a program to verify Pollock's conjecture for individual integers. Your program should make a calculation of the least number of tetrahedral numbers to represent each input integer as their sum. In addition, for some unknown reason, your program should make a similar calculation with only odd tetrahedral numbers available. For example, one can represent 40 as the sum of 2 tetrahedral numbers, 4×5×6 ⁄ 6 + 4×5×6 ⁄ 6, but 40 itself is not a tetrahedral number. One can represent 40 as the sum of 6 odd tetrahedral numbers, 5×6×7 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6, but cannot represent as the sum of fewer odd tetrahedral numbers. Thus, your program should report 2 and 6 if 40 is given.
[{"input": "14\n 5\n 165\n 120\n 103\n 106\n 139\n 0", "output": "6\n 2 14\n 2 5\n 1 1\n 1 18\n 5 35\n 4 4\n 3 37"}]
For each input positive integer, output a line containing two integers separated by a space. The first integer should be the least number of tetrahedral numbers to represent the input integer as their sum. The second integer should be the least number of odd tetrahedral numbers to represent the input integer as their sum. No extra characters should appear in the output.
s700455742
Wrong Answer
p00748
The input is a sequence of lines each of which contains a single positive integer less than 106. The end of the input is indicated by a line containing a single zero.
print("")
C: Pollock's conjecture The _n_ th triangular number is defined as the sum of the first _n_ positive integers. The _n_ th tetrahedral number is defined as the sum of the first _n_ triangular numbers. It is easy to show that the _n_ th tetrahedral number is equal to _n_(_n_ +1)(_n_ +2) ⁄ 6\. For example, the 5th tetrahedral number is 1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+3+4+5) = 5×6×7 ⁄ 6 = 35. The first 5 triangular numbers 1, 3, 6, 10, 15 ![Tr\[1\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-11) ![Tr\[2\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-12) ![Tr\[3\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-13) ![Tr\[4\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-14) ![Tr\[5\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-15) The first 5 tetrahedral numbers 1, 4, 10, 20, 35 ![Tet\[1\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-1) ![Tet\[2\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-2) ![Tet\[3\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-3) ![Tet\[4\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-4) ![Tet\[5\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-5) In 1850, Sir Frederick Pollock, 1st Baronet, who was not a professional mathematician but a British lawyer and Tory (currently known as Conservative) politician, conjectured that every positive integer can be represented as the sum of at most five tetrahedral numbers. Here, a tetrahedral number may occur in the sum more than once and, in such a case, each occurrence is counted separately. The conjecture has been open for more than one and a half century. Your mission is to write a program to verify Pollock's conjecture for individual integers. Your program should make a calculation of the least number of tetrahedral numbers to represent each input integer as their sum. In addition, for some unknown reason, your program should make a similar calculation with only odd tetrahedral numbers available. For example, one can represent 40 as the sum of 2 tetrahedral numbers, 4×5×6 ⁄ 6 + 4×5×6 ⁄ 6, but 40 itself is not a tetrahedral number. One can represent 40 as the sum of 6 odd tetrahedral numbers, 5×6×7 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6, but cannot represent as the sum of fewer odd tetrahedral numbers. Thus, your program should report 2 and 6 if 40 is given.
[{"input": "14\n 5\n 165\n 120\n 103\n 106\n 139\n 0", "output": "6\n 2 14\n 2 5\n 1 1\n 1 18\n 5 35\n 4 4\n 3 37"}]
For each input positive integer, output a line containing two integers separated by a space. The first integer should be the least number of tetrahedral numbers to represent the input integer as their sum. The second integer should be the least number of odd tetrahedral numbers to represent the input integer as their sum. No extra characters should appear in the output.
s061929825
Accepted
p00748
The input is a sequence of lines each of which contains a single positive integer less than 106. The end of the input is indicated by a line containing a single zero.
from collections import defaultdict, deque sq = [i for i in range(200)] for i in range(199): sq[i + 1] += sq[i] for i in range(199): sq[i + 1] += sq[i] ss = [] for s in sq: if s % 2: ss.append(s) dp = defaultdict(lambda: False) check = defaultdict(lambda: False) for s in sq: dp[s] = True check[s] = True dps = defaultdict(lambda: False) checks = defaultdict(lambda: False) for s in ss: dps[s] = True checks[s] = True def main(n, ss, check, dp): q = deque() q.append((n, 1)) check[n] = True if dp[n]: return 1 while q: a, i = q.pop() for s in ss: aa = a - s if aa <= 0: break if not check[aa]: check[aa] = True q.appendleft((aa, i + 1)) else: if dp[aa]: return i + 1 while 1: n = int(input()) if n == 0: break check = defaultdict(lambda: False) for s in sq: check[s] = True checks = defaultdict(lambda: False) for s in ss: checks[s] = True print(main(n, sq, check, dp), main(n, ss, checks, dps))
C: Pollock's conjecture The _n_ th triangular number is defined as the sum of the first _n_ positive integers. The _n_ th tetrahedral number is defined as the sum of the first _n_ triangular numbers. It is easy to show that the _n_ th tetrahedral number is equal to _n_(_n_ +1)(_n_ +2) ⁄ 6\. For example, the 5th tetrahedral number is 1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+3+4+5) = 5×6×7 ⁄ 6 = 35. The first 5 triangular numbers 1, 3, 6, 10, 15 ![Tr\[1\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-11) ![Tr\[2\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-12) ![Tr\[3\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-13) ![Tr\[4\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-14) ![Tr\[5\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-15) The first 5 tetrahedral numbers 1, 4, 10, 20, 35 ![Tet\[1\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-1) ![Tet\[2\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-2) ![Tet\[3\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-3) ![Tet\[4\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-4) ![Tet\[5\]](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-5) In 1850, Sir Frederick Pollock, 1st Baronet, who was not a professional mathematician but a British lawyer and Tory (currently known as Conservative) politician, conjectured that every positive integer can be represented as the sum of at most five tetrahedral numbers. Here, a tetrahedral number may occur in the sum more than once and, in such a case, each occurrence is counted separately. The conjecture has been open for more than one and a half century. Your mission is to write a program to verify Pollock's conjecture for individual integers. Your program should make a calculation of the least number of tetrahedral numbers to represent each input integer as their sum. In addition, for some unknown reason, your program should make a similar calculation with only odd tetrahedral numbers available. For example, one can represent 40 as the sum of 2 tetrahedral numbers, 4×5×6 ⁄ 6 + 4×5×6 ⁄ 6, but 40 itself is not a tetrahedral number. One can represent 40 as the sum of 6 odd tetrahedral numbers, 5×6×7 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6, but cannot represent as the sum of fewer odd tetrahedral numbers. Thus, your program should report 2 and 6 if 40 is given.
[{"input": "14\n 5\n 165\n 120\n 103\n 106\n 139\n 0", "output": "6\n 2 14\n 2 5\n 1 1\n 1 18\n 5 35\n 4 4\n 3 37"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s538653336
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
from collections import defaultdict as dd n = input() def num_bill(n): n = str(n) ans = sum([int(num) for num in n]) return ans buyer = num_bill(n) buyer_bill = dd(int) for i, s in enumerate(n): buyer_bill[i] = int(s) # print(buyer_bill) seller = 0 for i in range(len(n) - 1, -1, -1): if buyer_bill[i] > 5: buyer -= buyer_bill[i] - 1 buyer_bill[i - 1] += 1 seller += 10 - buyer_bill[i] buyer_bill[i] = 0 # print(buyer_bill, buyer, seller) # print(buyer_bill) print(buyer + seller)
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s195062989
Accepted
p02775
Input is given from Standard Input in the following format: N
ans = 0 s = [int(i) for i in input()[::-1]] + [0] i = 0 while i < len(s): t = s[i] if t <= 4: ans += t i += 1 elif t == 5: if s[i + 1] >= 5: ans += 6 i += 1 t = s[i] while t >= 4: if t == 4: if s[i + 1] < 5: ans += 4 i += 1 break ans += 9 - t i += 1 t = s[i] else: ans += 5 i += 1 elif t > 5: ans += 11 - t i += 1 t = s[i] while t >= 4: if t == 4: if s[i + 1] < 5: ans += 4 i += 1 break ans += 9 - t i += 1 t = s[i] print(ans)
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s751675292
Accepted
p02775
Input is given from Standard Input in the following format: N
""" N = 3456の場合を例に取る。 支払い額もしくはお釣りの一方の1円玉の枚数は0が最適。 支払い枚数をf(N)で書くことにする。 (pay, change) = (...6, ...0)が最適の場合 10円以上で支払額とお釣り金額の差は3450円より、 f(3456) = f(345) + 6 (pay, change) = (...0, ...4)が最適の場合 10円以上で支払額とお釣り金額の差は3460円より、 f(3456) = f(346) + 4 つまり一般に f(3456) = min(f(345) + 6, f(346) + 4) 今回は再帰は10^6回で重いのでdpを行う。具体的には [f(3), f(4)] [f(34), f(35)] = [min(f(3)+4, f(4)+7), min(f(3)+5, f(4)+5)] [f(345), f(346)] = [min(f(34)+5, f(35)+5), min(f(34)+6, f(35)+4)] の2ペアずつ値を保持して小さい方から計算すれば良い。 """ strN = input() # dp最初 n = int(strN[0]) dp = [min(n, 11 - n), min(n + 1, 11 - (n + 1))] # n == 9の場合も成立 for s in strN[1:]: n = int(s) dp = [ min(dp[0] + n, dp[1] + (10 - n)), min(dp[0] + (n + 1), dp[1] + (10 - (n + 1))), ] # 偶然、n == 0 or 9の場合もカバーできてる print(dp[0])
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s560525108
Runtime Error
p02775
Input is given from Standard Input in the following format: N
kuri_now = False cost = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0] kuri = [0, 0, 0, 0, 0, 0.5, 1, 1, 1, 1, 1] result = 0 for digit in reversed(input()): digit = int(digit) if kuri_now == 0: result += cost[digit] kuri_now = kuri[digit] elif kuri_now == 1: result += cost[digit + 1] kuri_now = kuri[digit + 1] else: if cost[digit] <= cost[digit + 1]: result += cost[digit] kuri_now = kuri[digit] else: result += cost[digit + 1] kuri_now = kuri[digit + 1] if kuri_now == 1: result += 1 print(result) kuri_now = False cost = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0] kuri = [0, 0, 0, 0, 0, 0.5, 1, 1, 1, 1, 1] result = 0 for digit in input(): digit = int(digit) if kuri_now == 0: result += cost[digit] kuri_now = kuri[digit] elif kuri_now == 1: result += cost[digit + 1] kuri_now = kuri[digit + 1] else: if cost[digit] <= cost[digit + 1]: result += cost[digit] kuri_now = kuri[digit] else: result += cost[digit + 1] kuri_now = kuri[digit + 1] if kuri_now == 1: result += 1 print(result)
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s295120057
Accepted
p02775
Input is given from Standard Input in the following format: N
l = [0] + [int(i) for i in input()] l.reverse() su = 0 for i in range(len(l)): if l[i] > 5: l[i] = 10 - l[i] l[i + 1] += 1 elif l[i] == 5 and l[i + 1] > 4: l[i + 1] += 1 su += l[i] print(su)
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s656500387
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
n = input() k = 0 pay = 0 n_list = [] for i in n[::-1]: n_list.append(int(i)) n_list.append(0) ans = 0 # for i in range(len(n_list) - 1): # num = n_list[i] # if (num <= 5 and n_list[i + 1] < 5) or num < 5: # ans += num # else: # n_list[i + 1] += 1 # ans += 10 - n_list[i] # k += 1 # # ans += n_list[-1] # print(ans)
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s784966838
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
N = [int(d) for d in input()] print(sum(10 - d if d >= 6 else d for d in N))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s725951145
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
m = [0] + list(input()) n = [int(m[i]) for i in range(len(m))]
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s989837784
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
print("0")
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s227338057
Accepted
p02775
Input is given from Standard Input in the following format: N
S = input().strip() INFTY = 10**8 dp = [[INFTY for _ in range(2)] for _ in range(len(S))] for k in range(10): n = int(S[-1]) if k >= n: dp[0][0] = min(dp[0][0], 2 * k - n) else: dp[0][1] = min(dp[0][1], 2 * k - n + 10) for i in range(1, len(S)): n = int(S[-(1 + i)]) for k in range(10): if k > n: dp[i][0] = min( dp[i][0], 2 * k - n + dp[i - 1][0], k + (k - 1) - n + dp[i - 1][1] ) elif k == n: dp[i][0] = min(dp[i][0], 2 * k - n + dp[i - 1][0]) if n == 0: dp[i][1] = min(dp[i][1], k + (k - 1) % 10 - n + dp[i - 1][1]) else: dp[i][1] = min(dp[i][1], k + 10 - n + k - 1 + dp[i - 1][1]) elif k < n: dp[i][1] = min( dp[i][1], k + 10 - n + k + dp[i - 1][0], k + 10 - n + k - 1 + dp[i - 1][1], ) print(min(dp[len(S) - 1][0], dp[len(S) - 1][1] + 1))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s770100280
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
import sys input_methods = ["clipboard", "file", "key"] using_method = 0 input_method = input_methods[using_method] IN = lambda: map(int, input().split()) mod = 1000000007 # +++++ def main(): s = input() if len(s) == 1: v = int(s) return min(1 + (10 - v), v) cc = [0] * (len(s)) for i in range(len(s)): cc[i] = [0, 0, 0, 0] init = int(s[-1]) sec = int(s[-2]) cc[0] = [0, 0, 10 - init, init] cc[1] = [ (10 - (sec + 1)) + (10 - init), (sec + 1) + (10 - init), (10 - sec) + init, sec + init, ] # pa(cc[1]) sv = s[::-1] sv = sv[2:] for i, c in enumerate(sv): aa, ab, ba, bb = cc[i + 1] # pa((aa.ab,ba,bb)) v = int(c) cc[i + 2] = [ 10 - (v + 1) + min(aa, ba), (v + 1) + min(aa, ba), (10 - v) + min(ab, bb), v + min(ab, bb), ] # pa(cc) if s[0] == "9": cc.append([0, 0, 0, 0]) aa, ab, ba, bb = cc[-2] v = 0 cc[-1] = [ 10 - (v + 1) + min(aa, ba), (v + 1) + min(aa, ba), (10 - v) + min(ab, bb), v + min(ab, bb), ] # pa(cc[-1]) ret = min(cc[-1]) print(ret) # +++++ isTest = False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text = clipboard.get() input_l = input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform == "ios": if input_method == input_methods[0]: ic = input_clipboard() input = lambda: ic.__next__() elif input_method == input_methods[1]: sys.stdin = open("inputFile.txt") else: pass isTest = True else: pass # input = sys.stdin.readline ret = main() if ret is not None: print(ret)
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s215115699
Accepted
p02775
Input is given from Standard Input in the following format: N
n = list(reversed(list(map(int, input())))) k = len(n) dp1, dp2 = [0] * k, [0] * k dp1[0], dp2[0] = n[0], 11 - n[0] for i, x in enumerate(n[1:], 1): dp1[i] = min(x + dp1[i - 1], x + dp2[i - 1]) dp2[i] = min(11 - x + dp1[i - 1], 9 - x + dp2[i - 1]) print(min(dp1[-1], dp2[-1]))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s488206978
Accepted
p02775
Input is given from Standard Input in the following format: N
n = list(input()) r = list(map(int, n))[::-1] ans = 0 k = 0 f = 0 for i in r: i += k if f == 5 and i > 4: i += 1 ans += min(i, 10 - i) k = int(i > 5) f = i print(ans + k)
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s929156983
Accepted
p02775
Input is given from Standard Input in the following format: N
import sys sys.setrecursionlimit(10000000) n = input() # a[i]: ans for n[:i] # a = [0 for i in range(len(n) + 1)] # a[0] = 0 # a[1] = max(a[0] + int(n[0]), (10 - int(n[0])) + 1) # a[2] = max(a[1] + int(n[1]), a[0] + (10 - int(n[1])) + 1) # def inv(n): # n_new = list() # for i in range(len(n)): # if n[i] == '9': # n_new.append(0) # else: # n_new.append(9 - int(n[i])) # for i in range(len(n)): # if n_new[-i] != 9: # n_new[-1] += 1 # break # else: # n_new[-1] = 0 # return ''.join(map(str, n_new)) # def func(n, calc_inv=True): # if len(n) == 0: # return 0 # if calc_inv: # return min(1 + func(inv(n), calc_inv=False), func(n, calc_inv=False)) # else: # return int(n[0]) + func(n[1:]) # print(func(n)) # a = [0 for i in range(len(n) + 1)] # for i in range(len(n)): # if int(n[i]) < 5: # a[i + 1] += int(n[i]) # elif int(n[i]) > 5: # a[i] += 1 # a[i + 1] -= (10 - int(n[i])) # else: # 5 # if a[i] >= 0: # a[i + 1] += 5 # else: # a[i] += 1 # a[i + 1] - 5 # print(a) # print(sum(map(abs, a))) a = [0 for i in range(len(n) + 1)] for i in range(1, len(n) + 1): # print(a) m = int(n[-i]) + a[i - 1] # print(m) if m < 5: a[i - 1] = m elif m > 5: a[i] += 1 a[i - 1] = -(10 - m) else: # 5 if i != len(n) and int(n[-i - 1]) >= 5: a[i] += 1 a[i - 1] = -m else: a[i - 1] = m # print(a[::-1]) print(sum(map(abs, a)))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s419646150
Accepted
p02775
Input is given from Standard Input in the following format: N
nn = [0] + list(map(int, list(input()))) dp0, dp1 = 0, 0 for i in range(len(nn)): dp0, dp1 = nn[i] + min(dp1, dp0), 9 - nn[i] + min(dp1, dp0 + 2) print(min(dp0, dp1))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s968142485
Runtime Error
p02775
Input is given from Standard Input in the following format: N
s = list(map(int, input())) L = len(s) o = s[0] p = 11 - s[1] for i in range(1, L): n = s[i] np = min(o + n, p + n) d = min(p + 9 - n, o + 11 - n) o = np p = d print(min(o, p))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s233136832
Accepted
p02775
Input is given from Standard Input in the following format: N
s = input() nums = list(reversed([int(c) for c in s])) + [0] r = (0, 1) # no borrow, with borrow for i in range(len(nums)): # print(r) next_no_borrow = min(r[0] + nums[i], r[1] + nums[i] + 1) next_borrow = min(10 - nums[i] + r[0], 9 - nums[i] + r[1]) r = (next_no_borrow, next_borrow) print(min(r))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s642899125
Accepted
p02775
Input is given from Standard Input in the following format: N
# import sys # inf = sys.maxsize n = str(input()) # l = len(str(n)) """ a = [] for i in range(l): if m[i] <= 5: a.append(0) elif m[i] > 5: a.append(1) for i in range(l): if i < l-1 and a[i+1] == 1 and m[i] == 5: a[i] = 1 p = [] for i in range(l): if a[i] == 0: if i < l-1 and a[i+1] == 1: p.append(m[i]+1) else: p.append(m[i]) elif a[i] == 1: p.append(0) pp = '' for i in range(l): pp += str(p[i]) if pp[0] == '0': pp = '1' + pp pp = int(pp) oo = pp - n print(pp) print(oo) ppp = [int(str(pp)[i]) for i in range(len(str(pp)))] ooo = [int(str(oo)[i]) for i in range(len(str(oo)))] print(sum(ppp) + sum(ooo)) """ dp = [0, 1] # dp[0]: ちょうど dp[1]: 1多い for i in n: i = int(i) dp0 = dp[0] dp1 = dp[1] dp[0] = min(dp0 + i, dp1 + (10 - i)) dp[1] = min(dp0 + i + 1, dp1 + (10 - i) - 1) print(dp[0])
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s853538676
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
# 0:0 1:1 2:2 3:3 4:4 5:5 6:5 7:4 8:3 9:2 N = input() A = 0 B = 0 for i in range(len(N)): if N[i] == "0": A += 0 if B >= 21: B = 0 if N[i] == "1": A += 1 if B >= 15: B = 0 elif N[i] == "2": A += 2 if B >= 10: B = 0 elif N[i] == "3": A += 3 if B >= 6: B = 0 elif N[i] == "4": A += 4 if B >= 3: B = 0 elif N[i] == "5": A += 5 if B >= 1: B = 0 elif N[i] == "6": A += 4 B += 1 elif N[i] == "7": A += 3 B += 1 elif N[i] == "8": A += 2 B += 1 elif N[i] == "9": A += 1 B += 1 if B >= 1: A += 1 print(A)
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s056432970
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
d, e = 0, 0 for x in input(): d, e = int(x) + min(e, d), 9 - int(x) + min(e, d + 2) print(min(d, e))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s334010714
Accepted
p02775
Input is given from Standard Input in the following format: N
N = input().strip() d = int(N[-1]) count_p = d count_m = 10 - d for i in range(len(N) - 2, -1, -1): d = int(N[i]) new_count_p = min(count_p + d, count_m + (d + 1)) new_count_m = min(count_p + (10 - d), count_m + (10 - (d + 1))) count_p = new_count_p count_m = new_count_m count_m += 1 print(min(count_p, count_m))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s197791203
Accepted
p02775
Input is given from Standard Input in the following format: N
n = input() precise = 0 ok_over = 1 ok_prec = 0 for d in n: d = int(d) new_over = min(precise + d + 1, ok_over + d + 2, ok_over + 9 - d, ok_prec + d + 1) new_prec = min(ok_over + d + 1, ok_prec + d) precise += d ok_over = new_over ok_prec = new_prec ok_over += 1 print(min(precise, ok_over, ok_prec))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s544307072
Runtime Error
p02775
Input is given from Standard Input in the following format: N
import sys input = sys.stdin.readline N, Q = map(int, input().split()) ans = [0] * N ki = [[] for _ in range(N)] for i in range(N - 1): a, b = map(int, input().split()) ki[a - 1].append(b - 1) ki[b - 1].append(a - 1) for i in range(Q): p, q = map(int, input().split()) ans[p - 1] += q # dfs from collections import deque stack = deque([0]) visited = ["False"] * N while stack: ne = stack.popleft() if visited[ne] == "False": visited[ne] = "True" for j in ki[ne]: if visited[j] == "False": ans[j] += ans[ne] stack.append(j) print(*ans)
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s917489349
Runtime Error
p02775
Input is given from Standard Input in the following format: N
""" ika tako X個中のK番目を求めたいが、Xが巨大すぎて全部を実際に計算してられない. 問題は「答えがaだとして、積がa以下となるペアがK個以上できるか?」を チェックする二分探索で求められることがある。 まず問題を仮にAiが全て正として単純化し「積がM以下となるペアが K個以上できるか」を判定する. """ from bisect import bisect def check_neg(m, k, pos, neg, len_pos): less = 0 # m 未満になるペア数 j = 0 for a in neg: d = m // a while j < len_pos and pos[j] <= d: j += 1 if len_pos == j: break less += len_pos - j return less < k def check_pos(m, k, pos, neg, len_pos, len_neg): less_eq = 0 # m 以下になるペア数 j = 0 for i in range(len_pos - 1, -1, -1): a = pos[i] d = m // a while j < len_pos and pos[j] <= d: j += 1 if j == len_pos: less_eq += len_pos * (i + 1) break less_eq += j j = 0 for i in range(len_neg - 1, -1, -1): a = neg[i] d = m // a while j < len_neg and neg[j] <= d: j += 1 if j == len_neg: less_eq += len_neg * (i + 1) break less_eq += j m_sqrt = int(m**0.5) less_eq -= bisect(pos, m_sqrt) less_eq -= bisect(neg, m_sqrt) less_eq //= 2 return less_eq < k def solve(n, k, aaa): pos = [a for a in aaa if a > 0] neg = [a for a in aaa if a < 0] len_pos = len(pos) len_neg = len(neg) neg_mul = len_pos * len_neg pos_mul = len_pos * (len_pos - 1) // 2 + len_neg * (len_neg - 1) // 2 if neg_mul >= k: l = -(10**18) r = 0 while l + 1 < r: m = (l + r) // 2 if check_neg(m, k, pos, neg, len_pos): l = m else: r = m return l elif n * (n - 1) // 2 - pos_mul >= k: return 0 else: k -= n * (n - 1) // 2 - pos_mul l = 0 r = 10**18 neg = [-a for a in neg] neg.reverse() while l + 1 < r: m = (l + r) // 2 if check_pos(m, k, pos, neg, len_pos, len_neg): l = m else: r = m return r n, k = map(int, input().split()) aaa = list(map(int, input().split())) aaa.sort() print(solve(n, k, aaa))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s190543816
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
N = str(input()) L = len(N) ans = 0 dp = [[0, 0] for _ in range(L)] s = list(N) a = int(s[0]) dp[0] = [a, 11 - a] for i in range(1, L): n = int(s[i]) dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + n dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + 10 - n dp[-1][1] += 1 print(min(dp[-1]))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s909408689
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
n = int(input()) lis = [int(str(n)[i]) for i in range(len(str(n)))] li = [0 for i in range(len(str(n)))] l = [0 for i in range(len(str(n)))] maintain_1 = 0 lis.insert(0, 0) for i in range(1, len(str(n)) + 1): if lis[-i] > 5 or (lis[-i] == 5 and lis[-(i + 1)] >= 5): li[-i] = 10 - lis[-i] - maintain_1 l[-i] = 1 - maintain_1 maintain_1 = 1 else: li[-i] = lis[-i] maintain_1 = 0 li.insert(0, 0) for i in range(1, len(str(n)) + 1): if li[-i] == 10: l[-i] = 1 li[-i] = 0 li[-(i + 1)] += l[-i] print(sum(li))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s100448267
Accepted
p02775
Input is given from Standard Input in the following format: N
def s_in(): return input() def n_in(): return int(input()) def l_in(): return list(map(int, input().split())) class Interval: def __init__(self, li): self.li = li self.n = len(li) self.sum_li = [li[0]] for i in range(1, self.n): self.sum_li.append(self.sum_li[i - 1] + li[i]) def sum(self, a, b=None): if b is None: return self.sum(0, a) res = self.sum_li[min(self.n - 1, b - 1)] if a > 0: res -= self.sum_li[a - 1] return res N = s_in()[::-1] n = len(N) dp1 = [0 for _ in range(n)] dp1[0] = int(N[0]) # dp1[i] は i桁目を同じ値だけ使ったとしたときの最小値 dp2 = [0 for _ in range(n)] dp2[0] = 10 - int(N[0]) # dp2[i] は i桁目を繰り上げたとしたときの最小値 for i, s in enumerate(N[1:]): i += 1 m = int(s) dp1[i] = min(dp1[i - 1] + m, dp2[i - 1] + (m + 1)) dp2[i] = min(dp1[i - 1] + (10 - m), dp2[i - 1] + (10 - m - 1)) # print(dp1) # print( dp2) print(min(dp1[n - 1], dp2[n - 1] + 1))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s386166624
Accepted
p02775
Input is given from Standard Input in the following format: N
S = "0" + input() digits = [int(c) for c in S.rstrip("0")] N = len(digits) # Track number of bills necessary to create digits[:i] # Can either pay exact or overpay by one bill to flip the sign of the balance dpPos = [None] * len(digits) dpNeg = [None] * len(digits) dpPos[-1] = digits[-1] dpNeg[-1] = 10 - digits[-1] for place in reversed(range(len(digits) - 1)): # Positive balance case exact = digits[place] overpay = exact + 1 dpPos[place] = min(exact + dpPos[place + 1], overpay + dpNeg[place + 1]) # Negative balance case exact = 10 - digits[place] - 1 overpay = exact + 1 dpNeg[place] = min(exact + dpNeg[place + 1], overpay + dpPos[place + 1]) print(dpPos[0])
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s586711018
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
def sub(line): a, b = line.strip().split() a = [int(item) for item in a] b = [int(item) for item in b] res = "" for i in range(len(b)): flag_a = len(a) - 1 - i flag_b = len(b) - 1 - i if a[flag_a] >= b[flag_b]: res = str(a[flag_a] - b[flag_b]) + res else: res = str(10 + a[flag_a] - b[flag_b]) + res while a[flag_a - 1] == 0: a[flag_a - 1] = 9 flag_a -= 1 a[flag_a - 1] -= 1 for j in range(len(a) - 1 - i - 1, -1, -1): res = str(a[j]) + res zero_flag = 0 for i in range(len(res)): if res[i] != "0": zero_flag = 1 break if zero_flag == 0: return 0 return res[i:] n = input() a = [int(x) for x in n] b = [int(x) for x in sub("1" + "0" * len(n) + " " + n)] s_a = [0] * (len(a)) s_b = [0] * (len(b) + 1) for i in range(len(a)): s_a[i] = s_a[i - 1] + a[i] s_a = [0] + s_a for i in range(len(b) - 1, -1, -1): s_b[i] = s_b[i + 1] + b[i] s_b[-1] = -1 r = 999999999999999999 for x, y in zip(s_a, s_b): r = min(r, x + 1 + y) print(r)
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s781218487
Accepted
p02775
Input is given from Standard Input in the following format: N
N = input() N = "0" + N M = len(N) INF = 10**12 DP1 = [INF] * (M + 1) DP2 = [INF] * (M + 1) DP1[0] = 0 for i in range(M): DP1[i + 1] = min(DP1[i] + int(N[i]), DP2[i] + 10 - int(N[i])) DP2[i + 1] = min(DP1[i] + int(N[i]) + 1, DP2[i] + 9 - int(N[i])) print(min(DP1[M], DP2[M] + 1))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s939969469
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
s = input() for num in s: print(num)
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s762458488
Accepted
p02775
Input is given from Standard Input in the following format: N
n = input() m = len(n) dp0 = [0] * m dp1 = [0] * m dp1[0] = min(int(n[0]) + 2, 11 - int(n[0])) dp0[0] = int(n[0]) for i in range(1, m): dp0[i] = min(dp0[i - 1], dp1[i - 1]) + int(n[i]) if int(n[i]) != 9: dp1[i] = min( dp0[i - 1] + int(n[i]) + 2, dp1[i - 1] + min(int(n[i]) + 2, 9 - int(n[i])) ) else: dp1[i] = dp1[i - 1] print(min(dp0[m - 1], dp1[m - 1]))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the minimum possible number of total banknotes used by you and the clerk. * * *
s888676928
Wrong Answer
p02775
Input is given from Standard Input in the following format: N
P = [0] + list(map(int, list(input()))) n = len(P) C = [0] * n for i in range(n - 1, 0, -1): if P[i] >= 10: P[i - 1] += P[i] // 10 P[i] %= 10 if P[i] >= 6: C[i] = 10 - P[i] P[i] = 0 P[i - 1] += 1 print(sum(P) + sum(C))
Statement In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk.
[{"input": "36", "output": "8\n \n\nIf you give four banknotes of value 10 each, and the clerk gives you back four\nbanknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the\nanswer is 8.\n\n* * *"}, {"input": "91", "output": "3\n \n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one\nbanknote of value 10, a total of three banknotes are used.\n\n* * *"}, {"input": "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170", "output": "243"}]
Print the number of the sequences a that can be obtained after the procedure, modulo 10^9+7. * * *
s309951077
Runtime Error
p03867
The input is given from Standard Input in the following format: N K
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (int i=(int)N-1; i>=0; i--) const ll MOD = pow(10,9)+7; const ll LLINF = pow(2,61)-1; const int INF = pow(2,30)-1; vector<ll> fac; void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; } ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; } ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; } ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- vector<bool> isp; void sieve(int x=pow(10,6)+10) { isp.resize(x,true); isp[0] = false; isp[1] = false; for (int i=2; pow(i,2)<=x; i++) { if (isp[i]) for(int j=2; i*j<=x; j++) isp[i*j] = false; } } // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- ll pnk(ll n, ll k) { ll pn = n, now = 0, result = 1; while (k>=1ll<<now) { if (k&1ll<<now) result = result * pn % MOD; pn = pn * pn % MOD; now++; } return result; } int main() { ll N, K; cin >> N >> K; // map<string, ll> m; // rep(i,1<<N/2) { // string S; rep(j,N/2) S += i&1<<j ? '1' : '0'; // rep(j,N/2) S += S[N/2-1-j]; // rep(j,N) { // m[S]++; // S = S.substr(1) + S[0]; // } // } // cout << m.size() << endl; sieve(); vector<ll> yaku; for (ll i=1; i*i<=N; i++) { if (N%i==0) { yaku.push_back(i); if (i*i!=N) yaku.push_back(N/i); } } sort(all(yaku)); // debug(all(yaku)); ll l = yaku.size(); vector<ll> count(l,0); rep(i,l) { count[i] = pnk(K,(yaku[i]+1)/2); rep(j,i) if (yaku[i]%yaku[j]==0) count[i] = (count[i]-count[j]+MOD) % MOD; } // debug(all(count)); ll result = 0; rep(i,l) result = (result+(yaku[i]%2 ? yaku[i] : yaku[i]/2)*count[i]) % MOD; cout << result << endl; return 0; }
Statement Takahashi and Aoki are going to together construct a sequence of integers. First, Takahashi will provide a sequence of integers a, satisfying all of the following conditions: * The length of a is N. * Each element in a is an integer between 1 and K, inclusive. * a is a _palindrome_ , that is, reversing the order of elements in a will result in the same sequence as the original. Then, Aoki will perform the following operation an arbitrary number of times: * Move the first element in a to the end of a. How many sequences a can be obtained after this procedure, modulo 10^9+7?
[{"input": "4 2", "output": "6\n \n\nThe following six sequences can be obtained:\n\n * (1, 1, 1, 1)\n * (1, 1, 2, 2)\n * (1, 2, 2, 1)\n * (2, 2, 1, 1)\n * (2, 1, 1, 2)\n * (2, 2, 2, 2)\n\n* * *"}, {"input": "1 10", "output": "10\n \n\n* * *"}, {"input": "6 3", "output": "75\n \n\n* * *"}, {"input": "1000000000 1000000000", "output": "875699961"}]
Print the number of the sequences a that can be obtained after the procedure, modulo 10^9+7. * * *
s886808028
Wrong Answer
p03867
The input is given from Standard Input in the following format: N K
import sys def MI(): return map(int, sys.stdin.readline().rstrip().split()) N, K = MI() mod = 10**9 + 7 def divisor(n): # nの約数のリスト res = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res A = divisor(N) d = {} # d[i] = iの約数のリスト(iはNの約数) for a in A: d[a] = divisor(a) prime = [] # Nの素因数のリスト for i in range(2, int(N**0.5) + 1): if N % i == 0: prime.append(i) while N % i == 0: N //= i if N != 1: prime.append(N) mu = {} # mu[i] = μ(i) (iはNの約数) for a in A: b = a r = 1 for p in prime: if b % p == 0: r *= -1 if b // p % p == 0: r = 0 break mu[a] = r ans = 0 for a in A: for b in d[a]: if a % 2 == 0: ans += mu[a // b] * pow(K, (b + 1) // 2, mod) * (a // 2) ans %= mod else: ans += mu[a // b] * pow(K, (b + 1) // 2, mod) * a print(ans)
Statement Takahashi and Aoki are going to together construct a sequence of integers. First, Takahashi will provide a sequence of integers a, satisfying all of the following conditions: * The length of a is N. * Each element in a is an integer between 1 and K, inclusive. * a is a _palindrome_ , that is, reversing the order of elements in a will result in the same sequence as the original. Then, Aoki will perform the following operation an arbitrary number of times: * Move the first element in a to the end of a. How many sequences a can be obtained after this procedure, modulo 10^9+7?
[{"input": "4 2", "output": "6\n \n\nThe following six sequences can be obtained:\n\n * (1, 1, 1, 1)\n * (1, 1, 2, 2)\n * (1, 2, 2, 1)\n * (2, 2, 1, 1)\n * (2, 1, 1, 2)\n * (2, 2, 2, 2)\n\n* * *"}, {"input": "1 10", "output": "10\n \n\n* * *"}, {"input": "6 3", "output": "75\n \n\n* * *"}, {"input": "1000000000 1000000000", "output": "875699961"}]
Print the number of the sequences a that can be obtained after the procedure, modulo 10^9+7. * * *
s467217409
Wrong Answer
p03867
The input is given from Standard Input in the following format: N K
mod = 10**9 + 7 def main(): n, k = map(int, input().split()) if n % 2 == 0: ans = pow(k, n // 2, mod) * (n // 2) ans -= k * (n // 2 - 1) else: ans = pow(k, (n + 1) // 2, mod) * n ans -= k * (n - 1) print(ans) if __name__ == "__main__": main()
Statement Takahashi and Aoki are going to together construct a sequence of integers. First, Takahashi will provide a sequence of integers a, satisfying all of the following conditions: * The length of a is N. * Each element in a is an integer between 1 and K, inclusive. * a is a _palindrome_ , that is, reversing the order of elements in a will result in the same sequence as the original. Then, Aoki will perform the following operation an arbitrary number of times: * Move the first element in a to the end of a. How many sequences a can be obtained after this procedure, modulo 10^9+7?
[{"input": "4 2", "output": "6\n \n\nThe following six sequences can be obtained:\n\n * (1, 1, 1, 1)\n * (1, 1, 2, 2)\n * (1, 2, 2, 1)\n * (2, 2, 1, 1)\n * (2, 1, 1, 2)\n * (2, 2, 2, 2)\n\n* * *"}, {"input": "1 10", "output": "10\n \n\n* * *"}, {"input": "6 3", "output": "75\n \n\n* * *"}, {"input": "1000000000 1000000000", "output": "875699961"}]
Print the minimum total cost to achieve Evi's objective. * * *
s756994538
Accepted
p04025
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list(map(lambda x: x - 1, MII())) ## dp ## def DD2(d1, d2, init=0): return [[init] * d2 for _ in range(d1)] def DD3(d1, d2, d3, init=0): return [DD2(d2, d3, init) for _ in range(d1)] ## math ## def divc(x, y) -> int: return -(-x // y) def divf(x, y) -> int: return x // y def gcd(x, y): while y: x, y = y, x % y return x def lcm(x, y): return x * y // gcd(x, y) def enumerate_divs(n): """Return a tuple list of divisor of n""" return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0] def get_primes(n=10**3): """Return a list of prime numbers n or less""" is_prime = [True] * (n + 1) is_prime[0] = is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] def prime_factor(n): """Return a list of prime factorization numbers of n""" res = [] for i in range(2, int(n**0.5) + 1): while n % i == 0: res.append(i) n //= i if n != 1: res.append(n) return res ## const ## MOD = 10**9 + 7 ## libs ## import itertools as it import functools as ft from collections import deque, Counter from heapq import heapify, heappop, heappush from bisect import bisect_left # ======================================================# def main(): import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list(map(lambda x: x - 1, MII())) ## dp ## def DD2(d1, d2, init=0): return [[init] * d2 for _ in range(d1)] def DD3(d1, d2, d3, init=0): return [DD2(d2, d3, init) for _ in range(d1)] ## math ## def divc(x, y) -> int: return -(-x // y) def divf(x, y) -> int: return x // y def gcd(x, y): while y: x, y = y, x % y return x def lcm(x, y): return x * y // gcd(x, y) def enumerate_divs(n): """Return a tuple list of divisor of n""" return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0] def get_primes(n=10**3): """Return a list of prime numbers n or less""" is_prime = [True] * (n + 1) is_prime[0] = is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] def prime_factor(n): """Return a list of prime factorization numbers of n""" res = [] for i in range(2, int(n**0.5) + 1): while n % i == 0: res.append(i) n //= i if n != 1: res.append(n) return res ## const ## MOD = 10**9 + 7 ## libs ## import itertools as it import functools as ft from collections import deque, Counter from heapq import heapify, heappop, heappush from bisect import bisect_left # ======================================================# def main(): n = II() aa = MII() minc = 10**9 for i in range(-100, 101): minc = min(minc, (sum((a - i) ** 2 for a in aa))) print(minc) if __name__ == "__main__": main()
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s814006153
Accepted
p04025
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
# coding: utf-8 # Your code here! # coding: utf-8 from fractions import gcd from functools import reduce import sys sys.setrecursionlimit(200000000) from inspect import currentframe # my functions here! # 標準エラー出力 def printargs2err(*args): names = {id(v): k for k, v in currentframe().f_back.f_locals.items()} print( ", ".join(names.get(id(arg), "???") + " : " + repr(arg) for arg in args), file=sys.stderr, ) def debug(*args): print(*args, file=sys.stderr) def printglobals(): for symbol, value in globals().items(): print('symbol="%s"、value=%s' % (symbol, value), file=sys.stderr) def printlocals(): for symbol, value in locals().items(): print('symbol="%s"、value=%s' % (symbol, value), file=sys.stderr) # 入力(後でいじる) def pin(type=int): return map(type, input().split()) # input def resolve(): N = int(input()) b = sorted(list(pin())) ans = 10000000 for i in range(-100, 101): temp = sum(map(lambda x: pow((i - x), 2), b)) ans = min(ans, temp) print(ans) # print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM]) # if __name__=="__main__":resolve() """ #printデバッグ消した? #前の問題の結果見てないのに次の問題に行くの? """ """ お前カッコ閉じるの忘れてるだろ """ import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """2 4 8""" output = """8""" self.assertIO(input, output) def test_入力例_2(self): input = """3 1 1 3""" output = """3""" self.assertIO(input, output) def test_入力例_3(self): input = """3 4 2 5""" output = """5""" self.assertIO(input, output) def test_入力例_4(self): input = """4 -100 -100 -100 -100""" output = """0""" self.assertIO(input, output) if __name__ == "__main__": resolve()
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s057829753
Runtime Error
p04025
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
n = int(input()) s = len(input()) mod = 10**9 + 7 dp = [[0] * (n + 1) for _ in range(n + 1)] dp[0][0] = 1 for i in range(1, n + 1): dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod for j in range(1, min(n, i + 1)): dp[i][j] = (dp[i - 1][j - 1] * 2 + dp[i - 1][j + 1]) % mod dp[i][n] = dp[i - 1][n - 1] * 2 % mod s2 = pow(2, s, mod) rev = pow(s2, mod - 2, mod) print(dp[n][s] * rev % mod)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s603774779
Wrong Answer
p04025
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
n = int(input()) l = [int(x) for x in input().split()] list.sort(l) x = 200 s = l[0] g = l[-1] for i in range(s, g + 1): y = 0 for j in range(len(l)): y += (l[j] - i) ** 2 if x > y: x = y print(x)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s716868877
Wrong Answer
p04025
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
s = input() t = " " + s[:-1] r = " " + s[:-2] for n, (i, j, k) in enumerate(zip(s, t, r)): if i == j: print(n + 1, n + 2) exit() elif i == k: print(n + 1, n + 3) exit() print(-1, -1)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print `YES` if you can sort p in ascending order in the way stated in the problem statement, and `NO` otherwise. * * *
s873031326
Accepted
p02958
Input is given from Standard Input in the following format: N p_1 p_2 ... p_N
import sys sys.setrecursionlimit(4100000) import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) from copy import copy def resolve(): N = [int(x) for x in sys.stdin.readline().split()][0] p_list = [int(x) for x in sys.stdin.readline().split()] is_broken = False old = p_list[0] for p in p_list[1:]: if old > p: is_broken = True break old = p if not is_broken: print("YES") return for i in range(N): for j in range(N): if i >= j: continue p_list_alt = copy(p_list) p_list_alt[i], p_list_alt[j] = p_list[j], p_list[i] is_broken = False old = p_list_alt[0] for p in p_list_alt[1:]: if old > p: is_broken = True break old = p if not is_broken: print("YES") return print("NO") import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """5 5 2 3 4 1""" output = """YES""" self.assertIO(input, output) def test_入力例_2(self): input = """5 2 4 3 5 1""" output = """NO""" self.assertIO(input, output) def test_入力例_3(self): input = """7 1 2 3 4 5 6 7""" output = """YES""" self.assertIO(input, output) def test_入力例_4(self): input = """2 1 2""" output = """YES""" self.assertIO(input, output) def test_入力例_5(self): input = """2 2 1""" output = """YES""" self.assertIO(input, output) if __name__ == "__main__": resolve() # AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す # python -m unittest template/template.py で実行できる # pypy3 -m unittest template/template.py で実行できる
Statement We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}. You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it. Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.
[{"input": "5\n 5 2 3 4 1", "output": "YES\n \n\nYou can sort p in ascending order by swapping p_1 and p_5.\n\n* * *"}, {"input": "5\n 2 4 3 5 1", "output": "NO\n \n\nIn this case, swapping any two elements does not sort p in ascending order.\n\n* * *"}, {"input": "7\n 1 2 3 4 5 6 7", "output": "YES\n \n\np is already sorted in ascending order, so no operation is needed."}]
Print `YES` if you can sort p in ascending order in the way stated in the problem statement, and `NO` otherwise. * * *
s172657901
Accepted
p02958
Input is given from Standard Input in the following format: N p_1 p_2 ... p_N
n = int(input()) aaa = list(map(int, input().split(" "))) correct_case = [i + 1 for i in range(n)] hoge = sum([a != num for a, num in zip(aaa, correct_case)]) print("YES" if hoge <= 2 else "NO")
Statement We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}. You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it. Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.
[{"input": "5\n 5 2 3 4 1", "output": "YES\n \n\nYou can sort p in ascending order by swapping p_1 and p_5.\n\n* * *"}, {"input": "5\n 2 4 3 5 1", "output": "NO\n \n\nIn this case, swapping any two elements does not sort p in ascending order.\n\n* * *"}, {"input": "7\n 1 2 3 4 5 6 7", "output": "YES\n \n\np is already sorted in ascending order, so no operation is needed."}]
Print `YES` if you can sort p in ascending order in the way stated in the problem statement, and `NO` otherwise. * * *
s273737732
Runtime Error
p02958
Input is given from Standard Input in the following format: N p_1 p_2 ... p_N
a = int(input()) b = input().split(" ") sequence = [] for i in range(0, a): sequence.append(int(b[i])) error = [] for q in range(0, a - 1): if sequence[q] - sequence[q + 1] > 0: error.append(q) error.append(q + 1) if len(error) == 0: print("YES") elif len(error) == 2: if a == 2: print("YES") elif error[0] == 0: if sequence[error[0] + 2] - sequence[error[0]] > 0: print("YES") else: print("NO") elif error[1] == a: if sequence[error[1]] - sequence[error[1] - 2] > 0: print("YES") else: print("NO") else: if ( sequence[error[1]] - sequence[error[1] - 2] > 0 and sequence[error[0] + 2] - sequence[error[0]] > 0 ): print("YES") else: print("NO") elif len(error) == 4: if error[1] == error[2]: if sequence[error[0]] > sequence[error[3]]: if error[0] == 0 and error[3] == a - 1: if ( sequence[error[0]] - sequence[error[3] - 1] > 0 and sequence[error[0] + 1] - sequence[error[3]] > 0 ): print("YES") else: print("NO") elif error[0] == 0: if sequence[error[0] + 3] - sequence[error[0]] > 0: print("YES") else: print("NO") elif error[1] == a: if sequence[error[3]] - sequence[error[3] - 3] > 0: print("YES") else: print("NO") else: if ( sequence[error[3]] - sequence[error[3] - 3] > 0 and sequence[error[0] + 3] - sequence[error[0]] > 0 ): print("YES") else: print("NO") elif ( sequence[error[0]] - sequence[error[2]] > 0 and sequence[error[1]] - sequence[error[3]] > 0 ): if error[0] == 0 and error[3] == a - 1: if ( sequence[error[0]] - sequence[error[3] - 1] > 0 and sequence[error[0] + 1] - sequence[error[3]] > 0 ): print("YES") else: print("NO") elif error[0] == 0: if sequence[error[3] + 1] - sequence[error[0]] > 0: print("YES") else: print("NO") elif error[3] == a: if sequence[error[3]] - sequence[error[0] - 1] > 0: print("YES") else: print("NO") elif ( sequence[error[3]] - sequence[error[0] - 1] > 0 and sequence[error[3] + 1] - sequence[error[0]] > 0 ): print("YES") else: print("NO") else: print("NO") else: print("NO")
Statement We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}. You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it. Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.
[{"input": "5\n 5 2 3 4 1", "output": "YES\n \n\nYou can sort p in ascending order by swapping p_1 and p_5.\n\n* * *"}, {"input": "5\n 2 4 3 5 1", "output": "NO\n \n\nIn this case, swapping any two elements does not sort p in ascending order.\n\n* * *"}, {"input": "7\n 1 2 3 4 5 6 7", "output": "YES\n \n\np is already sorted in ascending order, so no operation is needed."}]
Print `YES` if you can sort p in ascending order in the way stated in the problem statement, and `NO` otherwise. * * *
s127738423
Accepted
p02958
Input is given from Standard Input in the following format: N p_1 p_2 ... p_N
_, p = open(0) print("YNEOS"[sum(i != int(p) for i, p in enumerate(p.split(), 1)) > 2 :: 2])
Statement We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}. You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it. Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.
[{"input": "5\n 5 2 3 4 1", "output": "YES\n \n\nYou can sort p in ascending order by swapping p_1 and p_5.\n\n* * *"}, {"input": "5\n 2 4 3 5 1", "output": "NO\n \n\nIn this case, swapping any two elements does not sort p in ascending order.\n\n* * *"}, {"input": "7\n 1 2 3 4 5 6 7", "output": "YES\n \n\np is already sorted in ascending order, so no operation is needed."}]
Print `YES` if you can sort p in ascending order in the way stated in the problem statement, and `NO` otherwise. * * *
s560130881
Runtime Error
p02958
Input is given from Standard Input in the following format: N p_1 p_2 ... p_N
n, d = map(int, input().split()) a = (2 * d) + 1 if n % a == 0: print(int(n / a)) else: print((n // a) + 1)
Statement We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}. You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it. Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.
[{"input": "5\n 5 2 3 4 1", "output": "YES\n \n\nYou can sort p in ascending order by swapping p_1 and p_5.\n\n* * *"}, {"input": "5\n 2 4 3 5 1", "output": "NO\n \n\nIn this case, swapping any two elements does not sort p in ascending order.\n\n* * *"}, {"input": "7\n 1 2 3 4 5 6 7", "output": "YES\n \n\np is already sorted in ascending order, so no operation is needed."}]
The output should be composed of lines, each containing a single integer. No other characters should appear in the output. The output integer corresponding to the input integer _n_ is the number of all representations of _n_ as the sum of at most four positive squares.
s847401391
Wrong Answer
p00820
The input is composed of at most 255 lines, each containing a single positive integer less than 215 , followed by a line containing a single zero. The last line is not a part of the input data.
a = [[0] * 5 for _ in [0] * (1 << 15)] for i in range(int((1 << 15) ** 0.5)): a[i * i][1] += 1 for j in range(i * i + 1, min(4 * i * i + 1, 1 << 15)): for k in range(2, 5): a[j][k] += a[j - i * i][k - 1] while 1: n = int(input()) if n == 0: break print(sum(a[n]))
B: Lagrange's Four-Square Theorem The fact that any positive integer has a representation as the sum of at most four positive squares (i.e. squares of positive integers) is known as Lagrange’s Four-Square Theorem. The first published proof of the theorem was given by Joseph-Louis Lagrange in 1770. Your mission however is not to explain the original proof nor to discover a new proof but to show that the theorem holds for some specific numbers by counting how many such possible representations there are. For a given positive integer n, you should report the number of all representations of n as the sum of at most four positive squares. The order of addition does not matter, e.g. you should consider 42 \+ 32 and 32 \+ 42 are the same representation. For example, let’s check the case of 25. This integer has just three representations 12 +22 +22 +42 , 32 \+ 42 , and 52 . Thus you should report 3 in this case. Be careful not to count 42 \+ 32 and 32 \+ 42 separately.
[{"input": "25\n 2003\n 211\n 20007\n 0", "output": "3\n 48\n 7\n 738"}]
For each test, print the sum of magic points consumed during that test. Output should be in the order the tests are conducted. * * *
s871234339
Runtime Error
p03426
Input is given from Standard Input in the following format: H W D A_{1,1} A_{1,2} ... A_{1,W} : A_{H,1} A_{H,2} ... A_{H,W} Q L_1 R_1 : L_Q R_Q
tmp = list(map(int,input().split())) H,W,D = tmp[0],tmp[1],tmp[2] kiro = [None] * (H*W) As = [] for i in range(H): As.append(list(map(int,input().split()))) for i in range(H): for j in range(W): kiro[As[i][j]-1] = [i,j] Q = int(input()) Ls = [] Rs = [] def mkmk(L,R): ans = 0 for j in range(L,R,D): ans += abs(kiro[j+D-1][0] - kiro[j-1][0]) + abs(kiro[j+D-1][1] - kiro[j-1][1]) return(ans) for i in range(Q): t = list(map(int,input().split())) L = t[0] R = t[1] print(mkmk(L,R))
Statement We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
[{"input": "3 3 2\n 1 4 3\n 2 5 7\n 8 9 6\n 1\n 4 8", "output": "5\n \n\n * 4 is written in Square (1,2).\n\n * 6 is written in Square (3,3).\n\n * 8 is written in Square (3,1).\n\nThus, the sum of magic points consumed during the first test is\n(|3-1|+|3-2|)+(|3-3|+|1-3|)=5.\n\n* * *"}, {"input": "4 2 3\n 3 7\n 1 4\n 5 2\n 6 8\n 2\n 2 2\n 2 2", "output": "0\n 0\n \n\nNote that there may be a test where the piece is not moved at all, and there\nmay be multiple identical tests.\n\n* * *"}, {"input": "5 5 4\n 13 25 7 15 17\n 16 22 20 2 9\n 14 11 12 1 19\n 10 6 23 8 18\n 3 21 5 24 4\n 3\n 13 13\n 2 10\n 13 13", "output": "0\n 5\n 0"}]
For each test, print the sum of magic points consumed during that test. Output should be in the order the tests are conducted. * * *
s697711730
Runtime Error
p03426
Input is given from Standard Input in the following format: H W D A_{1,1} A_{1,2} ... A_{1,W} : A_{H,1} A_{H,2} ... A_{H,W} Q L_1 R_1 : L_Q R_Q
H, W, D = map(int, input().split()) A = [list(map(int, input().split())) for i in range(H)] rA = [[0 for j in range(2)] for i in range(H * W + 1)] S = [0 for i in range(H * W + 1)] for i in range(H): for j in range(W): rA[A[i][j]][0] = i rA[A[i][j]][1] = j Q = int(input()) for i in range(Q): L, R = map(int, input().split()) ans = 0 for j in range(H * W) [L::D]: if j == R: break if S[j]: ans += S[j] break S[j] -= ans ans += abs(rA[j + D][1] - rA[j][1]) + abs(rA[j + D][0] - rA[j][0]) for j in range(H * W)[L::D]: if S[j] > 0: break if j == R break S[j] += ans print (ans)
Statement We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
[{"input": "3 3 2\n 1 4 3\n 2 5 7\n 8 9 6\n 1\n 4 8", "output": "5\n \n\n * 4 is written in Square (1,2).\n\n * 6 is written in Square (3,3).\n\n * 8 is written in Square (3,1).\n\nThus, the sum of magic points consumed during the first test is\n(|3-1|+|3-2|)+(|3-3|+|1-3|)=5.\n\n* * *"}, {"input": "4 2 3\n 3 7\n 1 4\n 5 2\n 6 8\n 2\n 2 2\n 2 2", "output": "0\n 0\n \n\nNote that there may be a test where the piece is not moved at all, and there\nmay be multiple identical tests.\n\n* * *"}, {"input": "5 5 4\n 13 25 7 15 17\n 16 22 20 2 9\n 14 11 12 1 19\n 10 6 23 8 18\n 3 21 5 24 4\n 3\n 13 13\n 2 10\n 13 13", "output": "0\n 5\n 0"}]
For each test, print the sum of magic points consumed during that test. Output should be in the order the tests are conducted. * * *
s219872876
Runtime Error
p03426
Input is given from Standard Input in the following format: H W D A_{1,1} A_{1,2} ... A_{1,W} : A_{H,1} A_{H,2} ... A_{H,W} Q L_1 R_1 : L_Q R_Q
def ACBC_089_D(): _hwd = str(input()).split() _hwd = list(map(int, _hwd)) _area = [] _inifin = [] _mpcount = 0 for i in range(0, _hwd[0]): _aij = str(input()).split() _aij = list(map(int, _aij)) _area += _aij _q = int(input()) for i in range(0, _q): _lrq = str(input().split()) _lrq = list(map(int, _lrq)) for i in range(0, _hwd[0]): if _lrq[0] in _area[i]: _inix = _area[i].index(_lrq[0]) _iniy = i if _lrq[1] in _area[i]: _finx = _area[i].index(_lrq[1]) _finy = i _nowx = _inix _nowy = _iniy for i in range(0, int((_lrq[1] - _lrq[0]) / _hwd[2])): for i in range(1, _hwd[0] + 1): if _lrq[0] + _hwd[2] * i in _area[i]: _nowx = _area[i].index(_lrq[0] + _hwd[2] * i) _nowy = i _mpcount += _nowx + _nowy - _inix - _iniy print(_mpcount) ACBC_089_D()
Statement We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
[{"input": "3 3 2\n 1 4 3\n 2 5 7\n 8 9 6\n 1\n 4 8", "output": "5\n \n\n * 4 is written in Square (1,2).\n\n * 6 is written in Square (3,3).\n\n * 8 is written in Square (3,1).\n\nThus, the sum of magic points consumed during the first test is\n(|3-1|+|3-2|)+(|3-3|+|1-3|)=5.\n\n* * *"}, {"input": "4 2 3\n 3 7\n 1 4\n 5 2\n 6 8\n 2\n 2 2\n 2 2", "output": "0\n 0\n \n\nNote that there may be a test where the piece is not moved at all, and there\nmay be multiple identical tests.\n\n* * *"}, {"input": "5 5 4\n 13 25 7 15 17\n 16 22 20 2 9\n 14 11 12 1 19\n 10 6 23 8 18\n 3 21 5 24 4\n 3\n 13 13\n 2 10\n 13 13", "output": "0\n 5\n 0"}]
For each test, print the sum of magic points consumed during that test. Output should be in the order the tests are conducted. * * *
s007317320
Runtime Error
p03426
Input is given from Standard Input in the following format: H W D A_{1,1} A_{1,2} ... A_{1,W} : A_{H,1} A_{H,2} ... A_{H,W} Q L_1 R_1 : L_Q R_Q
# import numpy as np # import math def getInt(): return int(input()) def getIntList(): return [int(x) for x in input().split()] def zeros(n): return [0] * n def zeros2(n, m): return [zeros(m)] * n # obsoleted zeros((n, m))で代替 def getIntLines(n): return [int(input()) for i in range(n)] def getIntMat(n, m): # n行に渡って、1行にm個の整数 mat = zeros2(n, m) for i in range(n): mat[i] = getIntList() return mat ALPHABET = [chr(i + ord("a")) for i in range(26)] DIGIT = [chr(i + ord("0")) for i in range(10)] N1097 = 10**9 + 7 INF = 10**18 class Debug: def __init__(self): self.debug = True def off(self): self.debug = False def dmp(self, x, cmt=""): if self.debug: if cmt != "": print(cmt, ": ", end="") print(x) return x def prob(): d = Debug() d.off() H, W, D = getIntList() d.dmp((H, W, D), "H, W, D") A = getIntMat(H, W) d.dmp(A) p = zeros(H * W + 1) for i in range(H): for j in range(W): p[A[i][j]] = [i, j] d.dmp(p) Q = getInt() d.dmp(Q) for i in range(Q): mp = 0 L, R = getIntList() intX = A[p[L][0]][p[L][1]] while intX is not R: x = p[intX][0] y = p[intX][1] d.dmp((intX, x, y, mp), "intX, x, y, mp") intX += D nx = p[intX][0] ny = p[intX][1] mp += abs(x - nx) + abs(y - ny) d.dmp((intX, nx, ny, mp), "intX, nx, ny, mp") d.dmp((L, R, mp), "L, R, mp") print(mp) return None ans = prob() if ans is None: pass elif type(ans) == list and ans[0] == "col": for elm in ans[1]: print(elm) else: print(ans)
Statement We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
[{"input": "3 3 2\n 1 4 3\n 2 5 7\n 8 9 6\n 1\n 4 8", "output": "5\n \n\n * 4 is written in Square (1,2).\n\n * 6 is written in Square (3,3).\n\n * 8 is written in Square (3,1).\n\nThus, the sum of magic points consumed during the first test is\n(|3-1|+|3-2|)+(|3-3|+|1-3|)=5.\n\n* * *"}, {"input": "4 2 3\n 3 7\n 1 4\n 5 2\n 6 8\n 2\n 2 2\n 2 2", "output": "0\n 0\n \n\nNote that there may be a test where the piece is not moved at all, and there\nmay be multiple identical tests.\n\n* * *"}, {"input": "5 5 4\n 13 25 7 15 17\n 16 22 20 2 9\n 14 11 12 1 19\n 10 6 23 8 18\n 3 21 5 24 4\n 3\n 13 13\n 2 10\n 13 13", "output": "0\n 5\n 0"}]
For each test, print the sum of magic points consumed during that test. Output should be in the order the tests are conducted. * * *
s580334584
Runtime Error
p03426
Input is given from Standard Input in the following format: H W D A_{1,1} A_{1,2} ... A_{1,W} : A_{H,1} A_{H,2} ... A_{H,W} Q L_1 R_1 : L_Q R_Q
H,W,D = map(int,input().split(" ")) field = [] power = 0 for i in range(W): field.append(list(map(int,input().split(" ")))) Q = int(input()) for i in range(Q): L,R = map(int,input().split(" ")) point = field.index(L) while L =/ R: point = field.index(L) x1 = int(point/W)+1 y1 = point%W + 1 L = L + D point2 = field.index(L) x2 = int(point/W)+1 y2 = point%W + 1 power = power + abs(x1-x2) + abs(y1-y2)
Statement We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
[{"input": "3 3 2\n 1 4 3\n 2 5 7\n 8 9 6\n 1\n 4 8", "output": "5\n \n\n * 4 is written in Square (1,2).\n\n * 6 is written in Square (3,3).\n\n * 8 is written in Square (3,1).\n\nThus, the sum of magic points consumed during the first test is\n(|3-1|+|3-2|)+(|3-3|+|1-3|)=5.\n\n* * *"}, {"input": "4 2 3\n 3 7\n 1 4\n 5 2\n 6 8\n 2\n 2 2\n 2 2", "output": "0\n 0\n \n\nNote that there may be a test where the piece is not moved at all, and there\nmay be multiple identical tests.\n\n* * *"}, {"input": "5 5 4\n 13 25 7 15 17\n 16 22 20 2 9\n 14 11 12 1 19\n 10 6 23 8 18\n 3 21 5 24 4\n 3\n 13 13\n 2 10\n 13 13", "output": "0\n 5\n 0"}]
For each test, print the sum of magic points consumed during that test. Output should be in the order the tests are conducted. * * *
s850874797
Runtime Error
p03426
Input is given from Standard Input in the following format: H W D A_{1,1} A_{1,2} ... A_{1,W} : A_{H,1} A_{H,2} ... A_{H,W} Q L_1 R_1 : L_Q R_Q
h,w,d = map(int, input().split()) a = [[0 for _ in range(w)] for _ in range(h)] masu = {} for i in range(h): a[i] = list(map(int, input().split()) for j in range(w): masu[a[i][j]] = (i,j) """ masu = {} for i in range(h): for j in range(w): masu[a[i][j]] = (i,j) """ point = [0] * (h*w) for i in range(1,h*w-d+1): point[i] = abs(masu[i][0] - masu[i+d][0]) + abs(masu[i][1] - masu[i+d][1]) q = int(input()) ans = [0] * q for i in range(q): l, r = map(int, input().split()) if l == r: ans[i] = 0 else: ans[i] = sum(point[l:r:d]) for i in range(q): print(ans[i])
Statement We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
[{"input": "3 3 2\n 1 4 3\n 2 5 7\n 8 9 6\n 1\n 4 8", "output": "5\n \n\n * 4 is written in Square (1,2).\n\n * 6 is written in Square (3,3).\n\n * 8 is written in Square (3,1).\n\nThus, the sum of magic points consumed during the first test is\n(|3-1|+|3-2|)+(|3-3|+|1-3|)=5.\n\n* * *"}, {"input": "4 2 3\n 3 7\n 1 4\n 5 2\n 6 8\n 2\n 2 2\n 2 2", "output": "0\n 0\n \n\nNote that there may be a test where the piece is not moved at all, and there\nmay be multiple identical tests.\n\n* * *"}, {"input": "5 5 4\n 13 25 7 15 17\n 16 22 20 2 9\n 14 11 12 1 19\n 10 6 23 8 18\n 3 21 5 24 4\n 3\n 13 13\n 2 10\n 13 13", "output": "0\n 5\n 0"}]
For each test, print the sum of magic points consumed during that test. Output should be in the order the tests are conducted. * * *
s105676480
Runtime Error
p03426
Input is given from Standard Input in the following format: H W D A_{1,1} A_{1,2} ... A_{1,W} : A_{H,1} A_{H,2} ... A_{H,W} Q L_1 R_1 : L_Q R_Q
H, W, D, *L = map(int, open("0").read().split()) A = L[: W * H] Q = L[H * W] inf = [] for l, r in zip(*[iter(L[H * W + 1 :])] * 2): inf += [(l, r)] dic = {A[i * W + j]: (i, j) for i in range(H) for j in range(W)} ls = [[] for i in range(D)] for i in range(D): s = i if i != 0 else D ls[i].append(0) m = s n = s while True: n += D if H * W < n: n = s px, py = dic[m] x, y = dic[n] ls[i].append(ls[i][-1] + abs(px - x) + abs(py - y)) m = n if m == s: break for l, r in inf: i = l % D if i == 0: il = (l - D) // D ir = (r - D) // D else: il = (l - i) // D ir = (r - i) // D if l < r: print(ls[i][ir] - ls[i][il]) elif l > r: print(ls[i][-1] - ls[i][il] + ls[i][ir]) else: print(0)
Statement We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
[{"input": "3 3 2\n 1 4 3\n 2 5 7\n 8 9 6\n 1\n 4 8", "output": "5\n \n\n * 4 is written in Square (1,2).\n\n * 6 is written in Square (3,3).\n\n * 8 is written in Square (3,1).\n\nThus, the sum of magic points consumed during the first test is\n(|3-1|+|3-2|)+(|3-3|+|1-3|)=5.\n\n* * *"}, {"input": "4 2 3\n 3 7\n 1 4\n 5 2\n 6 8\n 2\n 2 2\n 2 2", "output": "0\n 0\n \n\nNote that there may be a test where the piece is not moved at all, and there\nmay be multiple identical tests.\n\n* * *"}, {"input": "5 5 4\n 13 25 7 15 17\n 16 22 20 2 9\n 14 11 12 1 19\n 10 6 23 8 18\n 3 21 5 24 4\n 3\n 13 13\n 2 10\n 13 13", "output": "0\n 5\n 0"}]
For each test, print the sum of magic points consumed during that test. Output should be in the order the tests are conducted. * * *
s193308752
Accepted
p03426
Input is given from Standard Input in the following format: H W D A_{1,1} A_{1,2} ... A_{1,W} : A_{H,1} A_{H,2} ... A_{H,W} Q L_1 R_1 : L_Q R_Q
import sys sdin = sys.stdin.readline H, W, D = map(int, sdin().split()) A = [] for h in range(H): A.append(list(map(int, sdin().split()))) Q = int(sdin()) RL = [] for q in range(Q): RL.append(tuple(map(int, sdin().split()))) codn = {} for h in range(H): for w in range(W): codn[A[h][w]] = (h + 1, w + 1) # mod D上での累積和 cums = [] for d in range(D): cum = [] res = D if d != 0: res = d cum = [0] while res + D <= H * W: prev = codn[res] nex = codn[res + D] cost = abs(nex[0] - prev[0]) + abs(nex[1] - prev[1]) cum.append(cum[-1] + cost) res += D cums.append(cum) # 各クエリの処理 ans = 0 for query in range(Q): q = RL[query] mod = q[0] % D start = (q[0] - mod) // D last = (q[1] - mod) // D if mod == 0: start -= 1 last -= 1 ans = cums[mod][last] - cums[mod][start] print(ans)
Statement We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
[{"input": "3 3 2\n 1 4 3\n 2 5 7\n 8 9 6\n 1\n 4 8", "output": "5\n \n\n * 4 is written in Square (1,2).\n\n * 6 is written in Square (3,3).\n\n * 8 is written in Square (3,1).\n\nThus, the sum of magic points consumed during the first test is\n(|3-1|+|3-2|)+(|3-3|+|1-3|)=5.\n\n* * *"}, {"input": "4 2 3\n 3 7\n 1 4\n 5 2\n 6 8\n 2\n 2 2\n 2 2", "output": "0\n 0\n \n\nNote that there may be a test where the piece is not moved at all, and there\nmay be multiple identical tests.\n\n* * *"}, {"input": "5 5 4\n 13 25 7 15 17\n 16 22 20 2 9\n 14 11 12 1 19\n 10 6 23 8 18\n 3 21 5 24 4\n 3\n 13 13\n 2 10\n 13 13", "output": "0\n 5\n 0"}]
For each test, print the sum of magic points consumed during that test. Output should be in the order the tests are conducted. * * *
s311759401
Runtime Error
p03426
Input is given from Standard Input in the following format: H W D A_{1,1} A_{1,2} ... A_{1,W} : A_{H,1} A_{H,2} ... A_{H,W} Q L_1 R_1 : L_Q R_Q
# ■標準入力ショートカット def get_next_int(): return int(float(input())) def get_next_ints(delim=" "): return tuple([int(float(x)) for x in input().split(delim)]) def get_next_str(): return input() def get_next_strs(delim=" "): return tuple(input().split(delim)) def get_next_by_types(*value_types, delim=" "): return tuple([t(x) for t, x in zip(value_types, input().split(delim))]) class PracticalSkillTest: def __init__(self): self.H, self.W, self.D = get_next_ints() self.field = [] for _ in range(self.H): self.field.append(get_next_ints()) self.Q = get_next_int() self.places = [] for _ in range(self.Q): self.places.append(get_next_ints()) self.mapping() self.dp = [[-1] * (self.H * self.W) for i in range(self.H * self.W)] def mapping(self): self.mapping_dic = {} for y in range(self.H): for x in range(self.W): self.mapping_dic[self.field[y][x]] = (x, y) def get_consumption(self, num): start = self.places[num][0] end = self.places[num][1] if self.dp[start][end] != -1: return self.dp[start][end] pos = self.mapping_dic[start] cost = 0 for i in range(start + self.D, end + 1, self.D): next_pos = self.mapping_dic[i] cost += abs(pos[0] - next_pos[0]) + abs(pos[1] - next_pos[1]) pos = next_pos self.dp[start][end] = cost return cost def practice_solve(self): for i in range(self.Q): cost = self.get_consumption(i) print(cost) def solve(): p = PracticalSkillTest() p.practice_solve() solve()
Statement We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
[{"input": "3 3 2\n 1 4 3\n 2 5 7\n 8 9 6\n 1\n 4 8", "output": "5\n \n\n * 4 is written in Square (1,2).\n\n * 6 is written in Square (3,3).\n\n * 8 is written in Square (3,1).\n\nThus, the sum of magic points consumed during the first test is\n(|3-1|+|3-2|)+(|3-3|+|1-3|)=5.\n\n* * *"}, {"input": "4 2 3\n 3 7\n 1 4\n 5 2\n 6 8\n 2\n 2 2\n 2 2", "output": "0\n 0\n \n\nNote that there may be a test where the piece is not moved at all, and there\nmay be multiple identical tests.\n\n* * *"}, {"input": "5 5 4\n 13 25 7 15 17\n 16 22 20 2 9\n 14 11 12 1 19\n 10 6 23 8 18\n 3 21 5 24 4\n 3\n 13 13\n 2 10\n 13 13", "output": "0\n 5\n 0"}]
For each test, print the sum of magic points consumed during that test. Output should be in the order the tests are conducted. * * *
s784217369
Accepted
p03426
Input is given from Standard Input in the following format: H W D A_{1,1} A_{1,2} ... A_{1,W} : A_{H,1} A_{H,2} ... A_{H,W} Q L_1 R_1 : L_Q R_Q
# 座標も数値も全部0-indexedに直す H, W, D = map(int, input().split()) coordinate = [None for _ in range(H * W)] for i in range(H): raw = list(map(int, input().split())) for j in range(W): coordinate[raw[j] - 1] = (i, j) l = H * W // D + 2 cumm = [[0 for _ in range(l)] for _ in range(D)] for i in range(H * W): q, r = divmod(i, D) if q == 0: continue # q>0 x1, y1 = coordinate[i] x0, y0 = coordinate[i - D] distance = abs(x1 - x0) + abs(y1 - y0) cumm[r][q] = cumm[r][q - 1] + distance Q = int(input()) for _ in range(Q): L, R = map(int, input().split()) q0, r0 = divmod(L - 1, D) q1, r1 = divmod(R - 1, D) print(cumm[r1][q1] - cumm[r0][q0])
Statement We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points. You now have to take Q practical tests of your ability as a magical girl. The i-th test will be conducted as follows: * Initially, a piece is placed on the square where the integer L_i is written. * Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. * Here, it is guaranteed that R_i-L_i is a multiple of D. For each test, find the sum of magic points consumed during that test.
[{"input": "3 3 2\n 1 4 3\n 2 5 7\n 8 9 6\n 1\n 4 8", "output": "5\n \n\n * 4 is written in Square (1,2).\n\n * 6 is written in Square (3,3).\n\n * 8 is written in Square (3,1).\n\nThus, the sum of magic points consumed during the first test is\n(|3-1|+|3-2|)+(|3-3|+|1-3|)=5.\n\n* * *"}, {"input": "4 2 3\n 3 7\n 1 4\n 5 2\n 6 8\n 2\n 2 2\n 2 2", "output": "0\n 0\n \n\nNote that there may be a test where the piece is not moved at all, and there\nmay be multiple identical tests.\n\n* * *"}, {"input": "5 5 4\n 13 25 7 15 17\n 16 22 20 2 9\n 14 11 12 1 19\n 10 6 23 8 18\n 3 21 5 24 4\n 3\n 13 13\n 2 10\n 13 13", "output": "0\n 5\n 0"}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s493085877
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
lis = [int(input()) for _ in range(5)] lis = sorted(lis, key=lambda x: (10 - (x % 10)) % 10, reverse=True) lis = [(j + 9) // 10 * 10 if i != 0 else j for i, j in enumerate(lis)] print(sum(lis))
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s569760501
Wrong Answer
p03076
Input is given from Standard Input in the following format: A B C D E
# 10の余りの絶対値でソートできると良いのですが、今のところ検討中です。
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s018293425
Wrong Answer
p03076
Input is given from Standard Input in the following format: A B C D E
L = [int(input()) for i in range(5)] longmenuindex = 0 for i in range(len(L)): if L[i] % 10 < L[longmenuindex] % 10 and L[i] % 10 != 0: longmenuindex = i time = 0 for i in range(len(L)): if i != longmenuindex: time += round(L[i], -1) print(time + L[longmenuindex])
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s740832223
Wrong Answer
p03076
Input is given from Standard Input in the following format: A B C D E
a = eval("int(input())," * 5) print(min(i % 10 for i in a) - 9 - sum(-i // 10 * 10 for i in a))
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s985782847
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
num_list = [int(input()) for _ in range(5)] res = [] zero = [] one = [] two = [] three = [] four = [] five = [] for n in num_list: if n % 10 > 5: res.append(n) for n in num_list: if n % 10 == 0: zero.append(n) elif n % 10 == 1: one.append(n) elif n % 10 == 2: two.append(n) elif n % 10 == 3: three.append(n) elif n % 10 == 4: four.append(n) elif n % 10 == 5: five.append(n) sum = 0 res.extend(zero) res.extend(five) res.extend(four) res.extend(three) res.extend(two) res.extend(one) for i, v in enumerate(res): plus = 0 if v % 10 == 0: pass else: plus = 10 - v % 10 if i == 4: sum += v break else: sum += v + plus print(sum)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s190797173
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
abc = [int(input()) + 9 for x in range(5)] print(sum([x // 10 for x in abc]) * 10 + min([x % 10 for x in abc]) - 9)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s665678147
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
d = list(map(int, open(0))) d.sort(key=lambda x: (x - 1) % 10, reverse=True) print(sum((x + 9) // 10 * 10 for x in d[:-1]) + d[-1])
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s083317927
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
L = [int(input()) for i in range(5)] l = [n % 10 if not (n % 10 == 0) else 100 for n in L] i = l.index(min(l)) I = 10 - (L[i] % 10) + L[i] if not (L[i] % 10 == 0) else L[i] SUM = sum([n + 10 - (n % 10) if not (n % 10 == 0) else n for n in L]) # print(i, I, SUM) ans = SUM - I + L[i] print(ans)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s440691381
Runtime Error
p03076
Input is given from Standard Input in the following format: A B C D E
with open("td3") as f: open0read = f.read() n = list(map(int, open0read.split())) n.sort(key=lambda x: -((x - 1) % 10)) print(sum([((x - 1) // 10 + 1) * 10 for x in n[:-1]] + [n[-1]]))
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s553679518
Wrong Answer
p03076
Input is given from Standard Input in the following format: A B C D E
I = ["{0:03d}".format(int(n)) for n in open(0).read().split()] c = 0 min_z = 9 for i in I: x, y, z = map(int, i) if 0 < z < min_z: min_z = z if 0 < z: y += 1 if 9 < y: x += 1 y -= 10 n = x * 100 + y * 10 c += n print(c + min_z - 10)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s986085861
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
nums = [] flg = True for _ in range(5): nums.append(int(input())) amaris = [] minnum = 10 for num in nums: amaris.append(num % 10) if num % 10 < minnum and num % 10 != 0: minnum = num % 10 count = 0 amari_count = 0 for num, amari in zip(nums, amaris): if amari == 0: count += num amari_count += 1 else: count += (num // 10 + 1) * 10 print(count + minnum - 10)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s653659205
Runtime Error
p03076
Input is given from Standard Input in the following format: A B C D E
read = input a = [read() for i in range(5)] a = list(map(int, a)) if all(map(lambda x: x % 10 == 0, a)): print(sum(a)) else: g10 = list(filter(lambda x: x % 10 > 0, a)) l10 = list(filter(lambda x: x % 10 == 0, a)) m = min(g10, key=lambda x: x % 10) g100 = list(map(lambda x: x // 10 * 10 + 10, g10)) print(sum([*g100, *l10, -m // 10 * 10 + m]))
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s707886689
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x) - 1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) abcde = [ni() for _ in range(5)] wait = [] ans = 0 for i in abcde: if i % 10 == 0: ans += i wait.append(0) else: wait.append(10 - i % 10) ans += 10 * (i // 10 + 1) wait.sort() print(ans - wait[-1])
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s889096915
Wrong Answer
p03076
Input is given from Standard Input in the following format: A B C D E
food = [input() for _ in range(5)] if len(set(food)) == 1: food_check1 = [int(10 - int(food[i][-1])) for i in range(1, len(food))] food_check2 = [int(i) for i in food] print(sum(food_check1) + sum(food_check2)) else: check = [int(i[-1]) for i in food if i[-1] != "0"] food_check1 = [int(i) for i in food if i[-1] != "0"] food_check2 = [ 10 - int(str(i)[-1]) for i in food_check1 if int(str(i)[-1]) != min(check) ] food = [int(i) for i in food] print(sum(food) + sum(food_check2))
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s531969788
Runtime Error
p03076
Input is given from Standard Input in the following format: A B C D E
A_list = [] for i in range(5): A_list.append(input()) one_list = [] one_list.append(int(A_list[0][-1])) one_list.append(int(A_list[1][-1])) one_list.append(int(A_list[2][-1])) one_list.append(int(A_list[3][-1])) one_list.append(int(A_list[4][-1])) min_num = max(one_list) for i in range(len(one_list)): if one_list[i] != 0 and min_num >= one_list[i]: min_num = one_list[i] min_one_list_index = i A_list_min = A_list[min_one_list_index] del A_list[min_one_list_index] def ceil(src, range): return ((int)(src / range) + 1) * range for i in range(len(A_list)): A_list[i] = ceil(int(A_list[i]), 10) print(sum(A_list) + int(A_list_min))
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s032972905
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
a = [int(input()) for _ in range(5)] a.sort(key=lambda x: (x - 1) % 10) print(a[0] + sum(i if i % 10 == 0 else (i // 10 + 1) * 10 for i in a[1:]))
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s139954991
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
A = [int(input()) for _ in range(5)] a = 0 s = 0 for l in A: b = -(-l // 10) * 10 s += b c = b - l if a < c: a = c print(s - a)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s612921246
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
l = list(int(input()) for _ in range(5)) s = list(10 - i % 10 for i in l) for i in range(s.count(10)): s.remove(10) if len(s) > 0: s.remove(max(s)) print(sum(l) + sum(s))
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s764276657
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
I = [int(input()) for _ in range(5)] min_ = 10 cnt = 0 for ii in range(5): mod10 = I[ii] % 10 cnt += I[ii] + (10 - mod10) if mod10 != 0 else I[ii] if min_ > mod10 and mod10 != 0: min_ = mod10 print(cnt - (10 - min_))
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s375494908
Runtime Error
p03076
Input is given from Standard Input in the following format: A B C D E
a = [] for i in range(5): num = input() a.append(num) if ( int(a[0][2]) <= int(a[1][2]) and int(a[0][2]) <= int(a[2][2]) and int(a[0][2]) <= int(a[3][2]) and int(a[0][2]) <= int(a[4][2]) ): b = ( int(a[1]) + 10 - int(a[1][2]) + int(a[2]) + 10 - int(a[2][2]) + int(a[3]) + 10 - int(a[3][2]) + int(a[4]) + 10 - int(a[4][2]) + int(a[0]) ) print(b) elif ( int(a[1][2]) <= int(a[0][2]) and int(a[1][2]) <= int(a[2][2]) and int(a[1][2]) <= int(a[3][2]) and int(a[1][2]) <= int(a[4][2]) ): b = ( int(a[0]) + 10 - int(a[0][2]) + int(a[2]) + 10 - int(a[2][2]) + int(a[3]) + 10 - int(a[3][2]) + int(a[4]) + 10 - int(a[4][2]) + int(a[1]) ) print(b) elif ( int(a[2][2]) <= int(a[0][2]) and int(a[2][2]) <= int(a[1][2]) and int(a[2][2]) <= int(a[3][2]) and int(a[2][2]) <= int(a[4][2]) ): b = ( int(a[0]) + 10 - int(a[0][2]) + int(a[1]) + 10 - int(a[1][2]) + int(a[3]) + 10 - int(a[3][2]) + int(a[4]) + 10 - int(a[4][2]) + int(a[2]) ) print(b) elif ( int(a[3][2]) <= int(a[0][2]) and int(a[3][2]) <= int(a[1][2]) and int(a[3][2]) <= int(a[2][2]) and int(a[3][2]) <= int(a[4][2]) ): b = ( int(a[0]) + 10 - int(a[0][2]) + int(a[1]) + 10 - int(a[1][2]) + int(a[2]) + 10 - int(a[2][2]) + int(a[4]) + 10 - int(a[4][2]) + int(a[3]) ) print(b) elif ( int(a[4][2]) <= int(a[0][2]) and int(a[4][2]) <= int(a[1][2]) and int(a[4][2]) <= int(a[2][2]) and int(a[4][2]) <= int(a[3][2]) ): b = ( int(a[0]) + 10 - int(a[0][2]) + int(a[1]) + 10 - int(a[1][2]) + int(a[2]) + 10 - int(a[2][2]) + int(a[3]) + 10 - int(a[3][2]) + int(a[4]) ) print(b)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s735365697
Wrong Answer
p03076
Input is given from Standard Input in the following format: A B C D E
m = [int(input()) for i in range(5)] k = [9999] * 5 j = [] for i in range(5): j.append(-(-m[i] // 10) * 10) t = m[i] - (m[i] // 10) * 10 if t > 0: k.append(t) if min(k) == 0: print(sum(j)) else: print(sum(j) - (10 - min(k)))
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s537851995
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
#!/usr/bin/env python3 l = [input() for _ in range(5)] m = 11 ans = 0 for i in range(len(l)): n = int(l[i][-1]) if n == 0: n = 10 if n < m: m = n ind = i for t in range(len(l)): if t == ind: ans += int(l[t]) else: n = int(l[t][-1]) if n == 0: n = 10 ans += int(l[t]) + 10 - n print(ans)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s124731772
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
import sys def fceil(b): return int(b / 10) + 1 if b % 10 else b // 10 aD = [int(_) for _ in sys.stdin.readlines()] aDM = sorted(set(_ % 10 for _ in aD)) aD10 = [fceil(_) * 10 for _ in aD] iM = aDM[0] if iM == 0: if 1 < len(aDM): iM = aDM[1] iD = 10 - iM if iM == 0: iD = 0 print(sum(aD10) - iD)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s037728722
Wrong Answer
p03076
Input is given from Standard Input in the following format: A B C D E
l = [input() for _ in [0] * 5] keta = [] for i in l: keta.append(i) # print(keta) xxx = [] for j in keta: if int(j[-1]) != 0: xxx.append(int(j) + (10 - int(j[-1]))) else: xxx.append(int(j)) # print(xxx) yyy = [] for k in keta: yyy.append(int(k[-1])) # print(yyy) zzz = [] for m in yyy: if int(m) > 0: zzz.append(m) # print(zzz) if 0 < sum(zzz): p = min(zzz) else: p = 0 print(sum(xxx) - (10 - p))
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s128710897
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
a, *t = map(int, open(0)) c = 0 for t in t: b = a + t a = a * (0 < a % 10 < t % 10 or t % 10 < 1) or t b -= a c += b + (10 - b % 10) * (b % 10 > 0) print(c + a)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s741271341
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
ABCDE = list(map(int, [input() for i in range(5)])) waiting = [(10 - a) % 10 for a in ABCDE] waiting.sort() waiting.pop() print(sum(waiting) + sum(ABCDE))
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s001129231
Runtime Error
p03076
Input is given from Standard Input in the following format: A B C D E
list = [int(input()) for i in range(5)] sum = sum(list) max = 0 for x in list: y = -(-x // 10) * 10 max = (y - x, max) print(sum - max)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s696053564
Runtime Error
p03076
Input is given from Standard Input in the following format: A B C D E
nums = [int(input()) for _ in range(5)] l = map(int, filter(lambda x: x != "0", [str(n)[-1] for n in nums])) r = [(n + 9) // 10 for n in nums] print(sum(r) * 10 - (10 - min(l))) if len(l) != 0 else print(sum(r) * 10)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]
Print the earliest possible time for the last dish to be delivered, as an integer. * * *
s773897191
Accepted
p03076
Input is given from Standard Input in the following format: A B C D E
Menu = [int(input()) for _ in range(5)] # 届く時間を1の位で切り上げたとき、届く時間の和 time_max = sum(map(lambda x: (x + 9) // 10 * 10, Menu)) # 1の位で切り上げたとき、最も元の時間との差が大きいもの tmp = max(map(lambda x: (x + 9) // 10 * 10 - x, Menu)) print(time_max - tmp)
Statement The restaurant AtCoder serves the following five dishes: * ABC Don (rice bowl): takes A minutes to serve. * ARC Curry: takes B minutes to serve. * AGC Pasta: takes C minutes to serve. * APC Ramen: takes D minutes to serve. * ATC Hanbagu (hamburger patty): takes E minutes to serve. Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered. This restaurant has the following rules on orders: * An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...). * Only one dish can be ordered at a time. * No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered. E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered. Here, he can order the dishes in any order he likes, and he can place an order already at time 0.
[{"input": "29\n 20\n 7\n 35\n 120", "output": "215\n \n\nIf we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta,\nATC Hanbagu, APC Ramen, the earliest possible time for each order is as\nfollows:\n\n * Order ABC Don at time 0, which will be delivered at time 29.\n * Order ARC Curry at time 30, which will be delivered at time 50.\n * Order AGC Pasta at time 50, which will be delivered at time 57.\n * Order ATC Hanbagu at time 60, which will be delivered at time 180.\n * Order APC Ramen at time 180, which will be delivered at time 215.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "101\n 86\n 119\n 108\n 57", "output": "481\n \n\nIf we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC\nHanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as\nfollows:\n\n * Order AGC Pasta at time 0, which will be delivered at time 119.\n * Order ARC Curry at time 120, which will be delivered at time 206.\n * Order ATC Hanbagu at time 210, which will be delivered at time 267.\n * Order APC Ramen at time 270, which will be delivered at time 378.\n * Order ABC Don at time 380, which will be delivered at time 481.\n\nThere is no way to order the dishes in which the last dish will be delivered\nearlier than this.\n\n* * *"}, {"input": "123\n 123\n 123\n 123\n 123", "output": "643\n \n\nThis is the largest valid case."}]