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 answer, with space in between. * * *
s653175647
Wrong Answer
p02777
Input is given from Standard Input in the following format: S T A B U
color = input() kosuu = input() trashc = input() _ = 0 color = color.split() kosuu = kosuu.split() trashc = trashc.split() while True: if trashc[0] == color[_]: if int(kosuu[_]) > 0: answer = int(kosuu[_]) - 1 break else: answer = 0 break _ = _ + 1 print(answer)
Statement We have A balls with the string S written on each of them and B balls with the string T written on each of them. From these balls, Takahashi chooses one with the string U written on it and throws it away. Find the number of balls with the string S and balls with the string T that we have now.
[{"input": "red blue\n 3 4\n red", "output": "2 4\n \n\nTakahashi chose a ball with `red` written on it and threw it away. Now we have\ntwo balls with the string S and four balls with the string T.\n\n* * *"}, {"input": "red blue\n 5 5\n blue", "output": "5 4\n \n\nTakahashi chose a ball with `blue` written on it and threw it away. Now we\nhave five balls with the string S and four balls with the string T."}]
Print the answer, with space in between. * * *
s948054643
Wrong Answer
p02777
Input is given from Standard Input in the following format: S T A B U
fs, bs = map(str, input().split()) ci, di = map(int, input().split()) es = str(input()) if es == fs: ca = ci - 1 print(ca) elif es == bs: da = di - 1 print(da)
Statement We have A balls with the string S written on each of them and B balls with the string T written on each of them. From these balls, Takahashi chooses one with the string U written on it and throws it away. Find the number of balls with the string S and balls with the string T that we have now.
[{"input": "red blue\n 3 4\n red", "output": "2 4\n \n\nTakahashi chose a ball with `red` written on it and threw it away. Now we have\ntwo balls with the string S and four balls with the string T.\n\n* * *"}, {"input": "red blue\n 5 5\n blue", "output": "5 4\n \n\nTakahashi chose a ball with `blue` written on it and threw it away. Now we\nhave five balls with the string S and four balls with the string T."}]
Print the area (the number of 0s) of the largest rectangle.
s628480767
Accepted
p02327
H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
class Rectangle: def __init__(self, height, position): self.height = height self.position = position def getLargestRectangleRow(size, bufTmp): S = [] maxv = 0 # bufTmp[0] * size bufTmp.append(0) for i in range(size + 1): rect = Rectangle(bufTmp[i], i) if len(S) == 0: S.append(rect) else: if S[-1].height < rect.height: S.append(rect) elif S[-1].height > rect.height: target = i while len(S) >= 1 and S[-1].height >= rect.height: pre = S.pop() area = pre.height * (i - pre.position) maxv = max(maxv, area) target = pre.position rect.position = target S.append(rect) return maxv def getLargestRectangle(): for j in range(W): for i in range(H): if buf[i][j]: T[i][j] = 0 else: if i > 0: T[i][j] = T[i - 1][j] + 1 else: T[i][j] = 1 maxv = 0 for i in range(H): maxv = max(maxv, getLargestRectangleRow(W, T[i])) return maxv nums = list(map(int, input().split())) H = nums[0] W = nums[1] buf = [[0 for i in range(W)] for j in range(H)] T = [[0 for i in range(W)] for j in range(H)] for i in range(H): nums = list(map(int, input().split())) for j in range(W): buf[i][j] = nums[j] print(getLargestRectangle())
Largest Rectangle Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s.
[{"input": "5\n 0 0 1 0 0\n 1 0 0 0 0\n 0 0 0 1 0\n 0 0 0 1 0", "output": "6"}]
Print the area (the number of 0s) of the largest rectangle.
s135988582
Accepted
p02327
H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
from typing import List, Tuple def rectangle(max_width: int, hist: List[int]) -> int: stack: List[Tuple[int, int]] = [] # (height, x_position) ans = 0 for i, h in enumerate(hist): j = i while stack and stack[-1][0] > h: pre_h, j = stack.pop() ans = max(ans, (i - j) * pre_h) if not stack or stack[-1][0] < h: stack.append((h, j)) ans = max(ans, max((max_width - j) * h for h, j in stack)) return ans if __name__ == "__main__": H, W = map(lambda x: int(x), input().split()) hist = [0] * W result = 0 for _ in range(H): one_row = list(map(int, input().split())) hist = list(map(lambda pre, cur: (pre + 1) * (cur ^ 1), hist, one_row)) result = max(result, rectangle(W, hist)) print(result)
Largest Rectangle Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s.
[{"input": "5\n 0 0 1 0 0\n 1 0 0 0 0\n 0 0 0 1 0\n 0 0 0 1 0", "output": "6"}]
Print the area (the number of 0s) of the largest rectangle.
s686242624
Wrong Answer
p02327
H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
h, w = map(int, input().split()) mp = [] for _ in range(h): lst = list(map(int, input().split())) cum = [] acc = 0 for i in lst: if not i: acc += 1 else: acc = 0 cum.append(acc) mp.append(cum) mp.append([-1] * w) ans = 0 for i in range(w - 1, -1, -1): stack = [] # print(ans) for j in range(h + 1): # print(stack) score = mp[j][i] if not stack: stack.append((score, j)) else: last_score, last_ind = stack[-1][0], stack[-1][1] if score > last_score: stack.append((score, j)) elif score == last_score: continue else: while stack and last_score > score: last_score, last_ind = stack.pop() ans = max(ans, last_score * (j - last_ind)) stack.append((score, last_ind)) print(ans)
Largest Rectangle Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s.
[{"input": "5\n 0 0 1 0 0\n 1 0 0 0 0\n 0 0 0 1 0\n 0 0 0 1 0", "output": "6"}]
Print the area (the number of 0s) of the largest rectangle.
s334423369
Wrong Answer
p02327
H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 4 5 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 output: 6 """ import sys class Rectangle(object): __slots__ = ("pos", "height") def __init__(self, pos=float("inf"), height=-1): """ init a Rectangle """ self.pos = pos self.height = height def gen_rec_info(_carpet_info): dp = [[1] * (W + 1) for _ in range(H + 1)] for i in range(H): for j in range(W): # stained if int(_carpet_info[i][j]): dp[i + 1][j + 1] = 0 else: dp[i + 1][j + 1] = dp[i][j + 1] + 1 return dp def get_largest_area(_hi_info): hi_max_area = 0 rec_stack = [] _hi_info[-1] = 0 for i, v in enumerate(_hi_info): rect = Rectangle(pos=i, height=int(v)) if not rec_stack: rec_stack.append(rect) else: last_height = rec_stack[-1].height if last_height < rect.height: rec_stack.append(rect) elif last_height > rect.height: target = i while rec_stack and rec_stack[-1].height >= rect.height: pre = rec_stack.pop() area = pre.height * (i - pre.pos) hi_max_area = max(hi_max_area, area) target = pre.pos rect.pos = target rec_stack.append(rect) return hi_max_area def solve(_rec_info): overall_max_area = 0 for hi_info in _rec_info: overall_max_area = max(overall_max_area, get_largest_area(hi_info)) return overall_max_area if __name__ == "__main__": _input = sys.stdin.readlines() H, W = map(int, _input[0].split()) carpet_info = list(map(lambda x: x.split(), _input[1:])) rec_info = gen_rec_info(carpet_info) # print(rec_info) ans = solve(rec_info) print(ans)
Largest Rectangle Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s.
[{"input": "5\n 0 0 1 0 0\n 1 0 0 0 0\n 0 0 0 1 0\n 0 0 0 1 0", "output": "6"}]
Print the area (the number of 0s) of the largest rectangle.
s889819779
Accepted
p02327
H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
""" Writer: SPD_9X2 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_B&lang=ja 各セルに対して、上にいくつ0が連続しているか数えれば、 ヒストグラム上での最大長方形問題になる """ def Largest_rectangle_in_histgram(lis): stk = [] ans = 0 N = len(lis) for i in range(N): if len(stk) == 0: stk.append((lis[i], i)) elif stk[-1][0] < lis[i]: stk.append((lis[i], i)) elif stk[-1][0] == lis[i]: pass else: lastpos = None while len(stk) > 0 and stk[-1][0] > lis[i]: nh, np = stk[-1] lastpos = np del stk[-1] ans = max(ans, nh * (i - np)) stk.append((lis[i], lastpos)) return ans H, W = map(int, input().split()) c = [] for i in range(H): C = list(map(int, input().split())) c.append(C) zlis = [[0] * (W + 1) for i in range(H)] for i in range(H): for j in range(W): if c[i][j] == 1: continue elif i == 0: zlis[i][j] = 1 else: zlis[i][j] = zlis[i - 1][j] + 1 # print (zlis) ans = 0 for i in range(H): ans = max(ans, Largest_rectangle_in_histgram(zlis[i])) print(ans)
Largest Rectangle Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s.
[{"input": "5\n 0 0 1 0 0\n 1 0 0 0 0\n 0 0 0 1 0\n 0 0 0 1 0", "output": "6"}]
Print the area (the number of 0s) of the largest rectangle.
s213537705
Accepted
p02327
H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
from collections import deque def rectangle(n, hs): # n:?¨????hs: ???????????°?????? stack = deque() # stack = (j, h) ????????¨?????????????´?????????? ans = 0 for i, h in enumerate(hs): j = -1 while stack and stack[-1][1] > h: j, h2 = stack.pop() ans = max(ans, (i - j) * h2) if ( not stack or stack[-1][1] < h ): # stack?????????????????????stack?????????????????????"??????h"?????????????????°?????????????????????????°????????????°???????£???¨??????stack???????????? stack.append((i if j == -1 else j, h)) ans = max(ans, max((n - j) * h2 for j, h2 in stack)) return ans H, W = map(int, input().split()) hs = [0] * W result = 0 for i in range(H): ht = list(map(int, input().split())) hs = list( map(lambda x, y: (x + 1) * abs(y - 1), hs, ht) ) # ???????????°??????????????? result = max(result, rectangle(W, hs)) print(result)
Largest Rectangle Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s.
[{"input": "5\n 0 0 1 0 0\n 1 0 0 0 0\n 0 0 0 1 0\n 0 0 0 1 0", "output": "6"}]
Print the length of the longest directed path in G. * * *
s126371408
Accepted
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
# DAGの最長経路...トポロジカルソートもどきか? # 普通にDAGに沿ったdpをすればいいのでは? # 再帰だと実装楽そうだけどどうしよう # 問題は終了と最初がわからんこと # いや最初は全部長さ0をセットすればいいだろ import sys sys.setrecursionlimit(1 << 25) readline = sys.stdin.buffer.readline read = sys.stdin.readline # 文字列読み込む時はこっち ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def ints(): return list(map(int, readline().split())) def read_col(H): """H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合""" ret = [] for _ in range(H): ret.append(list(map(int, readline().split()))) return tuple(map(list, zip(*ret))) MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce N, M = ints() dag = defaultdict(lambda: []) indeg = [0] * N for _ in ra(M): x, y = mina(*ints()) indeg[y] += 1 dag[x].append(y) q = deque() for u, inn in enu(indeg): # 多点DFS初期化 if inn == 0: q.append((u, 0)) dp = [0] * N while q: # トポロジカル順序でdpテーブルを埋めていく u, l = q.popleft() # dp[u] = max(dp[u], l) dp[u] = l for nx in dag[u]: indeg[nx] -= 1 if indeg[nx] == 0: q.append((nx, l + 1)) print(max(dp))
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s867075978
Accepted
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") AZ = "abcdefghijklmnopqrstuvwxyz" ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2, N + 1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) def base_10_to_n_without_0(X, n): X -= 1 if X // n: return base_10_to_n_without_0(X // n, n) + [X % n] return [X % n] #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# def topological_sort(graph): N = len(graph) in_cnt = [0 for i in range(N)] for x in range(N): for y in graph[x]: in_cnt[y] += 1 ret = [] q = deque([i for i in range(N) if not in_cnt[i]]) while q: x = q.popleft() ret.append(x) for y in graph[x]: in_cnt[y] -= 1 if not in_cnt[y]: q.append(y) if [i for i in range(N) if in_cnt[i]]: return None return ret N, M = IL() graph = [[] for i in range(N)] for _ in range(M): a, b = IL() graph[a - 1].append(b - 1) L = topological_sort(graph) d = [0 for i in range(N)] for x in L: for y in graph[x]: d[y] = max(d[y], d[x] + 1) print(max(d))
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s823346941
Runtime Error
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
import sys sys.setrecursionlimit(150000)sys.setrecursionlimit(150000) def gdp(n, dp, G): if dp[n]!=-1: return dp[n] if G[n]==[]: dp[n]=0 return 0 for i in G[n]: ll=gdp(i, dp, G) if dp[n]<ll+1: dp[n]=ll+1 return dp[n] def solve(N: int, M: int, x: "List[int]", y: "List[int]"): G=[[] for _ in range(N)] for i in range(M): G[x[i]-1].append(y[i]-1) dp=[-1]*N print(max(gdp(i, dp, G) for i in range(N))) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int x = [int()] * (M) # type: "List[int]" y = [int()] * (M) # type: "List[int]" for i in range(M): x[i] = int(next(tokens)) y[i] = int(next(tokens)) solve(N, M, x, y) if __name__ == '__main__': main()
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s980622415
Wrong Answer
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
if __name__ == "__main__": print(3)
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s854015882
Runtime Error
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
n , m = map(int, input().split()) edge=[[] for _ in range(n)] deg=[0] * n for i in range(m): x, y =map(int, input().split()) edge[x - 1 ].append(y - 1) deg[y - 1] +=1 from collections import deque que =deque() for i in range(n): if deg[i] == 0: que.append(i) dp = [0] *n while que: v = que.popleft() nv = edge[v] for nv in nv: deg[nv] -=1 if deg[nv] ==0: que.append(nv) dp[nv] = max(dp[v] + 1 ,dp[nv]) print(max(dp)
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s956056544
Accepted
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
# https://atcoder.jp/contests/dp/tasks/dp_g import sys input = sys.stdin.readline N, M = [int(x) for x in input().split()] # メモ化再帰版 # E = [[] for _ in range(N)] # for i in range(M): # e = tuple([int(x) for x in input().split()]) # E[e[0] - 1].append(e[1] - 1) # # dp = [-1] * N # def rec(v): # if dp[v] != -1: # return dp[v] # # res = 0 # for n in E[v]: # res = max(res, rec(n) + 1) # dp[v] = res # return res # # res = 0 # for n in range(N): # res = max(res, rec(n)) # # print(res) # BFS版 from collections import deque deg = [0] * N # 各頂点の入力数 dp = [0] * N # 各頂点のスタートからの距離 E = [[] for _ in range(N)] for i in range(M): e = tuple([int(x) - 1 for x in input().split()]) E[e[0]].append(e[1]) deg[e[1]] += 1 que = deque([i for i, v in enumerate(deg) if v == 0]) while len(que) > 0: v = que.popleft() for to in E[v]: deg[to] -= 1 if deg[to] == 0: que.append(to) dp[to] = max(dp[to], dp[v] + 1) print(max(dp))
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s643873570
Runtime Error
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
# https://atcoder.jp/contests/dp/tasks/dp_g import sys sys.setrecursionlimit(10**7) class DAG: def __init__(self, n): # n: num of vertices self.n = n self.adj = [[] for _ in range(n)] def addEdge(self, parent, child): self.adj[parent].append(child) def dfs(self, node): ans = 0 for child in self.adj[node]: ans = max(ans, 1 + self.dfs(child)) return ans def dfsWithMemo(self, node, memo, visited): if(visited[node]): return memo[node] visited[node] = True for child in self.adj[node]: memo[node] = max( memo[node], 1 + self.dfsWithMemo(child, memo, visited)) return memo[node] def dfsWithDp(self, node, dp, visited): if(visited[node]): return dp[node] visited[node] = True for child in self.adj[node]: if not visited[child]: self.dfsWithDp(child, dp, visited) dp[node] = max(dp[node], 1 + self.dfsWithDp(child, dp, visited)) return dp[node] # o(n^2) solution def findLongestPathNaive(self): ans = 0 for i in range(self.n): ans = max(ans, self.dfs(i)) return ans # o(n) solution def findLongestPathWithMemo(self): visited = [False] * self.n memo = [0] * self.n ans = 0 for i in range(self.n): ans = max(ans, self.dfsWithMemo(i, memo, visited)) return ans # O(n) solution def findLongestPathWithDp(self): visited = [False] * self.n dp = [0] * self.n # dp[i] := longest path starting from vertex i ans = 0 for i in range(self.n): ans = max(ans, self.dfsWithDp(i, dp, visited)) return ans def main(): N, M = map(int, input().split()) dag = DAG(N) for _ in range(M): parent, child = map(lambda i: int(i) - 1, input().split()) dag.addEdge(parent, child) # print(dag.findLongestPathNaive()) # print(dag.findLongestPathWithMemo()) print(dag.findLongestPathWithDp()) main()
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s701870113
Runtime Error
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
from _collections import defaultdict import sys class Graph: def __init__(self, n): self.g = defaultdict(list) self.dp = [-1 for i in range(n + 1)] def add_edge(self, x, y): self.g[x].append(y) def longest_path_util(self, node): if self.dp[node] != -1: return self.dp[node] leaf = 1 best_child = 0 for neib in self.g[node]: leaf = 0 best_child = max(best_child, self.longest_path_util(neib)) if leaf != 0: self.dp[node] = 0 else: self.dp[node] = best_child + 1 return self.dp[node] def longest_path(self, n): ans = 0 for i in range(1, n + 1): ans = max(ans, self.longest_path_util(i)) return ans n, k = map(int, input().split()) graph = Graph(n) for _ in range(k): x, y = list(map(int, sys.stdin.readline().split())) graph.add_edge(x, y) print(graph.longest_path(n))
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s563856622
Runtime Error
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
#include <bits/stdc++.h> using namespace std; int dfs(vector<int> graph[], int vertex, int N); // template<class T> void printvector(vector<int> &toprint) { for(int i = 0; i < toprint.size(); i++) cout << toprint[i] << " "; cout << endl; } // USING ADJENCY LIST TO STORE vertices int N, M; // Vertices, Edges int main() { cin >> N >> M; vector<int>graph[N+1]; int x1, y1; for(int i = 1; i <= M; i++) { cin >> x1 >> y1; graph[x1].push_back(y1); } // cout << endl; // for(int v = 1; v <= N; v++) // { // printvector(graph[v]); // } int finalmax = INT_MIN; for(int i = 1; i <= N; i++) { finalmax = max(finalmax, dfs(graph, i, N)); } cout << finalmax << endl; return 0; } int dfs(vector<int> graph[], int vertex, int N) { if (graph[vertex].size() == 0) { return 0; } int maximum = INT_MIN; for(auto v : graph[vertex]) { maximum = max(maximum , 1 + dfs(graph, v, N)); } return maximum; }
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s445173911
Wrong Answer
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
import sys input = sys.stdin.readline n, m = map(int, input().split()) infi = 10**10 # topological sort # 通常のグラフ構成のグラフ graph1 = [[] for _ in range(n + 1)] # 入ってくる辺の数を記録するグラフ graph2 = [0 for _ in range(n + 1)] for _ in range(m): x, y = map(int, input().split()) graph1[x].append(y) graph2[y] += 1 # start地点になるのは入ってくる辺の数が0の点 start = [] for i in range(1, n + 1): if graph2[i] == 0: start.append(i) start2 = start[::] # start地点から # ①topoリストに加える # ②隣接点の入ってくる辺の数を減らす # ③入ってくる辺の数が0になったらstartに加える # を繰り返す # ※今回はtopoに加えるのは本質ではない。 # topoに加えていく順序で見ていきながら距離を入れていく。 # topo=[] dist = [infi] * (n + 1) for i in start: dist[i] = 0 while start: a = start.pop() kyori = dist[a] # topo.append(a) for b in graph1[a]: graph2[b] -= 1 if graph2[b] == 0: start.append(b) dist[b] = min(dist[b], dist[a] + 1) print(max(dist[1:]))
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s718376495
Runtime Error
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; ++i) #pragma region Debug template <typename T> void view(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } #pragma endregion template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } map<int, vector<int>> dag; vector<int> max_depth; int ans = 0; void dfs(int v, int d = 0) { chmax(max_depth[v], d); chmax(ans, max_depth[v]); for (auto &child : dag[v]) { dfs(child, d + 1); } } int main() { int n, m; cin >> n >> m; vector<bool> start(n, true); max_depth = vector<int>(n, 0); rep(i, m) { int x, y; cin >> x >> y; x--; y--; dag[x].push_back(y); start[y] = false; } rep(i, n) { if (!start[i]) continue; dfs(i); } cout << ans << endl; return 0; }
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s712468342
Runtime Error
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
import sys sys.setrecursionlimit(10**6) from functools import lru_cache @lru_cache(maxsize = None) edges, vertices = map(int, input().split()) dp = [None for _ in range(edges)] nodes = [[] for _ in range(edges)] for i in range(vertices): start, end = map(int, input().split()) nodes[end -1].append(start-1) for i in range(edges): if not len(nodes[i]): dp[i] = 0 @lru_cache(maxsize = None) def find(arr): if not len(arr): return 0 for x in arr: if dp[x] is None: dp[x] = find(nodes[x]) return 1 + max(dp[x] for x in arr) for i in range(edges): dp[i] = find(nodes[i]) print(max(dp))
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s635642733
Runtime Error
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
N, M = (int(i) for i in input().split()) outs = [[] for i in range(N)] ins = [0] * N for _ in range(M): x, y = (int(i) for i in input().split()) x -= 1 y -= 1 outs[x].append(y) ins[y] += 1 q = [] for i in range(N): if ins[i] == 0: q.append(i) result = [] while q != []: qn = q.pop(0) result.append(qn) for v in outs[qn]: ins[v] -= 1 if ins[v] == 0: q.append(v) last = [0] * N # last[i] = iが最後だったときに最長のパス for sq in result: for v in outs[sq]: last[v] = max(last[v], last[sq] + 1) print(max(last)
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s982611016
Runtime Error
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
def dfs(cur, visited, dis): visited[cur] = 1 if cur in adj_list: for item in adj_list[cur]: if not visited[item]: dfs(item, visited, dis) dis[cur] = max(dis[cur], 1 + dis[item]) v, e = map(int, input().split()) adj_list = {} for _ in range(e): x, y = map(int, input().split()) adj_list.setdefault(x, []).append(y) visited = [0] * (v + 1) dis = [0] * (v + 1) for i in range(v + 1): if not visited[i]: dfs(i, visited, dis) print(max(dis))
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s506191371
Accepted
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
N, M = map(int, input().split()) XY = [list(map(int, input().split())) for i in range(M)] def tsort(N, E): c = [[] for i in range(N)] t = [0] * N for i, j in E: c[i].append(j) t[j] += 1 A, B = zip(*E) s = set(range(N)) - set(B) l = [] while s: n = s.pop() l.append(n) for i in c[n]: t[i] -= 1 if t[i] == 0: s.add(i) return c, l c, l = tsort(N, [(x - 1, y - 1) for x, y in XY]) d = [0] * N for i in l: for n in c[i]: d[n] = max(d[n], d[i] + 1) print(max(d))
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s063298230
Runtime Error
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on 2019/3/6 Update on 2019/3/6 Solved on 2019/3/ @author: shinjisu """ # Educational Dynamic Programming # import math import numpy as np def getInt(): return int(input()) # def getIntList(): return [int(x) for x in input().split()] def getIntList(): return np.array(input().split(), dtype=np.longlong) # def zeros(n): return [0]*n def zeros(n): return np.zeros(n, dtype=np.longlong) # def getIntLines(n): return [int(input()) for i in range(n)] def getIntLines(n): data = zeros(n) for i in range(n): data[i] = getInt() return data def getIntMat(n, m): # n行に渡って、1行にm個の整数 mat = zeros((n, m)) dmp(mat) for i in range(n): mat[i] = getIntList() return mat # def zeros2(n, m): return [zeros(m)]*n # obsoleted zeros((n, m))で代替 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 def dmp(x, cmt=""): global debug if debug: if cmt != "": print(cmt, ": ", end="") print(x) return x def find(frm, to, path): dmp((frm, to, path), "frm, to, path") if frm in path: return dmp(-1, "not found") elif frm == to: return dmp(0, "same") else: path = path + [frm] dmp(path) longest = -1 for i in range(M): dmp(longest, "longest") if edge[i, 0] == frm: if edge[i, 1] == to: longest = max(longest, len(path)) else: longest = max(longest, find(edge[i, 1], to, path)) return longest def prob_G(): # Longest Path global N, M, edge N, M = getIntList() dmp((N, M), "N, M") edge = getIntMat(M, 2) dmp(edge, "edge") graph = zeros((N + 1, N + 1)) dmp(graph, "graph") for i in range(1, N + 1): for j in range(1, N + 1): graph[i][j] = find(i, j, []) dmp(graph, "graph") return graph.max() debug = False # True False ans = prob_G() print(ans) # for row in ans: # print(row)
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s165430851
Runtime Error
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
from collections import Counter from collections import defaultdict import math import random import heapq as hq from math import sqrt import sys from functools import reduce def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def tinput(): return input().split() def rinput(): return map(int, tinput()) def rlinput(): return list(rinput()) mod = int(1e9) + 7 def factors(n): return set( reduce( list.__add__, ([i, n // i] for i in range(1, int(n**0.5) + 1) if n % i == 0) ) ) # ---------------------------------------------------- def dfs(i): visited[i] = True for node in g[i]: if not visited[node]: dfs(node) dp[i] = max(dp[i], 1 + dp[node]) if __name__ == "__main__": n, m = rinput() g = defaultdict(list) for i in range(m): x, y = rinput() g[x].append(y) dp = [0] * (n + 1) visited = [False] * (n + 1) for i in range(1, n + 1): if not visited[i]: dfs(i) # print('-=============================') # print(dp) print(max(dp)) # 5 3 # 2 3 # 2 4 # 5 2 # 5 1 # 1 4 # 4 3 # 1 3
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the length of the longest directed path in G. * * *
s418721727
Wrong Answer
p03166
Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M
from collections import deque N, M = map(int, input().split()) to_nodes = [[] for _ in range(N)] # 終点ノード deg = [0] * N # 入力辺 for _ in range(M): x, y = map(int, input().split()) to_nodes[x - 1].append(y - 1) deg[y - 1] += 1 st = deque() push, pop = st.append, st.pop for n in range(N): if deg[n] == 0: push(n) # 入力辺が無く、最長パスの始点になりうる点を取得 dp = [0] * N # print(deg,dp) while st: n = pop() nodes = to_nodes[n] for ni in nodes: deg[ni] -= 1 # 使ったエッジをグラフから削除する if deg[ni] == 0: push(ni) dp[ni] = max(dp[ni], dp[n] + 1) # print('n',n,'ni',ni,deg,dp) print(max(dp)) """'' @input 4 5 1 2 1 3 3 2 2 4 3 4 @output [0, 2, 1, 2] [0, 0, 0, 0] n 0 ni 1 [0, 1, 1, 2] [0, 0, 0, 0] n 0 ni 2 [0, 1, 0, 2] [0, 0, 1, 0] n 2 ni 1 [0, 0, 0, 2] [0, 2, 1, 0] n 2 ni 3 [0, 0, 0, 1] [0, 2, 1, 0] n 1 ni 3 [0, 0, 0, 0] [0, 2, 1, 3] 3 """ ""
Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G **does not contain directed cycles**. Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.
[{"input": "4 5\n 1 2\n 1 3\n 3 2\n 2 4\n 3 4", "output": "3\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_0_muffet.png)\n\n* * *"}, {"input": "6 3\n 2 3\n 4 5\n 5 6", "output": "2\n \n\nThe red directed path in the following figure is the longest:\n\n![](https://img.atcoder.jp/dp/longest_1_muffet.png)\n\n* * *"}, {"input": "5 8\n 5 3\n 2 3\n 2 4\n 5 2\n 5 1\n 1 4\n 4 3\n 1 3", "output": "3\n \n\nThe red directed path in the following figure is one of the longest:\n\n![](https://img.atcoder.jp/dp/longest_2_muffet.png)"}]
Print the maximum number of participants who can add zabuton to the stack. * * *
s909228228
Wrong Answer
p03536
Input is given from Standard Input in the following format: N H_1 P_1 H_2 P_2 : H_N P_N
N = int(input()) ds = [] for i in range(N): ds.append(list(map(int, input().split()))) ds.sort(key=lambda x: x[0] + x[1]) l = 0 ans = 0 for d in ds: h, p = d if l <= h: ans += 1 l += p print(ans)
Statement In the final of CODE FESTIVAL in some year, there are N participants. The _height_ and _power_ of Participant i is H_i and P_i, respectively. Ringo is hosting a game of stacking zabuton (cushions). The participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton. Initially, the stack is empty. When it is Participant i's turn, if there are H_i or less zabuton already stacked, he/she will add exactly P_i zabuton to the stack. Otherwise, he/she will give up and do nothing. Ringo wants to maximize the number of participants who can add zabuton to the stack. How many participants can add zabuton to the stack in the optimal order of participants?
[{"input": "3\n 0 2\n 1 3\n 3 4", "output": "2\n \n\nWhen the participants line up in the same order as the input, Participants 1\nand 3 will be able to add zabuton.\n\nOn the other hand, there is no order such that all three participants can add\nzabuton. Thus, the answer is 2.\n\n* * *"}, {"input": "3\n 2 4\n 3 1\n 4 1", "output": "3\n \n\nWhen the participants line up in the order 2, 3, 1, all of them will be able\nto add zabuton.\n\n* * *"}, {"input": "10\n 1 3\n 8 4\n 8 3\n 9 1\n 6 4\n 2 3\n 4 2\n 9 2\n 8 3\n 0 1", "output": "5"}]
Print the maximum number of participants who can add zabuton to the stack. * * *
s109445188
Wrong Answer
p03536
Input is given from Standard Input in the following format: N H_1 P_1 H_2 P_2 : H_N P_N
n = int(input()) lis = [] for _ in range(n): lis.append(list(map(int, input().split()))) hs = sorted(lis) ps = sorted(hs, key=lambda x: x[1]) zab, c = 0, 0 for i in range(n): h, p = ps[i] if zab <= h: zab += p c += 1 print(c)
Statement In the final of CODE FESTIVAL in some year, there are N participants. The _height_ and _power_ of Participant i is H_i and P_i, respectively. Ringo is hosting a game of stacking zabuton (cushions). The participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton. Initially, the stack is empty. When it is Participant i's turn, if there are H_i or less zabuton already stacked, he/she will add exactly P_i zabuton to the stack. Otherwise, he/she will give up and do nothing. Ringo wants to maximize the number of participants who can add zabuton to the stack. How many participants can add zabuton to the stack in the optimal order of participants?
[{"input": "3\n 0 2\n 1 3\n 3 4", "output": "2\n \n\nWhen the participants line up in the same order as the input, Participants 1\nand 3 will be able to add zabuton.\n\nOn the other hand, there is no order such that all three participants can add\nzabuton. Thus, the answer is 2.\n\n* * *"}, {"input": "3\n 2 4\n 3 1\n 4 1", "output": "3\n \n\nWhen the participants line up in the order 2, 3, 1, all of them will be able\nto add zabuton.\n\n* * *"}, {"input": "10\n 1 3\n 8 4\n 8 3\n 9 1\n 6 4\n 2 3\n 4 2\n 9 2\n 8 3\n 0 1", "output": "5"}]
Print the maximum number of participants who can add zabuton to the stack. * * *
s225514744
Wrong Answer
p03536
Input is given from Standard Input in the following format: N H_1 P_1 H_2 P_2 : H_N P_N
N = int(input()) HP = sorted( [list(map(int, input().split())) for i in range(N)], key=lambda x: x[0] + x[1] ) H = 0 count = 0 for h, p in HP: if h >= H: H += p count += 1 print(count)
Statement In the final of CODE FESTIVAL in some year, there are N participants. The _height_ and _power_ of Participant i is H_i and P_i, respectively. Ringo is hosting a game of stacking zabuton (cushions). The participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton. Initially, the stack is empty. When it is Participant i's turn, if there are H_i or less zabuton already stacked, he/she will add exactly P_i zabuton to the stack. Otherwise, he/she will give up and do nothing. Ringo wants to maximize the number of participants who can add zabuton to the stack. How many participants can add zabuton to the stack in the optimal order of participants?
[{"input": "3\n 0 2\n 1 3\n 3 4", "output": "2\n \n\nWhen the participants line up in the same order as the input, Participants 1\nand 3 will be able to add zabuton.\n\nOn the other hand, there is no order such that all three participants can add\nzabuton. Thus, the answer is 2.\n\n* * *"}, {"input": "3\n 2 4\n 3 1\n 4 1", "output": "3\n \n\nWhen the participants line up in the order 2, 3, 1, all of them will be able\nto add zabuton.\n\n* * *"}, {"input": "10\n 1 3\n 8 4\n 8 3\n 9 1\n 6 4\n 2 3\n 4 2\n 9 2\n 8 3\n 0 1", "output": "5"}]
Print an integer representing the sum of the interior angles of a regular polygon with N sides. * * *
s636965494
Runtime Error
p03023
Input is given from Standard Input in the following format: N
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) def opt(a, b): c = gcd(a, b) return a // c, b // c def dot(A, B): a = A[0] * B[0] b = A[1] * B[1] return opt(a, b) def add(A, B): return opt(A[0] * B[1] + B[0] * A[1], A[1] * B[1]) N, A, B, C = map(int, input().split()) A = opt(A, 100) B = opt(B, 100) C = opt(C, 100) g = 1000000007 c = [((1, 1), 0, 0, 0)] ans = (0, 1) e = (0, 1) pi = 0 while pi < len(c): PQ, cnt, acnt, bcnt = c[pi] pi += 1 if e[1] > (e[1] - e[0]) * g * 100: continue if acnt >= N or bcnt >= N: e = add(e, PQ) ans = add(ans, opt(cnt * PQ[0], PQ[1])) continue cnt += 1 c.append((dot(PQ, A), cnt, acnt + 1, bcnt)) c.append((dot(PQ, B), cnt, acnt, bcnt + 1)) c.append((dot(PQ, C), cnt, acnt, bcnt)) print(ans[0] * pow(ans[1], g - 2, g) % g)
Statement Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
[{"input": "3", "output": "180\n \n\nThe sum of the interior angles of a regular triangle is 180 degrees.\n\n* * *"}, {"input": "100", "output": "17640"}]
Print an integer representing the sum of the interior angles of a regular polygon with N sides. * * *
s631252238
Runtime Error
p03023
Input is given from Standard Input in the following format: N
from collections import deque def bfs(neighbor, start): order = [0 for i in range(N)] visited = [0 for i in range(N)] visited[start] = 1 q = deque([start]) num = 1 while q: path = q.popleft() order[path] = num visited[path] = 1 num += 1 for v in neighbor[path]: if visited[v] == 1: continue q.append(v) order = [[i, order[i]] for i in range(len(neighbor))] order.sort(key=lambda x: x[1]) return [order[i][0] for i in range(len(order))] N = int(input()) node = [[0, i] for i in range(N)] ab = [] neigh = [[0 for i in range(N)] for j in range(N)] for i in range(N - 1): ai, bi = map(int, input().split()) node[ai - 1][0] += 1 node[bi - 1][0] += 1 neigh[ai - 1][bi - 1] = 1 neigh[bi - 1][ai - 1] = 1 ab.append([ai - 1, bi - 1]) c = list(map(int, input().split())) c.sort(reverse=True) node.sort(key=lambda x: x[0], reverse=True) m = max([node[i][0] for i in range(N)]) max_node = [node[i][1] for i in range(N) if node[i][0] == m] ans1 = 0 for nn in max_node: can = 0 bbb = bfs(neigh, nn) cn = [[c[i], bbb[i]] for i in range(N)] # cn.sort(key=lambda x:x[1]) for i in range(N - 1): can += min(cn[ab[i][0]][0], cn[ab[i][1]][0]) if can > ans1: ans1 = can ans2 = " ".join([str(cn[i][0]) for i in range(N)]) print(ans1) print(ans2)
Statement Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
[{"input": "3", "output": "180\n \n\nThe sum of the interior angles of a regular triangle is 180 degrees.\n\n* * *"}, {"input": "100", "output": "17640"}]
Print an integer representing the sum of the interior angles of a regular polygon with N sides. * * *
s023412156
Runtime Error
p03023
Input is given from Standard Input in the following format: N
print((input() - 2) * 180)
Statement Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
[{"input": "3", "output": "180\n \n\nThe sum of the interior angles of a regular triangle is 180 degrees.\n\n* * *"}, {"input": "100", "output": "17640"}]
Print an integer representing the sum of the interior angles of a regular polygon with N sides. * * *
s430862012
Runtime Error
p03023
Input is given from Standard Input in the following format: N
print(180 * (int(input() - 2)))
Statement Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
[{"input": "3", "output": "180\n \n\nThe sum of the interior angles of a regular triangle is 180 degrees.\n\n* * *"}, {"input": "100", "output": "17640"}]
Print an integer representing the sum of the interior angles of a regular polygon with N sides. * * *
s894972639
Wrong Answer
p03023
Input is given from Standard Input in the following format: N
print(180 * (int(input()) - 1))
Statement Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
[{"input": "3", "output": "180\n \n\nThe sum of the interior angles of a regular triangle is 180 degrees.\n\n* * *"}, {"input": "100", "output": "17640"}]
Print an integer representing the sum of the interior angles of a regular polygon with N sides. * * *
s463634910
Accepted
p03023
Input is given from Standard Input in the following format: N
num = int(input()) print((180 * num) - 360)
Statement Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
[{"input": "3", "output": "180\n \n\nThe sum of the interior angles of a regular triangle is 180 degrees.\n\n* * *"}, {"input": "100", "output": "17640"}]
Print an integer representing the sum of the interior angles of a regular polygon with N sides. * * *
s864143877
Wrong Answer
p03023
Input is given from Standard Input in the following format: N
n = int(input("enter the number of sides of the polygon")) if n >= 3: sum = (n - 2) * 180 print("the total sum of the interior angles is: ", sum) else: print("enter the number greater or equal to 3")
Statement Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
[{"input": "3", "output": "180\n \n\nThe sum of the interior angles of a regular triangle is 180 degrees.\n\n* * *"}, {"input": "100", "output": "17640"}]
Print the sum of the inversion numbers of the final sequences, modulo 10^9+7. * * *
s775008844
Wrong Answer
p03189
Input is given from Standard Input in the following format: N Q A_1 : A_N X_1 Y_1 : X_Q Y_Q
N, Q = map(int, input().split()) A = [int(input()) for i in range(N)] DP = [[0] * (N - i - 1) for i in range(N - 1)] mod = 10**9 + 7 for i in range(N - 1): for j in range(len(DP[i])): if A[i] > A[i + j + 1]: DP[i][j] = 1 x, y = 0, 0 v = (10**9 + 8) >> 1 for q in range(Q): x, y = map(int, input().split()) x, y = x - 1, y - 1 if x > y: x, y = y, x for i in range(x + 1, y + 1): if A[i] != A[x]: DP[x][i - x - 1] = v for i in range(x + 1, y): if A[i] != A[y]: DP[i][y - i - 1] = v P = 0 for i in range(N - 1): P += sum(DP[i]) P = P * pow(2, Q, mod) % mod print(P)
Statement You are given an integer sequence of length N: A_1,A_2,...,A_N. Let us perform Q operations in order. The i-th operation is described by two integers X_i and Y_i. In this operation, we will choose one of the following two actions and perform it: * Swap the values of A_{X_i} and A_{Y_i} * Do nothing There are 2^Q ways to perform these operations. Find the sum of the inversion numbers of the final sequences for all of these ways to perform operations, modulo 10^9+7. Here, the inversion number of a sequence P_1,P_2,...,P_M is the number of pairs of integers (i,j) such that 1\leq i < j\leq M and P_i > P_j.
[{"input": "3 2\n 1\n 2\n 3\n 1 2\n 1 3", "output": "6\n \n\nThere are four ways to perform operations, as follows:\n\n * Do nothing, both in the first and second operations. The final sequence would be 1,2,3, with the inversion number of 0.\n * Do nothing in the first operation, then perform the swap in the second. The final sequence would be 3,2,1, with the inversion number of 3.\n * Perform the swap in the first operation, then do nothing in the second. The final sequence would be 2,1,3, with the inversion number of 1.\n * Perform the swap, both in the first and second operations. The final sequence would be 3,1,2, with the inversion number of 2.\n\nThe sum of these inversion numbers, 0+3+1+2=6, should be printed.\n\n* * *"}, {"input": "5 3\n 3\n 2\n 3\n 1\n 4\n 1 5\n 2 3\n 4 2", "output": "36\n \n\n* * *"}, {"input": "9 5\n 3\n 1\n 4\n 1\n 5\n 9\n 2\n 6\n 5\n 3 5\n 8 9\n 7 9\n 3 2\n 3 8", "output": "425"}]
Print the sum of the inversion numbers of the final sequences, modulo 10^9+7. * * *
s669581421
Runtime Error
p03189
Input is given from Standard Input in the following format: N Q A_1 : A_N X_1 Y_1 : X_Q Y_Q
def run(N, Q, A, XY): return rec_count(A, XY, 0) def rec_count(A, XY, i): div = 10**9 + 7 if i >= len(XY): return count_swap(A) % div A_swap = swap(A, XY[i]) return (rec_count(A, XY, i + 1) + rec_count(A_swap, XY, i + 1)) % div def swap(A, XY): A_swap = A.copy() X = XY[0] - 1 Y = XY[1] - 1 A_swap[X], A_swap[Y] = A[Y], A[X] return A_swap def count_swap(A): cnt = 0 for i in range(len(A)): for j in range(i + 1, len(A)): if A[i] > A[j]: cnt += 1 return cnt def main(): N, Q = map(int, input().split()) A = [] for _ in range(N): A.append(int(input())) XY = [] for _ in range(Q): XY.append(list(map(int, input().split()))) print(run(N, Q, A, XY)) if __name__ == "__main__": main()
Statement You are given an integer sequence of length N: A_1,A_2,...,A_N. Let us perform Q operations in order. The i-th operation is described by two integers X_i and Y_i. In this operation, we will choose one of the following two actions and perform it: * Swap the values of A_{X_i} and A_{Y_i} * Do nothing There are 2^Q ways to perform these operations. Find the sum of the inversion numbers of the final sequences for all of these ways to perform operations, modulo 10^9+7. Here, the inversion number of a sequence P_1,P_2,...,P_M is the number of pairs of integers (i,j) such that 1\leq i < j\leq M and P_i > P_j.
[{"input": "3 2\n 1\n 2\n 3\n 1 2\n 1 3", "output": "6\n \n\nThere are four ways to perform operations, as follows:\n\n * Do nothing, both in the first and second operations. The final sequence would be 1,2,3, with the inversion number of 0.\n * Do nothing in the first operation, then perform the swap in the second. The final sequence would be 3,2,1, with the inversion number of 3.\n * Perform the swap in the first operation, then do nothing in the second. The final sequence would be 2,1,3, with the inversion number of 1.\n * Perform the swap, both in the first and second operations. The final sequence would be 3,1,2, with the inversion number of 2.\n\nThe sum of these inversion numbers, 0+3+1+2=6, should be printed.\n\n* * *"}, {"input": "5 3\n 3\n 2\n 3\n 1\n 4\n 1 5\n 2 3\n 4 2", "output": "36\n \n\n* * *"}, {"input": "9 5\n 3\n 1\n 4\n 1\n 5\n 9\n 2\n 6\n 5\n 3 5\n 8 9\n 7 9\n 3 2\n 3 8", "output": "425"}]
Print the sum of the inversion numbers of the final sequences, modulo 10^9+7. * * *
s939209393
Runtime Error
p03189
Input is given from Standard Input in the following format: N Q A_1 : A_N X_1 Y_1 : X_Q Y_Q
def selection(elems, low, high): num_swap = 0 ns_l = 0 ns_r = 0 if low < high: pos, num_swap = partition(elems, low, high) ns_l = selection(elems, low, pos - 1) ns_r = selection(elems, pos + 1, high) return num_swap + ns_l + ns_r def partition(elems, low, high): pivot = elems[low] num_swap = 0 lower_end = low i = low + 1 while i <= high: if elems[i] < pivot: tmp = elems[lower_end] elems[lower_end] = elems[i] elems[i] = tmp # if(i != higher_start): num_swap += 1 lower_end += 1 i += 1 elems[lower_end] = pivot return lower_end, num_swap def swap_list(dl, idx1, idx2): tmp = dl[idx1] dl[idx1] = dl[idx2] dl[idx2] = tmp def dec2binary(dec): q = dec // 2 r = dec % 2 binary_list = [r] while q != 0: r = q % 2 q = q // 2 binary_list.append(r) return binary_list # get the reserved binary_list def main(): N, Q = [int(each) for each in input().split()] dl = [] operation = [] for i in range(N): dl.append(int(input().strip())) for i in range(Q): operation.append([int(each) for each in input().split()]) print("dl ", dl) total_num = 0 for i in range(2**Q): valid_opr = dec2binary(i) swap_dl = [] for m in range(N): swap_dl.append(dl[m]) for j in range(len(operation)): idx1 = operation[j][0] - 1 idx2 = operation[j][1] - 1 if j < len(valid_opr) and valid_opr[j] == 1: swap_list(swap_dl, idx1, idx2) elif j >= len(valid_opr): break tmp_num = selection(swap_dl, 0, len(swap_dl) - 1) # print('for {} , the inversion num {}'.format(swap_dl , tmp_num)) total_num += tmp_num print(total_num) return total_num if __name__ == "__main__": main()
Statement You are given an integer sequence of length N: A_1,A_2,...,A_N. Let us perform Q operations in order. The i-th operation is described by two integers X_i and Y_i. In this operation, we will choose one of the following two actions and perform it: * Swap the values of A_{X_i} and A_{Y_i} * Do nothing There are 2^Q ways to perform these operations. Find the sum of the inversion numbers of the final sequences for all of these ways to perform operations, modulo 10^9+7. Here, the inversion number of a sequence P_1,P_2,...,P_M is the number of pairs of integers (i,j) such that 1\leq i < j\leq M and P_i > P_j.
[{"input": "3 2\n 1\n 2\n 3\n 1 2\n 1 3", "output": "6\n \n\nThere are four ways to perform operations, as follows:\n\n * Do nothing, both in the first and second operations. The final sequence would be 1,2,3, with the inversion number of 0.\n * Do nothing in the first operation, then perform the swap in the second. The final sequence would be 3,2,1, with the inversion number of 3.\n * Perform the swap in the first operation, then do nothing in the second. The final sequence would be 2,1,3, with the inversion number of 1.\n * Perform the swap, both in the first and second operations. The final sequence would be 3,1,2, with the inversion number of 2.\n\nThe sum of these inversion numbers, 0+3+1+2=6, should be printed.\n\n* * *"}, {"input": "5 3\n 3\n 2\n 3\n 1\n 4\n 1 5\n 2 3\n 4 2", "output": "36\n \n\n* * *"}, {"input": "9 5\n 3\n 1\n 4\n 1\n 5\n 9\n 2\n 6\n 5\n 3 5\n 8 9\n 7 9\n 3 2\n 3 8", "output": "425"}]
Print the sum of the inversion numbers of the final sequences, modulo 10^9+7. * * *
s409365724
Wrong Answer
p03189
Input is given from Standard Input in the following format: N Q A_1 : A_N X_1 Y_1 : X_Q Y_Q
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines """ ・逆再生 ・各時点に対して、「(Ai,Aj)がjが右になって終わる確率」を計算していく """ import numpy as np MOD = 10**9 + 7 N, Q = map(int, readline().split()) data = list(map(int, read().split())) A = np.array(data[:N]) it = iter(data[N:]) XY = list(zip(it, it)) dp = np.triu(np.ones((N, N), np.int64), 1) for x, y in XY[::-1]: x -= 1 y -= 1 p = dp[x, y] q = dp[y, x] r = p + q if r & 1: r += MOD r //= 2 if r >= MOD: r -= MOD temp = dp[x] temp += dp[y] temp[temp & 1 == 1] += MOD temp //= 2 temp[temp >= MOD] -= MOD dp[y] = temp temp = dp[:, x] temp += dp[:, y] temp[temp & 1 == 1] += MOD temp //= 2 temp[temp >= MOD] -= MOD dp[:, y] = temp dp[x, y] = r dp[y, x] = r dp[x, x] = 0 dp[y, y] = 0 select = A[:, None] > A[None, :] answer = (dp * select).sum() * pow(2, Q, MOD) % MOD print(answer)
Statement You are given an integer sequence of length N: A_1,A_2,...,A_N. Let us perform Q operations in order. The i-th operation is described by two integers X_i and Y_i. In this operation, we will choose one of the following two actions and perform it: * Swap the values of A_{X_i} and A_{Y_i} * Do nothing There are 2^Q ways to perform these operations. Find the sum of the inversion numbers of the final sequences for all of these ways to perform operations, modulo 10^9+7. Here, the inversion number of a sequence P_1,P_2,...,P_M is the number of pairs of integers (i,j) such that 1\leq i < j\leq M and P_i > P_j.
[{"input": "3 2\n 1\n 2\n 3\n 1 2\n 1 3", "output": "6\n \n\nThere are four ways to perform operations, as follows:\n\n * Do nothing, both in the first and second operations. The final sequence would be 1,2,3, with the inversion number of 0.\n * Do nothing in the first operation, then perform the swap in the second. The final sequence would be 3,2,1, with the inversion number of 3.\n * Perform the swap in the first operation, then do nothing in the second. The final sequence would be 2,1,3, with the inversion number of 1.\n * Perform the swap, both in the first and second operations. The final sequence would be 3,1,2, with the inversion number of 2.\n\nThe sum of these inversion numbers, 0+3+1+2=6, should be printed.\n\n* * *"}, {"input": "5 3\n 3\n 2\n 3\n 1\n 4\n 1 5\n 2 3\n 4 2", "output": "36\n \n\n* * *"}, {"input": "9 5\n 3\n 1\n 4\n 1\n 5\n 9\n 2\n 6\n 5\n 3 5\n 8 9\n 7 9\n 3 2\n 3 8", "output": "425"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s996910653
Accepted
p03473
Input is given from Standard Input in the following format: M
print((48 - int(input())))
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s734910817
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48 - int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s171351104
Wrong Answer
p03473
Input is given from Standard Input in the following format: M
print(60 - int(input()))
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s702053056
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s971630504
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48 - input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s451036318
Runtime Error
p03473
Input is given from Standard Input in the following format: M
i = 48 - i print(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s630051169
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s329843055
Accepted
p03473
Input is given from Standard Input in the following format: M
print(max(0, 48 - int(input())))
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s029044773
Accepted
p03473
Input is given from Standard Input in the following format: M
###================================================== ### import # import bisect # from collections import Counter, deque, defaultdict # from copy import deepcopy # from functools import reduce, lru_cache # from heapq import heappush, heappop # import itertools # import math # import string import sys ### stdin def input(): return sys.stdin.readline() def iIn(): return int(input()) def iInM(): return map(int, input().split()) def iInM1(): return map(int1, input().split()) def iInLH(): return list(map(int, input().split())) def iInLH1(): return list(map(int1, input().split())) def iInLV(n): return [iIn() for _ in range(n)] def iInLV1(n): return [iIn() - 1 for _ in range(n)] def iInLD(n): return [iInLH() for _ in range(n)] def iInLD1(n): return [iInLH1() for _ in range(n)] def sInLH(): return list(input().split()) def sInLV(n): return [input().rstrip("\n") for _ in range(n)] def sInLD(n): return [sInLH() for _ in range(n)] ### stdout def OutH(lst, deli=" "): print(deli.join(map(str, lst))) def OutV(lst): print("\n".join(map(str, lst))) ### setting sys.setrecursionlimit(10**6) ### utils int1 = lambda x: int(x) - 1 ### constants INF = int(1e9) MOD = 1000000007 dx = (-1, 0, 1, 0) dy = (0, -1, 0, 1) ###--------------------------------------------------- M = iIn() ans = 24 + (24 - M) print(ans)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s618944605
Accepted
p03473
Input is given from Standard Input in the following format: M
import bisect import numpy as np import sys input = sys.stdin.readline def IL(): return list(map(int, input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return input() M = I() print(48 - M)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s141557964
Runtime Error
p03473
Input is given from Standard Input in the following format: M
# !/usr/bin/env python # -*- coding: utf-8 -*- import math def generate_prime(p_max): prime = set([2]) for i in range(3, p_max + 1): for p in prime: if i % p == 0: break if p > int(math.sqrt(i)): prime.add(i) break return prime def main(): prime = generate_prime(10**5) prime2 = set() for p in prime: if (p + 1) / 2 in prime: prime2.add(p) ans = [0] * (10**5 + 1) for i in range(1, 10**5 + 1): if i in prime2: ans[i] = ans[i - 1] + 1 else: ans[i] = ans[i - 1] q = int(input()) queries = [[int(i) for i in input().split()] for _ in range(q)] for query in queries: print(ans[query[1]] - ans[query[0] - 1]) if __name__ == "__main__": main()
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s666229120
Runtime Error
p03473
Input is given from Standard Input in the following format: M
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using VI = vector<int>; using VL = vector<ll>; using VS = vector<string>; template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>; #define FOR(i,a,n) for(int i=(a);i<(n);++i) #define eFOR(i,a,n) for(int i=(a);i<=(n);++i) #define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i) #define erFOR(i,a,n) for(int i=(n);i>=(a);--i) #define each(i, a) for(auto &i : a) #define SORT(a) sort(a.begin(),a.end()) #define rSORT(a) sort(a.rbegin(),a.rend()) #define fSORT(a,f) sort(a.begin(),a.end(),f) #define all(a) a.begin(),a.end() #define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x)) #define tp(a,i) get<i>(a) #define line cout << "-----------------------------\n" #define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ") #define stop system("pause") constexpr ll INF = 1000000000; constexpr ll LLINF = 1LL << 60; constexpr ll mod = 1000000007; constexpr ll MOD = 998244353; constexpr ld eps = 1e-10; constexpr ld pi = 3.1415926535897932; template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; } template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; } inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; } template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; } template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; } template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); } template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); } template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); } template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); } template<class T>inline void print(const T& a) { cout << a << "\n"; } template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); } template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); } template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); } inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; } int main() { init(); int m; cin >> m; print(24 - m + 24); return 0; }
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s696525303
Runtime Error
p03473
Input is given from Standard Input in the following format: M
n = int(input()) cc = [] ss = [] ff = [] for i in range(n - 1): c, s, f = list(map(int, input().split())) cc.append(c) ss.append(s) ff.append(f) for l in range(n - 1): ans = ss[l] + cc[l] for k in range(l + 1, n - 1): temp = ss[k] while temp < ans: temp += ff[k] ans = temp + cc[k] print(ans) print(0)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s447943742
Accepted
p03473
Input is given from Standard Input in the following format: M
nancy = int(input()) print(24 - nancy + 24)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s274519348
Runtime Error
p03473
Input is given from Standard Input in the following format: M
a=int(input()) print(24+(24-a)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s101830355
Runtime Error
p03473
Input is given from Standard Input in the following format: M
temp = input() b = int(temp) print(48 - temp)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s874751175
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s783327121
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s251417265
Runtime Error
p03473
Input is given from Standard Input in the following format: M
i = input() print(24 + i)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s804997284
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48 - {})
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s871020690
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s525912380
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(M - input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s304529534
Accepted
p03473
Input is given from Standard Input in the following format: M
M = (int)(input()) print(str(48 - M))
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s257970720
Runtime Error
p03473
Input is given from Standard Input in the following format: M
I = int(intput()) print(24 + 24 - I)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s984062046
Accepted
p03473
Input is given from Standard Input in the following format: M
print("{}\n".format((48 - int(input()))))
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s414931233
Accepted
p03473
Input is given from Standard Input in the following format: M
k = list(map(int, input().split())) print(48 - k[0])
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s643417021
Accepted
p03473
Input is given from Standard Input in the following format: M
print(list(range(48, 24, -1))[int(input())])
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s704659520
Accepted
p03473
Input is given from Standard Input in the following format: M
number = int(input()) h = 48 - number print(h)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s519999234
Wrong Answer
p03473
Input is given from Standard Input in the following format: M
print("{}".format(int(input()) + 24))
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s512211624
Accepted
p03473
Input is given from Standard Input in the following format: M
import math import sys def getinputdata(): # 配列初期化 array_result = [] data = input() array_result.append(data.split(" ")) flg = 1 try: while flg: data = input() array_temp = [] if data != "": array_result.append(data.split(" ")) flg = 1 else: flg = 0 finally: return array_result arr_data = getinputdata() x = int(arr_data[0][0]) print(24 - x + 24)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s362383304
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print((24 = M) + 24)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s368353797
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s659256246
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(24 - int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s759956773
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48 - int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s880854819
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s556895472
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(abs(int(input) - 48))
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s634447322
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s096211683
Wrong Answer
p03473
Input is given from Standard Input in the following format: M
print(int(input()) - 24)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s342318878
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s186653910
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s831256586
Wrong Answer
p03473
Input is given from Standard Input in the following format: M
print(24 + int(input()))
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s981407703
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48 -int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s810962451
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s508616903
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48 - int(open(0)))
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s564200019
Wrong Answer
p03473
Input is given from Standard Input in the following format: M
print(21)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s956405007
Accepted
p03473
Input is given from Standard Input in the following format: M
print((24 - int(input())) + 24)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s968257728
Accepted
p03473
Input is given from Standard Input in the following format: M
print(2 * 24 - int(input()))
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s113999284
Wrong Answer
p03473
Input is given from Standard Input in the following format: M
i = int(input()) print(i + 24)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s931600873
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input().split())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s061248388
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48 - map(int, input()))
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s880540883
Runtime Error
p03473
Input is given from Standard Input in the following format: M
print(48-int(input())
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s066939290
Wrong Answer
p03473
Input is given from Standard Input in the following format: M
print(list(range(48, 24, -1))[21])
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s142243029
Runtime Error
p03473
Input is given from Standard Input in the following format: M
m = int(input()) print(24-m+24
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s981720755
Runtime Error
p03473
Input is given from Standard Input in the following format: M
M = int(input()) print(48-M)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s743326474
Accepted
p03473
Input is given from Standard Input in the following format: M
# coding: utf-8 # 問題文 # 12 月 30 日の M 時から次の年になるまでは何時間か、求めてください。 # # 制約 # 1≦M≦23 # 入力は全て整数 # # 入力は以下の形式で標準入力から与えられる。 # M # # 出力 # 12 月 30 日の M 時から次の年になるまでが x 時間のとき、x を出力せよ。 two_day_hour = 48 current_hour = int(input()) print(two_day_hour - current_hour)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s010243154
Accepted
p03473
Input is given from Standard Input in the following format: M
time = int(input()) print((24 - time) + 24)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s625837140
Accepted
p03473
Input is given from Standard Input in the following format: M
# -*- cording: utf-8 -*- data = int(input()) remein = (24 - data) + 24 print(remein)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s608031477
Runtime Error
p03473
Input is given from Standard Input in the following format: M
# -*- coding: utf-8 -*- int a=input() print(48-a)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s207547955
Runtime Error
p03473
Input is given from Standard Input in the following format: M
int m = 0 cin << m cout >> 24-m >> endl
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s993747164
Runtime Error
p03473
Input is given from Standard Input in the following format: M
M = int(input()) print(48-M)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]