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
The output consists of 2 lines. In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. In the second line, please print the number of swap operations.
s613242033
Accepted
p02259
The first line of the input includes an integer _N_ , the number of elements in the sequence. In the second line, _N_ elements of the sequence are given separated by spaces characters.
n, data = int(input()), list(map(int, input().split())) i, t = 0, 0 while i != n - 1: for j in range(n - 1, i, -1): if data[j - 1] > data[j]: data[j - 1], data[j] = data[j], data[j - 1] t += 1 i += 1 print(" ".join(map(str, data))) print(t)
Bubble Sort Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
[{"input": "5\n 5 3 2 4 1", "output": "1 2 3 4 5\n 8"}, {"input": "6\n 5 2 4 6 1 3", "output": "1 2 3 4 5 6\n 9"}]
The output consists of 2 lines. In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. In the second line, please print the number of swap operations.
s177210767
Accepted
p02259
The first line of the input includes an integer _N_ , the number of elements in the sequence. In the second line, _N_ elements of the sequence are given separated by spaces characters.
n = int(input()) t = list(map(int, input().split(" "))) x, y = 0, 0 while True: x = 0 for i in range(n - 1): if t[i] > t[i + 1]: t[i], t[i + 1] = t[i + 1], t[i] y = y + 1 else: x = x + 1 if x == n - 1: break print(" ".join(map(str, t))) print(y)
Bubble Sort Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
[{"input": "5\n 5 3 2 4 1", "output": "1 2 3 4 5\n 8"}, {"input": "6\n 5 2 4 6 1 3", "output": "1 2 3 4 5 6\n 9"}]
The output consists of 2 lines. In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. In the second line, please print the number of swap operations.
s210744116
Accepted
p02259
The first line of the input includes an integer _N_ , the number of elements in the sequence. In the second line, _N_ elements of the sequence are given separated by spaces characters.
length = int(input()) targ = [int(n) for n in input().split(" ")] swap = 0 for l in range(length): for m in range(l): if targ[l - m] < targ[l - m - 1]: disp = targ[l - m - 1] targ[l - m - 1] = targ[l - m] targ[l - m] = disp swap += 1 print(" ".join([str(n) for n in targ])) print(swap)
Bubble Sort Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
[{"input": "5\n 5 3 2 4 1", "output": "1 2 3 4 5\n 8"}, {"input": "6\n 5 2 4 6 1 3", "output": "1 2 3 4 5 6\n 9"}]
If there does not exist an valid assignment that is consistent with s, print `-1`. Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s. * t is a string of length N consisting of `S` and `W`. * If t_i is `S`, it indicates that the animal numbered i is a sheep. If t_i is `W`, it indicates that the animal numbered i is a wolf. * * *
s934303936
Wrong Answer
p03798
The input is given from Standard Input in the following format: N s
N = int(input()) s = list(input()) check_SW = True X = ["S"] for i in range(1, N): if check_SW: if s[i - 1] == "o": X.append("S") check_SW = True else: X.append("W") check_SW = False else: if s[i - 1] == "×": X.append("S") check_SW = False else: X.append("W") check_SW = True print(X)
Statement Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1. There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies. Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is `o`, the animal said that the two neighboring animals are of the same species, and if s_i is `x`, the animal said that the two neighboring animals are of different species. More formally, a sheep answered `o` if the two neighboring animals are both sheep or both wolves, and answered `x` otherwise. Similarly, a wolf answered `x` if the two neighboring animals are both sheep or both wolves, and answered `o` otherwise. Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print `-1`.
[{"input": "6\n ooxoox", "output": "SSSWWS\n \n\nFor example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a\nsheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their\nresponses. Besides, there is another valid assignment of species: a wolf,\nsheep, wolf, sheep, wolf and wolf.\n\nLet us remind you: if the neiboring animals are of the same species, a sheep\nanswers `o` and a wolf answers `x`. If the neiboring animals are of different\nspecies, a sheep answers `x` and a wolf answers `o`.\n\n![b34c052fc21c42d2def9b98d6dccd05c.png](https://atcoder.jp/img/arc069/b34c052fc21c42d2def9b98d6dccd05c.png)\n\n* * *"}, {"input": "3\n oox", "output": "-1\n \n\nPrint `-1` if there is no valid assignment of species.\n\n* * *"}, {"input": "10\n oxooxoxoox", "output": "SSWWSSSWWS"}]
If there does not exist an valid assignment that is consistent with s, print `-1`. Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s. * t is a string of length N consisting of `S` and `W`. * If t_i is `S`, it indicates that the animal numbered i is a sheep. If t_i is `W`, it indicates that the animal numbered i is a wolf. * * *
s174342321
Runtime Error
p03798
The input is given from Standard Input in the following format: N s
!/usr/bin/python3 from itertools import product def solve(): N = int(input()) S = [0 if i == 'o' else 1 for i in input()] for i, j in product(range(2), repeat=2): pattern = [i, j] + [0] * (N - 2) for k in range(2, N): pattern[k] = (pattern[k - 1] + pattern[k - 2] + S[k] ) % 2 if S[-1] != (pattern[-2] + pattern[-1] + pattern[0]) % 2 : continue if S[0] != (pattern[-1] + pattern[0] + pattern[1]) % 2 : continue answer = [ 'S' if pattern[k] == 0 else 'W' for k in range(N)] print(''.join(answer)) return None print(-1) if __name__ == '__main__': solve()
Statement Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1. There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies. Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is `o`, the animal said that the two neighboring animals are of the same species, and if s_i is `x`, the animal said that the two neighboring animals are of different species. More formally, a sheep answered `o` if the two neighboring animals are both sheep or both wolves, and answered `x` otherwise. Similarly, a wolf answered `x` if the two neighboring animals are both sheep or both wolves, and answered `o` otherwise. Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print `-1`.
[{"input": "6\n ooxoox", "output": "SSSWWS\n \n\nFor example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a\nsheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their\nresponses. Besides, there is another valid assignment of species: a wolf,\nsheep, wolf, sheep, wolf and wolf.\n\nLet us remind you: if the neiboring animals are of the same species, a sheep\nanswers `o` and a wolf answers `x`. If the neiboring animals are of different\nspecies, a sheep answers `x` and a wolf answers `o`.\n\n![b34c052fc21c42d2def9b98d6dccd05c.png](https://atcoder.jp/img/arc069/b34c052fc21c42d2def9b98d6dccd05c.png)\n\n* * *"}, {"input": "3\n oox", "output": "-1\n \n\nPrint `-1` if there is no valid assignment of species.\n\n* * *"}, {"input": "10\n oxooxoxoox", "output": "SSWWSSSWWS"}]
If there does not exist an valid assignment that is consistent with s, print `-1`. Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s. * t is a string of length N consisting of `S` and `W`. * If t_i is `S`, it indicates that the animal numbered i is a sheep. If t_i is `W`, it indicates that the animal numbered i is a wolf. * * *
s039586610
Runtime Error
p03798
The input is given from Standard Input in the following format: N s
io = STDIN $n=io.gets.chomp.to_i $s=io.gets.chomp $ans=' '*$n def check2(i) return true if $ans[i]==' ' nxt = i==$n-1 ? 0 : i+1 return true if $ans[i-1]==' ' || $ans[nxt]==' ' rslt=case $s[i] when "o" if $ans[i]=="S" $ans[i-1]==$ans[nxt] else $ans[i-1]!=$ans[nxt] end else if $ans[i]=="S" $ans[i-1]!=$ans[nxt] else $ans[i-1]==$ans[nxt] end end # p ["check2",i,rslt,$s[i],$ans[i-1],$ans[i],$ans[nxt]] rslt end def check1(i) if i==$n if check2(i-1) return $ans else return false end else ["S","W"].each do |a| $ans[i]=a if check2(i-1) return true if check1(i+1) end end return false end end puts check1(0) ? $ans : -1
Statement Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1. There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies. Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is `o`, the animal said that the two neighboring animals are of the same species, and if s_i is `x`, the animal said that the two neighboring animals are of different species. More formally, a sheep answered `o` if the two neighboring animals are both sheep or both wolves, and answered `x` otherwise. Similarly, a wolf answered `x` if the two neighboring animals are both sheep or both wolves, and answered `o` otherwise. Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print `-1`.
[{"input": "6\n ooxoox", "output": "SSSWWS\n \n\nFor example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a\nsheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their\nresponses. Besides, there is another valid assignment of species: a wolf,\nsheep, wolf, sheep, wolf and wolf.\n\nLet us remind you: if the neiboring animals are of the same species, a sheep\nanswers `o` and a wolf answers `x`. If the neiboring animals are of different\nspecies, a sheep answers `x` and a wolf answers `o`.\n\n![b34c052fc21c42d2def9b98d6dccd05c.png](https://atcoder.jp/img/arc069/b34c052fc21c42d2def9b98d6dccd05c.png)\n\n* * *"}, {"input": "3\n oox", "output": "-1\n \n\nPrint `-1` if there is no valid assignment of species.\n\n* * *"}, {"input": "10\n oxooxoxoox", "output": "SSWWSSSWWS"}]
If there does not exist an valid assignment that is consistent with s, print `-1`. Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s. * t is a string of length N consisting of `S` and `W`. * If t_i is `S`, it indicates that the animal numbered i is a sheep. If t_i is `W`, it indicates that the animal numbered i is a wolf. * * *
s615420454
Accepted
p03798
The input is given from Standard Input in the following format: N s
n = int(input()) s = input() def check(s1, s2): ans = [s1, s2] for i in range(1, n - 1): if (ans[i] == "S" and s[i] == "o") or (ans[i] == "W" and s[i] == "x"): ans.append(ans[i - 1]) elif ans[i] == "S" and s[i] == "x" and ans[i - 1] == "S": ans.append("W") elif ans[i] == "S" and s[i] == "x" and ans[i - 1] == "W": ans.append("S") elif ans[i] == "W" and s[i] == "o" and ans[i - 1] == "S": ans.append("W") elif ans[i] == "W" and s[i] == "o" and ans[i - 1] == "W": ans.append("S") if ans[-1] == "S": if s[-1] == "o" and ans[0] == ans[-2]: if ans[0] == "S" and s[0] == "o" and ans[1] == ans[-1]: print("".join(ans)) exit() if ans[0] == "S" and s[0] == "x" and ans[1] != ans[-1]: print("".join(ans)) exit() if ans[0] == "W" and s[0] == "o" and ans[1] != ans[-1]: print("".join(ans)) exit() if ans[0] == "W" and s[0] == "x" and ans[1] == ans[-1]: print("".join(ans)) exit() if s[-1] == "x" and ans[0] != ans[-2]: if ans[0] == "S" and s[0] == "o" and ans[1] == ans[-1]: print("".join(ans)) exit() if ans[0] == "S" and s[0] == "x" and ans[1] != ans[-1]: print("".join(ans)) exit() if ans[0] == "W" and s[0] == "o" and ans[1] != ans[-1]: print("".join(ans)) exit() if ans[0] == "W" and s[0] == "x" and ans[1] == ans[-1]: print("".join(ans)) exit() else: if s[-1] == "o" and ans[0] != ans[-2]: if ans[0] == "S" and s[0] == "o" and ans[1] == ans[-1]: print("".join(ans)) exit() if ans[0] == "S" and s[0] == "x" and ans[1] != ans[-1]: print("".join(ans)) exit() if ans[0] == "W" and s[0] == "o" and ans[1] != ans[-1]: print("".join(ans)) exit() if ans[0] == "W" and s[0] == "x" and ans[1] == ans[-1]: print("".join(ans)) exit() if s[-1] == "x" and ans[0] == ans[-2]: if ans[0] == "S" and s[0] == "o" and ans[1] == ans[-1]: print("".join(ans)) exit() if ans[0] == "S" and s[0] == "x" and ans[1] != ans[-1]: print("".join(ans)) exit() if ans[0] == "W" and s[0] == "o" and ans[1] != ans[-1]: print("".join(ans)) exit() if ans[0] == "W" and s[0] == "x" and ans[1] == ans[-1]: print("".join(ans)) exit() return check("S", "S") check("S", "W") check("W", "S") check("W", "W") print(-1)
Statement Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1. There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies. Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is `o`, the animal said that the two neighboring animals are of the same species, and if s_i is `x`, the animal said that the two neighboring animals are of different species. More formally, a sheep answered `o` if the two neighboring animals are both sheep or both wolves, and answered `x` otherwise. Similarly, a wolf answered `x` if the two neighboring animals are both sheep or both wolves, and answered `o` otherwise. Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print `-1`.
[{"input": "6\n ooxoox", "output": "SSSWWS\n \n\nFor example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a\nsheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their\nresponses. Besides, there is another valid assignment of species: a wolf,\nsheep, wolf, sheep, wolf and wolf.\n\nLet us remind you: if the neiboring animals are of the same species, a sheep\nanswers `o` and a wolf answers `x`. If the neiboring animals are of different\nspecies, a sheep answers `x` and a wolf answers `o`.\n\n![b34c052fc21c42d2def9b98d6dccd05c.png](https://atcoder.jp/img/arc069/b34c052fc21c42d2def9b98d6dccd05c.png)\n\n* * *"}, {"input": "3\n oox", "output": "-1\n \n\nPrint `-1` if there is no valid assignment of species.\n\n* * *"}, {"input": "10\n oxooxoxoox", "output": "SSWWSSSWWS"}]
Print the maximum value of D that enables you to visit all the cities. * * *
s697667243
Accepted
p03262
Input is given from Standard Input in the following format: N X x_1 x_2 ... x_N
# abc109_c.py # https://atcoder.jp/contests/abc109/tasks/abc109_c # C - Skip / # 実行時間制限: 2 sec / メモリ制限: 1024 MB # 配点 : 300点 # 問題文 # 数直線上に N個の都市があり、i 番目の都市は座標 xiにあります。 # あなたの目的は、これら全ての都市を 1度以上訪れることです。 # あなたは、はじめに正整数 Dを設定します。 # その後、あなたは座標 Xから出発し、以下の移動 1、移動 2を好きなだけ行います。 # 移動 1: 座標 y から座標 y+Dに移動する # 移動 2: 座標 y から座標 y−Dに移動する # 全ての都市を 1度以上訪れることのできる Dの最大値を求めてください。 # ここで、都市を訪れるとは、その都市のある座標に移動することです。 # 制約 # 入力はすべて整数である # 1≤N≤10^5 # 1≤X≤10^9 # 1≤xi≤10^9 # xiはすべて異なる # x1,x2,...,xN≠X # 入力 # 入力は以下の形式で標準入力から与えられる。 # N X # x1 x2 ... xN # 出力 # 全ての都市を 1度以上訪れることのできる Dの最大値を出力せよ。 # 入力例 1 # 3 3 # 1 7 11 # 出力例 1 # 2 # D=2と設定すれば次のように移動を行うことですべての都市を訪れることができ、これが最大です。 # 移動 2を行い、座標 1に移動する # 移動 1を行い、座標 3に移動する # 移動 1を行い、座標 5に移動する # 移動 1を行い、座標 7に移動する # 移動 1を行い、座標 9に移動する # 移動 1を行い、座標 11に移動する # 入力例 2 # 3 81 # 33 105 57 # 出力例 2 # 24 # 入力例 3 # 1 1 # 1000000000 # 出力例 3 # 999999999 def calculation(lines): # N = int(lines[0]) N, X = list(map(int, lines[0].split())) values = list(map(int, lines[1].split())) values.append(X) mi = min(values) # 最小値を起点とする values = [value - mi for value in values] for _ in range(10): # 解の候補として最小値を取得する values = [value for value in values if value > 0] mi = min(values) # 最小値単位のあまりを取得する values = list(set([value % mi for value in values])) if values == [0]: return [mi] # 引数を取得 def get_input_lines(lines_count): lines = list() for _ in range(lines_count): lines.append(input()) return lines # テストデータ def get_testdata(pattern): if pattern == 1: lines_input = ["3 3", "1 7 11"] lines_export = [2] if pattern == 2: lines_input = ["3 81", "33 105 57"] lines_export = [24] if pattern == 3: lines_input = ["1 1", "1000000000"] lines_export = [999999999] return lines_input, lines_export # 動作モード判別 def get_mode(): import sys args = sys.argv if len(args) == 1: mode = 0 else: mode = int(args[1]) return mode # 主処理 def main(): import time started = time.time() mode = get_mode() if mode == 0: lines_input = get_input_lines(2) else: lines_input, lines_export = get_testdata(mode) lines_result = calculation(lines_input) for line_result in lines_result: print(line_result) # if mode > 0: # print(f'lines_input=[{lines_input}]') # print(f'lines_export=[{lines_export}]') # print(f'lines_result=[{lines_result}]') # if lines_result == lines_export: # print('OK') # else: # print('NG') # finished = time.time() # duration = finished - started # print(f'duration=[{duration}]') # 起動処理 if __name__ == "__main__": main()
Statement There are N cities on a number line. The i-th city is located at coordinate x_i. Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D. Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like: * Move 1: travel from coordinate y to coordinate y + D. * Move 2: travel from coordinate y to coordinate y - D. Find the maximum value of D that enables you to visit all the cities. Here, to visit a city is to travel to the coordinate where that city is located.
[{"input": "3 3\n 1 7 11", "output": "2\n \n\nSetting D = 2 enables you to visit all the cities as follows, and this is the\nmaximum value of such D.\n\n * Perform Move 2 to travel to coordinate 1.\n * Perform Move 1 to travel to coordinate 3.\n * Perform Move 1 to travel to coordinate 5.\n * Perform Move 1 to travel to coordinate 7.\n * Perform Move 1 to travel to coordinate 9.\n * Perform Move 1 to travel to coordinate 11.\n\n* * *"}, {"input": "3 81\n 33 105 57", "output": "24\n \n\n* * *"}, {"input": "1 1\n 1000000000", "output": "999999999"}]
Print the maximum value of D that enables you to visit all the cities. * * *
s045559442
Wrong Answer
p03262
Input is given from Standard Input in the following format: N X x_1 x_2 ... x_N
n, x = map(int, input().split()) a = list(map(int, input().split())) res, ans = [], 0 for i in range(n): res.append(abs(a[i] - x)) # print(min(res)) res.sort() ans = res[0] cnt = 0 if n > 1: num = min((n - 1), 11) for j in range(2, num): cmp = a[0] % res[0] * j for s in range(n): if a[s] % res[0] * j != cmp: break else: cnt += 1 if cnt == n: ans = res[0] * j print(ans)
Statement There are N cities on a number line. The i-th city is located at coordinate x_i. Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D. Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like: * Move 1: travel from coordinate y to coordinate y + D. * Move 2: travel from coordinate y to coordinate y - D. Find the maximum value of D that enables you to visit all the cities. Here, to visit a city is to travel to the coordinate where that city is located.
[{"input": "3 3\n 1 7 11", "output": "2\n \n\nSetting D = 2 enables you to visit all the cities as follows, and this is the\nmaximum value of such D.\n\n * Perform Move 2 to travel to coordinate 1.\n * Perform Move 1 to travel to coordinate 3.\n * Perform Move 1 to travel to coordinate 5.\n * Perform Move 1 to travel to coordinate 7.\n * Perform Move 1 to travel to coordinate 9.\n * Perform Move 1 to travel to coordinate 11.\n\n* * *"}, {"input": "3 81\n 33 105 57", "output": "24\n \n\n* * *"}, {"input": "1 1\n 1000000000", "output": "999999999"}]
Print the maximum value of D that enables you to visit all the cities. * * *
s764980609
Runtime Error
p03262
Input is given from Standard Input in the following format: N X x_1 x_2 ... x_N
import numpy as np import math def main(): N, X = map(int, input().split()) x = np.asarray(list(map(int, input().split()))) x = np.absolute(x - X) if N > 1: d = np.absolute(x[:N-1] - x[1:N]) l = None for i, n in enumerate(d): if i == 0: l = n else: l = math.gcd(l, n) print(l) else: print(x[0]) if __name__ == '__main__': main()))
Statement There are N cities on a number line. The i-th city is located at coordinate x_i. Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D. Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like: * Move 1: travel from coordinate y to coordinate y + D. * Move 2: travel from coordinate y to coordinate y - D. Find the maximum value of D that enables you to visit all the cities. Here, to visit a city is to travel to the coordinate where that city is located.
[{"input": "3 3\n 1 7 11", "output": "2\n \n\nSetting D = 2 enables you to visit all the cities as follows, and this is the\nmaximum value of such D.\n\n * Perform Move 2 to travel to coordinate 1.\n * Perform Move 1 to travel to coordinate 3.\n * Perform Move 1 to travel to coordinate 5.\n * Perform Move 1 to travel to coordinate 7.\n * Perform Move 1 to travel to coordinate 9.\n * Perform Move 1 to travel to coordinate 11.\n\n* * *"}, {"input": "3 81\n 33 105 57", "output": "24\n \n\n* * *"}, {"input": "1 1\n 1000000000", "output": "999999999"}]
Print the maximum value of D that enables you to visit all the cities. * * *
s604270272
Runtime Error
p03262
Input is given from Standard Input in the following format: N X x_1 x_2 ... x_N
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10 ** 20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) N, X = LI() X_list = LI() X_list.sort() bisect.insort_left(X_list, X) # print(X_list) X_diff = [j-i for i, j in zip(X_list[:-1], X_list[1:])] print(min(X_diff)
Statement There are N cities on a number line. The i-th city is located at coordinate x_i. Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D. Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like: * Move 1: travel from coordinate y to coordinate y + D. * Move 2: travel from coordinate y to coordinate y - D. Find the maximum value of D that enables you to visit all the cities. Here, to visit a city is to travel to the coordinate where that city is located.
[{"input": "3 3\n 1 7 11", "output": "2\n \n\nSetting D = 2 enables you to visit all the cities as follows, and this is the\nmaximum value of such D.\n\n * Perform Move 2 to travel to coordinate 1.\n * Perform Move 1 to travel to coordinate 3.\n * Perform Move 1 to travel to coordinate 5.\n * Perform Move 1 to travel to coordinate 7.\n * Perform Move 1 to travel to coordinate 9.\n * Perform Move 1 to travel to coordinate 11.\n\n* * *"}, {"input": "3 81\n 33 105 57", "output": "24\n \n\n* * *"}, {"input": "1 1\n 1000000000", "output": "999999999"}]
Print the maximum value of D that enables you to visit all the cities. * * *
s641014766
Runtime Error
p03262
Input is given from Standard Input in the following format: N X x_1 x_2 ... x_N
import sys from fractions import gcd from itertools import groupby as gb from itertools import permutations as perm from itertools import combinations as comb from collections import Counter as C from collections import defaultdict as dd sys.setrecursionlimit(10**5) def y(f): if f: print('Yes') else: print('No') def Y(f): if f: print('YES') else: print('NO') n,x = map(int,input().split()) a = list(map(int,input().split())) p = [] for i in a: p.append(abs(i - x)) g = p[0] for i in p: g = gcd(i, g) print(g)y
Statement There are N cities on a number line. The i-th city is located at coordinate x_i. Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D. Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like: * Move 1: travel from coordinate y to coordinate y + D. * Move 2: travel from coordinate y to coordinate y - D. Find the maximum value of D that enables you to visit all the cities. Here, to visit a city is to travel to the coordinate where that city is located.
[{"input": "3 3\n 1 7 11", "output": "2\n \n\nSetting D = 2 enables you to visit all the cities as follows, and this is the\nmaximum value of such D.\n\n * Perform Move 2 to travel to coordinate 1.\n * Perform Move 1 to travel to coordinate 3.\n * Perform Move 1 to travel to coordinate 5.\n * Perform Move 1 to travel to coordinate 7.\n * Perform Move 1 to travel to coordinate 9.\n * Perform Move 1 to travel to coordinate 11.\n\n* * *"}, {"input": "3 81\n 33 105 57", "output": "24\n \n\n* * *"}, {"input": "1 1\n 1000000000", "output": "999999999"}]
Print the maximum value of D that enables you to visit all the cities. * * *
s896915520
Runtime Error
p03262
Input is given from Standard Input in the following format: N X x_1 x_2 ... x_N
n,x=map(int,input().split()) pos=list(map(int,input().split())) pos2=[abs(p-x) for p in pos] def make_divisor_list(num): if num < 1: return [] elif num == 1: return [1] else: divisor_list = [] divisor_list.append(1) for i in range(2, num // 2 + 1): if num % i == 0: divisor_list.append(i) divisor_list.append(num) return divisor_list if n==1: ans=pos2[0] else: minpos= min(pos2) divs=make_divisor_list(minpos)[::-1] if divs[0]==1:ans=1 else: for j in divs: if all(x%j==0 for x in pos2): ans=j break print(ans)
Statement There are N cities on a number line. The i-th city is located at coordinate x_i. Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D. Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like: * Move 1: travel from coordinate y to coordinate y + D. * Move 2: travel from coordinate y to coordinate y - D. Find the maximum value of D that enables you to visit all the cities. Here, to visit a city is to travel to the coordinate where that city is located.
[{"input": "3 3\n 1 7 11", "output": "2\n \n\nSetting D = 2 enables you to visit all the cities as follows, and this is the\nmaximum value of such D.\n\n * Perform Move 2 to travel to coordinate 1.\n * Perform Move 1 to travel to coordinate 3.\n * Perform Move 1 to travel to coordinate 5.\n * Perform Move 1 to travel to coordinate 7.\n * Perform Move 1 to travel to coordinate 9.\n * Perform Move 1 to travel to coordinate 11.\n\n* * *"}, {"input": "3 81\n 33 105 57", "output": "24\n \n\n* * *"}, {"input": "1 1\n 1000000000", "output": "999999999"}]
Print the maximum value of D that enables you to visit all the cities. * * *
s025735477
Runtime Error
p03262
Input is given from Standard Input in the following format: N X x_1 x_2 ... x_N
N = int(input()) A = [] for i in range(N): A.append(input()) S = 0 for i in range(N-1): if A[i][-1] == A[i+1][0]: S += 1 B = 0 for i in range(N): for j in range(N): if A[i] == A[j]: B += 1 else: B += 0 if S == N-1 and B == N: print('Yes') else: print('No')
Statement There are N cities on a number line. The i-th city is located at coordinate x_i. Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D. Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like: * Move 1: travel from coordinate y to coordinate y + D. * Move 2: travel from coordinate y to coordinate y - D. Find the maximum value of D that enables you to visit all the cities. Here, to visit a city is to travel to the coordinate where that city is located.
[{"input": "3 3\n 1 7 11", "output": "2\n \n\nSetting D = 2 enables you to visit all the cities as follows, and this is the\nmaximum value of such D.\n\n * Perform Move 2 to travel to coordinate 1.\n * Perform Move 1 to travel to coordinate 3.\n * Perform Move 1 to travel to coordinate 5.\n * Perform Move 1 to travel to coordinate 7.\n * Perform Move 1 to travel to coordinate 9.\n * Perform Move 1 to travel to coordinate 11.\n\n* * *"}, {"input": "3 81\n 33 105 57", "output": "24\n \n\n* * *"}, {"input": "1 1\n 1000000000", "output": "999999999"}]
Print the maximum value of D that enables you to visit all the cities. * * *
s016792776
Runtime Error
p03262
Input is given from Standard Input in the following format: N X x_1 x_2 ... x_N
L = [input() for x in " " * int(input())] print("YNeos"[any(i[-1] != j[0] * L.count(i) for i, j in zip(L, L[1:])) :: 2])
Statement There are N cities on a number line. The i-th city is located at coordinate x_i. Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D. Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like: * Move 1: travel from coordinate y to coordinate y + D. * Move 2: travel from coordinate y to coordinate y - D. Find the maximum value of D that enables you to visit all the cities. Here, to visit a city is to travel to the coordinate where that city is located.
[{"input": "3 3\n 1 7 11", "output": "2\n \n\nSetting D = 2 enables you to visit all the cities as follows, and this is the\nmaximum value of such D.\n\n * Perform Move 2 to travel to coordinate 1.\n * Perform Move 1 to travel to coordinate 3.\n * Perform Move 1 to travel to coordinate 5.\n * Perform Move 1 to travel to coordinate 7.\n * Perform Move 1 to travel to coordinate 9.\n * Perform Move 1 to travel to coordinate 11.\n\n* * *"}, {"input": "3 81\n 33 105 57", "output": "24\n \n\n* * *"}, {"input": "1 1\n 1000000000", "output": "999999999"}]
Print the maximum value of D that enables you to visit all the cities. * * *
s523539388
Accepted
p03262
Input is given from Standard Input in the following format: N X x_1 x_2 ... x_N
############################################################################### from sys import stdout from bisect import bisect_left as binl from copy import copy, deepcopy mod = 1 def intin(): input_tuple = input().split() if len(input_tuple) <= 1: return int(input_tuple[0]) return tuple(map(int, input_tuple)) def intina(): return [int(i) for i in input().split()] def intinl(count): return [intin() for _ in range(count)] def modadd(x, y): global mod return (x + y) % mod def modmlt(x, y): global mod return (x * y) % mod def lcm(x, y): while y != 0: z = x % y x = y y = z return x def combination(x, y): assert x >= y if y > x // 2: y = x - y ret = 1 for i in range(0, y): j = x - i i = i + 1 ret = ret * j ret = ret // i return ret def get_divisors(x): retlist = [] for i in range(1, int(x**0.5) + 3): if x % i == 0: retlist.append(i) retlist.append(x // i) return retlist def get_factors(x): retlist = [] for i in range(2, int(x**0.5) + 3): while x % i == 0: retlist.append(i) x = x // i retlist.append(x) return retlist def make_linklist(xylist): linklist = {} for a, b in xylist: linklist.setdefault(a, []) linklist.setdefault(b, []) linklist[a].append(b) linklist[b].append(a) return linklist def calc_longest_distance(linklist, v=1): distance_list = {} distance_count = 0 distance = 0 vlist_previous = [] vlist = [v] nodecount = len(linklist) while distance_count < nodecount: vlist_next = [] for v in vlist: distance_list[v] = distance distance_count += 1 vlist_next.extend(linklist[v]) distance += 1 vlist_to_del = vlist_previous vlist_previous = vlist vlist = list(set(vlist_next) - set(vlist_to_del)) max_distance = -1 max_v = None for v, distance in distance_list.items(): if distance > max_distance: max_distance = distance max_v = v return (max_distance, max_v) def calc_tree_diameter(linklist, v=1): _, u = calc_longest_distance(linklist, v) distance, _ = calc_longest_distance(linklist, u) return distance ############################################################################### def main(): N, X = intin() xlist = intina() x_relative_list = [x - X for x in xlist] ans = None for xr in x_relative_list: xr = abs(xr) if ans is None: ans = xr continue ans = lcm(ans, xr) print(ans) if __name__ == "__main__": main()
Statement There are N cities on a number line. The i-th city is located at coordinate x_i. Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D. Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like: * Move 1: travel from coordinate y to coordinate y + D. * Move 2: travel from coordinate y to coordinate y - D. Find the maximum value of D that enables you to visit all the cities. Here, to visit a city is to travel to the coordinate where that city is located.
[{"input": "3 3\n 1 7 11", "output": "2\n \n\nSetting D = 2 enables you to visit all the cities as follows, and this is the\nmaximum value of such D.\n\n * Perform Move 2 to travel to coordinate 1.\n * Perform Move 1 to travel to coordinate 3.\n * Perform Move 1 to travel to coordinate 5.\n * Perform Move 1 to travel to coordinate 7.\n * Perform Move 1 to travel to coordinate 9.\n * Perform Move 1 to travel to coordinate 11.\n\n* * *"}, {"input": "3 81\n 33 105 57", "output": "24\n \n\n* * *"}, {"input": "1 1\n 1000000000", "output": "999999999"}]
Print the maximum value of D that enables you to visit all the cities. * * *
s326349808
Runtime Error
p03262
Input is given from Standard Input in the following format: N X x_1 x_2 ... x_N
N, X = map(int, input().split()) Alist = list(map(int, input().split())) for i in range(len(Alist)): Alist[i] = abs(Alist[i] - X) Alist.sort() p = [] q = 1 for i in range(1, len(Alist)): if Alist[i] % Alist[0] != 0: p.appnd(Alist[i] % Alist[0]) q = q * 0 p.sort() r = 1 if p != []: for i in range(0, len(Alist)): if Alist[i] % p[0] != 0: r = r * 0 if len(Alist) > 1: if q == 0 and r == 1: print(p[0]) if q == 0 and r == 0: print(1) if q == 1: print(Alist[0]) else: print(Alist[0])
Statement There are N cities on a number line. The i-th city is located at coordinate x_i. Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D. Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like: * Move 1: travel from coordinate y to coordinate y + D. * Move 2: travel from coordinate y to coordinate y - D. Find the maximum value of D that enables you to visit all the cities. Here, to visit a city is to travel to the coordinate where that city is located.
[{"input": "3 3\n 1 7 11", "output": "2\n \n\nSetting D = 2 enables you to visit all the cities as follows, and this is the\nmaximum value of such D.\n\n * Perform Move 2 to travel to coordinate 1.\n * Perform Move 1 to travel to coordinate 3.\n * Perform Move 1 to travel to coordinate 5.\n * Perform Move 1 to travel to coordinate 7.\n * Perform Move 1 to travel to coordinate 9.\n * Perform Move 1 to travel to coordinate 11.\n\n* * *"}, {"input": "3 81\n 33 105 57", "output": "24\n \n\n* * *"}, {"input": "1 1\n 1000000000", "output": "999999999"}]
Print the maximum value of D that enables you to visit all the cities. * * *
s219422018
Accepted
p03262
Input is given from Standard Input in the following format: N X x_1 x_2 ... x_N
def yakusuu(i, m): _i = i while i**2 <= m: if m % i == 0: return i else: i += 1 for j in range(_i - 1, 0, -1): if m % j == 0: break return m // j def factoring(N, result): original_N = N tmp = 2 while tmp <= N and (tmp - 1) ** 2 <= original_N: tmp = yakusuu(tmp, N) result.append(tmp) N //= tmp N, start = map(int, input().split()) x = list(map(int, input().split())) tmp_list = [] factoring(abs(x[0] - start), tmp_list) for i in range(N - 1): now = abs(x[i] - x[i + 1]) new_list = [] for j in tmp_list: if now % j == 0: now //= j new_list.append(j) tmp_list = [new_list[i] for i in range(len(new_list))] ans = 1 for j in tmp_list: ans *= j print(ans)
Statement There are N cities on a number line. The i-th city is located at coordinate x_i. Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D. Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like: * Move 1: travel from coordinate y to coordinate y + D. * Move 2: travel from coordinate y to coordinate y - D. Find the maximum value of D that enables you to visit all the cities. Here, to visit a city is to travel to the coordinate where that city is located.
[{"input": "3 3\n 1 7 11", "output": "2\n \n\nSetting D = 2 enables you to visit all the cities as follows, and this is the\nmaximum value of such D.\n\n * Perform Move 2 to travel to coordinate 1.\n * Perform Move 1 to travel to coordinate 3.\n * Perform Move 1 to travel to coordinate 5.\n * Perform Move 1 to travel to coordinate 7.\n * Perform Move 1 to travel to coordinate 9.\n * Perform Move 1 to travel to coordinate 11.\n\n* * *"}, {"input": "3 81\n 33 105 57", "output": "24\n \n\n* * *"}, {"input": "1 1\n 1000000000", "output": "999999999"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s710124909
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
a, b, c, d = map(int, input().split()) print(max(min(b, d) - max(a, c), 0)
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s789154881
Wrong Answer
p03632
Input is given from Standard Input in the following format: A B C D
a, b, c, _ = map(int, input().split()) print(max(0, b - c - a))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s132632651
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
A, B, C, D=map(int, input().split()) X=set([for i in range(A, B+1)]) print(sum([1 for i in range(C, D+1) if i in X]))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s491191645
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
import sys input = sys.stdin.readline().strip a,b,c,d=map(int,input().split()) if b<c or d<a: print(0) elif print(max(b,d)-min(a,c))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s067289910
Accepted
p03632
Input is given from Standard Input in the following format: A B C D
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify import sys, bisect, math, itertools sys.setrecursionlimit(10**8) mod = 10**9 + 7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) a, b, c, d = inpl() res = 0 for i in range(a, d + 1): if i <= b and i >= c: res += 1 print(max(0, res - 1))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s788631619
Wrong Answer
p03632
Input is given from Standard Input in the following format: A B C D
# region header import sys import math from bisect import bisect_left, bisect_right, insort_left, insort_right from collections import defaultdict, deque, Counter from copy import deepcopy from fractions import gcd from functools import lru_cache, reduce from heapq import heappop, heappush from itertools import ( accumulate, groupby, product, permutations, combinations, combinations_with_replacement, ) from math import ceil, floor, factorial, log, sqrt, sin, cos from operator import itemgetter from string import ascii_lowercase, ascii_uppercase, digits sys.setrecursionlimit(10**7) rs = lambda: sys.stdin.readline().rstrip() ri = lambda: int(rs()) rf = lambda: float(rs()) rs_ = lambda: [_ for _ in rs().split()] ri_ = lambda: [int(_) for _ in rs().split()] rf_ = lambda: [float(_) for _ in rs().split()] INF = float("inf") MOD = 10**9 + 7 # endregion A, B, C, D = ri_() print(min(B, D) - max(A, C))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s215954687
Accepted
p03632
Input is given from Standard Input in the following format: A B C D
( a, b, c, d, ) = map(int, input().split()) print(max(min(b, d) - max(a, c), 0))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s993614742
Accepted
p03632
Input is given from Standard Input in the following format: A B C D
a, c, b, d = map(int, input().split(" ")) print(max(0, min(c, d) - max(a, b)))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s309710687
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
a,b,c,d=map(int,input().split()) print(max(0,min(b,d)-max(a,c))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s749829522
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
A,B,C,D = [int(i) for i in input().split()] print(min(0,min(B,D) - max(A,C))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s425281406
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
a, b, c, d = map((int, input().split())) start = min(a, b) end = min(c, d) print(end - start if end - start > 0 else 0)
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s998304333
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
A,B,C,D=map(int,input().split()) if A <= C and C <= B and B <= D: print(B-C) elif C <= A and A <= B and B <= D: print(B-A) elif A <= B and B <= C and C <= D: print(0) elif C <= A and A <= D and D <= B: print(D-A) elif A <= C and C <= D and D <= B: print(D-C) else C <= D and D <= A and A <= B: print(0)
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s154406963
Wrong Answer
p03632
Input is given from Standard Input in the following format: A B C D
a = input().split() ast = int(a[0]) aen = int(a[1]) bst = int(a[2]) ben = int(a[3]) if ast > ben or bst > aen: print("0") elif ast < bst and aen < ben: print(aen - bst) elif ast < bst and aen > ben: print(ben - bst) elif bst < ast and ben < aen: print(ben - ast) elif bst < ast and ben > aen: print(aen - ast)
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s675685926
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
a, b, c, d = map(int, input().split()) if (b <= c or d <= a): print(0) elif (b <= d or c <= a): print(max(abs(a - d) - abs(a - c) - abs(b - d), abs(b - c) - abs(a - c) - abs(b - d))) else: print(max(abs(a - b) - abs(a - c) - abs(b - d), abs(c - d) - abs(a - c) - abs(b - d))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s346705652
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
a,b,c,d = map(int, input().split()) if c >= b or a >= d: print(0) else: if a <= c: print(min(b-c,d-c)) else: print(min(d-a,b-a)
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s867212947
Accepted
p03632
Input is given from Standard Input in the following format: A B C D
a_list = list(map(int, input().split())) a, b, c, d = a_list[0], a_list[1], a_list[2], a_list[3] start = 0 alice_time = (a, b) bob_time = (c, d) max_end = max(b, d) alice_zone = [0] * max_end bob_zone = [0] * max_end alice_zone[a:b] = [1] * len(alice_zone[a:b]) bob_zone[c:d] = [1] * len(bob_zone[c:d]) kasanari_zone = [alice * bob for alice, bob, in zip(alice_zone, bob_zone)] print(sum(kasanari_zone))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s388661907
Accepted
p03632
Input is given from Standard Input in the following format: A B C D
nums = [int(x) for x in input().split()] nums = [[nums[0], nums[1]], [nums[2], nums[3]]] N = 100 imos = [0 for i in range(N + 2)] for num in nums: a, b = num[0], num[1] - 1 imos[a] += 1 imos[b + 1] -= 1 ans = [] j = 0 for i in imos: ans.append(j + i) j += i print(ans.count(2))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s834081843
Accepted
p03632
Input is given from Standard Input in the following format: A B C D
arr = [int(x) for x in input().split()] if arr[0] < arr[2]: if arr[2] <= arr[1] <= arr[3]: print(arr[1] - arr[2]) elif arr[1] < arr[2]: print("0") else: print(arr[3] - arr[2]) else: if arr[0] <= arr[3] <= arr[1]: print(arr[3] - arr[0]) elif arr[3] < arr[0]: print("0") else: print(arr[1] - arr[0])
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s888068715
Wrong Answer
p03632
Input is given from Standard Input in the following format: A B C D
def ans(nlist, max, min): if (int)(nlist[max]) > (int)(nlist[min + 1]) or (int)(nlist[min]) > (int)( nlist[max + 1] ): print(0) return if (int)(nlist[min]) < (int)(nlist[max]): print((int)(nlist[min + 1]) - (int)(nlist[max])) return if (int)(nlist[min + 1]) > (int)(nlist[max + 1]): print((int)(nlist[max + 1]) - (int)(nlist[min])) return print((int)(nlist[min + 1]) - (int)(nlist[min])) fnum = input() fnum = fnum.split(" ") max = 0 if (int(fnum[1]) - int(fnum[0])) > (int(fnum[2]) - int(fnum[3])) else 2 min = 2 - max ans(fnum, max, min)
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s451781623
Accepted
p03632
Input is given from Standard Input in the following format: A B C D
x = list(map(int, input().split())) imos = [0] * (max(x) + 2) imos[x[0]] += 1 imos[x[1] + 1] -= 1 imos[x[2]] += 1 imos[x[3] + 1] -= 1 for i in range(len(imos) - 1): imos[i + 1] += imos[i] print(max(imos.count(2) - 1, 0))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s637350158
Accepted
p03632
Input is given from Standard Input in the following format: A B C D
l = list(map(int, input().split())) ans = min(l[1], l[3]) - max(l[0], l[2]) print(ans if ans > 0 else 0)
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s727705071
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
# -*- coding: utf-8 -*- A,B,C,D = map(int,input().split()) L = [A:B] M = [C:D] print(L&M)
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s909091436
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
a, b, c, d = input().split(" ") time = min(b, d) - max(a, c) print(time if time else 0)
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s262783487
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
a,b,c,d = map(int, input().split()) if a > c: a,b,c,d = c,d,a,b if b < c:print(0) elif b => c and b < d:print(b-c) else : print(d-c)
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s901989061
Runtime Error
p03632
Input is given from Standard Input in the following format: A B C D
if __name__ == '__main__': A, B, C, D = map(int, input().split()) if B <= C or D <= A: print(0) else: if A < C: print(B-C) elif A > C print(D - A) else: if B < D: print(B-A) else: print(D-A)
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s937572129
Accepted
p03632
Input is given from Standard Input in the following format: A B C D
as1, ae, bs, be = map(int, input().split()) da = {as1: "AS", ae: "AE"} db = {bs: "BS", be: "BE"} order = [as1, ae, bs, be] order.sort() Alice = False Bob = False start = -1 end = -1 for t in order: if t in da and da[t] == "AS": Alice = True if t in db and db[t] == "BS": Bob = True if t in da and da[t] == "AE": Alice = False if t in db and db[t] == "BE": Bob = False if Alice and Bob: start = t if start != -1 and (not (Alice) or not (Bob)): end = t break # print(str(start) + " " + str(end)) print(str(end - start))
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s928478683
Accepted
p03632
Input is given from Standard Input in the following format: A B C D
def inputs(num_of_input): ins = [input() for i in range(num_of_input)] return ins def solve(inputs): i = inputs[0].split() times = {"a": {}, "b": {}} times["a"]["start"] = int(i[0]) times["a"]["end"] = int(i[1]) times["b"]["start"] = int(i[2]) times["b"]["end"] = int(i[3]) first_start = "a" if times["a"]["start"] < times["b"]["start"] else "b" second_start = "b" if first_start == "a" else "a" first_end = "a" if times["a"]["end"] < times["b"]["end"] else "b" second_end = "b" if first_end == "a" else "a" if second_start == first_end: return times[first_end]["end"] - times[second_start]["start"] if times[first_end]["end"] < times[second_start]["start"]: return 0 return ( (times[second_end]["end"] - times[first_start]["start"]) - (times[second_start]["start"] - times[first_start]["start"]) - (times[second_end]["end"] - times[first_end]["end"]) ) if __name__ == "__main__": ret = solve(inputs(1)) print(ret)
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. * * *
s973118102
Wrong Answer
p03632
Input is given from Standard Input in the following format: A B C D
import sys a, b, c, d = map(int, input().split(" ")) box = [] box.append(a) box.append(b) box.append(c) box.append(d) count = [] for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): for l in range(d + 1): if c < (b - a): box.sort() p = box[-2] q = box[-3] print(abs(q - p)) sys.exit() else: print(0) sys.exit()
Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
[{"input": "0 75 25 100", "output": "50\n \n\nAlice started holding down her button 0 second after the start-up of the\nrobot, and released her button 75 second after the start-up. \nBob started holding down his button 25 second after the start-up, and released\nhis button 100 second after the start-up. \nTherefore, the time when both of them were holding down their buttons, is the\n50 seconds from 25 seconds after the start-up to 75 seconds after the start-\nup.\n\n* * *"}, {"input": "0 33 66 99", "output": "0\n \n\nAlice and Bob were not holding their buttons at the same time, so the answer\nis zero seconds.\n\n* * *"}, {"input": "10 90 20 80", "output": "60"}]
If it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S, print `Yes`; otherwise, print `No`. * * *
s826069160
Wrong Answer
p02920
Input is given from Standard Input in the following format: N S_1 S_2 ... S_{2^N}
n, a, p, f = int(input()), sorted(list(map(int, input().split())))[::-1], 1, 0 while p < 2**n: for j, k in zip(a[:p], a[p : 2 * p]): if j <= k: f = 1 p *= 2 print("YNeos"[f::2])
Statement We have one slime. You can set the _health_ of this slime to any integer value of your choice. A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second. Determine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S. Here S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N}.
[{"input": "2\n 4 2 3 1", "output": "Yes\n \n\nWe will show one way to make the multiset of the healths of the slimes that\nwill exist in 2 seconds equal to S.\n\nFirst, set the health of the first slime to 4.\n\nBy letting the first slime spawn a slime whose health is 3, the healths of the\nslimes that exist in 1 second can be 4,~3.\n\nThen, by letting the first slime spawn a slime whose health is 2, and letting\nthe second slime spawn a slime whose health is 1, the healths of the slimes\nthat exist in 2 seconds can be 4,~3,~2,~1, which is equal to S as multisets.\n\n* * *"}, {"input": "2\n 1 2 3 1", "output": "Yes\n \n\nS may contain multiple instances of the same integer.\n\n* * *"}, {"input": "1\n 1 1", "output": "No\n \n\n* * *"}, {"input": "5\n 4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3", "output": "No"}]
If it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S, print `Yes`; otherwise, print `No`. * * *
s078448209
Wrong Answer
p02920
Input is given from Standard Input in the following format: N S_1 S_2 ... S_{2^N}
n = int(input()) a = [int(i) for i in input().split()] # a.sort(reverse=True) s = 0 ans = 1 # print(a) # for i in range(n): # for j in range(2**i): # print(i," ",a[j],a[2**i+j],j,2**i+j) # if(a[j]<=a[2**i+j]): # ans=0 # break # if(ans==0): break print("No") # if ans==1:print("Yes") # else:print("No")
Statement We have one slime. You can set the _health_ of this slime to any integer value of your choice. A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second. Determine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S. Here S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N}.
[{"input": "2\n 4 2 3 1", "output": "Yes\n \n\nWe will show one way to make the multiset of the healths of the slimes that\nwill exist in 2 seconds equal to S.\n\nFirst, set the health of the first slime to 4.\n\nBy letting the first slime spawn a slime whose health is 3, the healths of the\nslimes that exist in 1 second can be 4,~3.\n\nThen, by letting the first slime spawn a slime whose health is 2, and letting\nthe second slime spawn a slime whose health is 1, the healths of the slimes\nthat exist in 2 seconds can be 4,~3,~2,~1, which is equal to S as multisets.\n\n* * *"}, {"input": "2\n 1 2 3 1", "output": "Yes\n \n\nS may contain multiple instances of the same integer.\n\n* * *"}, {"input": "1\n 1 1", "output": "No\n \n\n* * *"}, {"input": "5\n 4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3", "output": "No"}]
If it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S, print `Yes`; otherwise, print `No`. * * *
s016567455
Wrong Answer
p02920
Input is given from Standard Input in the following format: N S_1 S_2 ... S_{2^N}
print("Yes")
Statement We have one slime. You can set the _health_ of this slime to any integer value of your choice. A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second. Determine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S. Here S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N}.
[{"input": "2\n 4 2 3 1", "output": "Yes\n \n\nWe will show one way to make the multiset of the healths of the slimes that\nwill exist in 2 seconds equal to S.\n\nFirst, set the health of the first slime to 4.\n\nBy letting the first slime spawn a slime whose health is 3, the healths of the\nslimes that exist in 1 second can be 4,~3.\n\nThen, by letting the first slime spawn a slime whose health is 2, and letting\nthe second slime spawn a slime whose health is 1, the healths of the slimes\nthat exist in 2 seconds can be 4,~3,~2,~1, which is equal to S as multisets.\n\n* * *"}, {"input": "2\n 1 2 3 1", "output": "Yes\n \n\nS may contain multiple instances of the same integer.\n\n* * *"}, {"input": "1\n 1 1", "output": "No\n \n\n* * *"}, {"input": "5\n 4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3", "output": "No"}]
If it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S, print `Yes`; otherwise, print `No`. * * *
s001035859
Wrong Answer
p02920
Input is given from Standard Input in the following format: N S_1 S_2 ... S_{2^N}
import random s = ["Yes", "No"] print(random.choice(s))
Statement We have one slime. You can set the _health_ of this slime to any integer value of your choice. A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second. Determine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S. Here S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N}.
[{"input": "2\n 4 2 3 1", "output": "Yes\n \n\nWe will show one way to make the multiset of the healths of the slimes that\nwill exist in 2 seconds equal to S.\n\nFirst, set the health of the first slime to 4.\n\nBy letting the first slime spawn a slime whose health is 3, the healths of the\nslimes that exist in 1 second can be 4,~3.\n\nThen, by letting the first slime spawn a slime whose health is 2, and letting\nthe second slime spawn a slime whose health is 1, the healths of the slimes\nthat exist in 2 seconds can be 4,~3,~2,~1, which is equal to S as multisets.\n\n* * *"}, {"input": "2\n 1 2 3 1", "output": "Yes\n \n\nS may contain multiple instances of the same integer.\n\n* * *"}, {"input": "1\n 1 1", "output": "No\n \n\n* * *"}, {"input": "5\n 4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3", "output": "No"}]
If it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S, print `Yes`; otherwise, print `No`. * * *
s320627344
Accepted
p02920
Input is given from Standard Input in the following format: N S_1 S_2 ... S_{2^N}
from bisect import bisect_left class SegTree: def segfunc(self, x, y): return x + y def __init__(self, ide, init_val): n = len(init_val) self.ide_ele = ide self.num = 2 ** (n - 1).bit_length() self.seg = [self.ide_ele] * 2 * self.num for i in range(n): self.seg[i + self.num - 1] = init_val[i] for i in range(self.num - 2, -1, -1): self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) def update(self, idx, val): idx += self.num - 1 self.seg[idx] = val while idx: idx = (idx - 1) // 2 self.seg[idx] = self.segfunc(self.seg[idx * 2 + 1], self.seg[idx * 2 + 2]) def query(self, begin, end): if end <= begin: return self.ide_ele begin += self.num - 1 end += self.num - 2 res = self.ide_ele while begin + 1 < end: if begin & 1 == 0: res = self.segfunc(res, self.seg[begin]) if end & 1 == 1: res = self.segfunc(res, self.seg[end]) end -= 1 begin = begin // 2 end = (end - 1) // 2 if begin == end: res = self.segfunc(res, self.seg[begin]) else: res = self.segfunc(self.segfunc(res, self.seg[begin]), self.seg[end]) return res def main(): lim = int(input()) s = list(map(int, input().split())) n = len(s) s.sort() f = True tmp = [1] * n tmp[n - 1] = 0 seg = SegTree(0, tmp) st = set() st.add(n - 1) for _ in range(1, lim + 1): adst = set() for v in st: u = bisect_left(s, s[v]) if seg.query(0, u) == 0: f = False break L, R = 0, u while L + 1 < R: P = (L + R) // 2 if seg.query(P, u) > 0: L = P else: R = P seg.update(L, 0) adst.add(L) for v in adst: st.add(v) if f: print("Yes") else: print("No") if __name__ == "__main__": main()
Statement We have one slime. You can set the _health_ of this slime to any integer value of your choice. A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second. Determine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S. Here S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N}.
[{"input": "2\n 4 2 3 1", "output": "Yes\n \n\nWe will show one way to make the multiset of the healths of the slimes that\nwill exist in 2 seconds equal to S.\n\nFirst, set the health of the first slime to 4.\n\nBy letting the first slime spawn a slime whose health is 3, the healths of the\nslimes that exist in 1 second can be 4,~3.\n\nThen, by letting the first slime spawn a slime whose health is 2, and letting\nthe second slime spawn a slime whose health is 1, the healths of the slimes\nthat exist in 2 seconds can be 4,~3,~2,~1, which is equal to S as multisets.\n\n* * *"}, {"input": "2\n 1 2 3 1", "output": "Yes\n \n\nS may contain multiple instances of the same integer.\n\n* * *"}, {"input": "1\n 1 1", "output": "No\n \n\n* * *"}, {"input": "5\n 4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3", "output": "No"}]
If it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S, print `Yes`; otherwise, print `No`. * * *
s563216754
Accepted
p02920
Input is given from Standard Input in the following format: N S_1 S_2 ... S_{2^N}
class BinaryIndexTree: # 1-indexed def __init__(self, N): """ INPUT N [int] -> 全部0で初期化 N [list] -> そのまま初期化 """ if isinstance(N, int): self.N = N self.depth = N.bit_length() self.tree = [0] * (N + 1) self.elem = [0] * (N + 1) elif isinstance(N, list): self.N = len(N) self.depth = self.N.bit_length() self.tree = [0] + N self.elem = [0] + N self._init() else: raise "INVALID INPUT: input must be int or list" def _init(self): size = self.N for i in range(1, self.N): if i + (i & -i) > size: continue self.tree[i + (i & -i)] += self.tree[i] def add(self, i, x): self.elem[i] += x while i <= self.N: self.tree[i] += x i += i & -i def sum(self, i): res = 0 while i > 0: res += self.tree[i] i -= i & -i return res def lower_bound(self, val): if val <= 0: return 0 i = 0 k = 1 << self.depth while k: if i + k <= self.N and self.tree[i + k] < val: val -= self.tree[i + k] i += k k >>= 1 return i + 1 N = int(input()) A = list(map(int, input().split())) atoi = {a: i + 1 for i, a in enumerate(sorted(set(A)))} bit = BinaryIndexTree(len(atoi) + 5) for a in A: i = atoi[a] bit.add(i, 1) slime = [] p = bit.lower_bound(1 << N) slime.append(p) bit.add(p, -1) for _ in range(N): next_slime = [] for s in slime: tot = bit.sum(s - 1) p = bit.lower_bound(tot) if p == 0: print("No") exit() next_slime.append(p) bit.add(p, -1) slime += next_slime print("Yes")
Statement We have one slime. You can set the _health_ of this slime to any integer value of your choice. A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second. Determine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S. Here S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N}.
[{"input": "2\n 4 2 3 1", "output": "Yes\n \n\nWe will show one way to make the multiset of the healths of the slimes that\nwill exist in 2 seconds equal to S.\n\nFirst, set the health of the first slime to 4.\n\nBy letting the first slime spawn a slime whose health is 3, the healths of the\nslimes that exist in 1 second can be 4,~3.\n\nThen, by letting the first slime spawn a slime whose health is 2, and letting\nthe second slime spawn a slime whose health is 1, the healths of the slimes\nthat exist in 2 seconds can be 4,~3,~2,~1, which is equal to S as multisets.\n\n* * *"}, {"input": "2\n 1 2 3 1", "output": "Yes\n \n\nS may contain multiple instances of the same integer.\n\n* * *"}, {"input": "1\n 1 1", "output": "No\n \n\n* * *"}, {"input": "5\n 4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3", "output": "No"}]
Print the difference in a line.
s326788920
Accepted
p02473
Two integers $A$ and $B$ separated by a space character are given in a line.
m, n = map(int, input().split()) print(m - n)
Difference of Big Integers Given two integers $A$ and $B$, compute the difference, $A - B$.
[{"input": "5 8", "output": "-3"}, {"input": "100 25", "output": "75"}, {"input": "-1 -1", "output": "0"}, {"input": "12 -3", "output": "15"}]
Print the difference in a line.
s316669836
Accepted
p02473
Two integers $A$ and $B$ separated by a space character are given in a line.
a = input().split() print(int(a[0]) - int(a[1]))
Difference of Big Integers Given two integers $A$ and $B$, compute the difference, $A - B$.
[{"input": "5 8", "output": "-3"}, {"input": "100 25", "output": "75"}, {"input": "-1 -1", "output": "0"}, {"input": "12 -3", "output": "15"}]
Print the difference in a line.
s216014644
Accepted
p02473
Two integers $A$ and $B$ separated by a space character are given in a line.
if __name__ == "__main__": a, b = list(map(lambda x: int(x), input().split())) print(a - b)
Difference of Big Integers Given two integers $A$ and $B$, compute the difference, $A - B$.
[{"input": "5 8", "output": "-3"}, {"input": "100 25", "output": "75"}, {"input": "-1 -1", "output": "0"}, {"input": "12 -3", "output": "15"}]
Print the difference in a line.
s305243849
Accepted
p02473
Two integers $A$ and $B$ separated by a space character are given in a line.
s = input().split() print(int(s[0]) - int(s[1]))
Difference of Big Integers Given two integers $A$ and $B$, compute the difference, $A - B$.
[{"input": "5 8", "output": "-3"}, {"input": "100 25", "output": "75"}, {"input": "-1 -1", "output": "0"}, {"input": "12 -3", "output": "15"}]
Print the answer. * * *
s922434143
Wrong Answer
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
[N, M] = [int(_) for _ in input().split()] C = set([i for i in range(1, N + 1)]) R = [] for m in range(M): [A, B] = [int(_) for _ in input().split()] C.discard(A) C.discard(B) f = False for r in R: if A in r: r.append(B) f = True break if not f: R.append([A, B]) # print(*R) # print(*C) S = [ set(R[0]), ] for i in range(1, len(R)): f = False # print(R[i], *S) for r in R[i]: for j, s in enumerate(S): S[j] = s.union(set(R[i])) f = True break if not f: S.append(set(R[i])) # print(*S) print(len(S) + len(C) - 1)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s950527274
Accepted
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
from typing import Dict, List N, M = [int(x) for x in input().split()] class UnionFind: def __init__(self, num_node: int): self.__parent_index = [x for x in range(num_node)] self.__tree_rank = [1] * num_node def __is_root(self, index: int) -> bool: return self.__parent_index[index] == index def root(self, index: int) -> int: """Find root index.""" while not self.__is_root(index): index = self.__parent_index[index] = self.root(self.__parent_index[index]) return index def unite(self, x: int, y: int) -> bool: """Unite two trees.""" x = self.root(x) y = self.root(y) if x == y: return False if self.__tree_rank[x] < self.__tree_rank[y]: x, y = y, x self.__tree_rank[x] += self.__tree_rank[y] self.__parent_index[y] = x return True def groups(self) -> Dict[int, List[int]]: __groups: Dict[int, List[int]] = {} for node, parent in enumerate(self.__parent_index): __root = self.root(parent) if __groups.get(__root) is None: __groups[__root] = [node] else: __groups[__root].append(node) return __groups uni = UnionFind(N) for i in range(M): a, b = [int(x) - 1 for x in input().split()] uni.unite(a, b) print(len(uni.groups()) - 1)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s851313897
Runtime Error
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
class Vertex(object): def __init__(self, id): self.id = id self.adjacent = {} # DFS self.visited = False def add_neighbor(self, neighbor, weight=0): self.adjacent[neighbor] = weight def get_neighbors(self): return self.adjacent def get_connections(self): return self.adjacent.keys() def get_vertex_id(self): return self.id def get_weight(self, neighbor): return self.adjacent[neighbor] # DFS def set_visited(self): self.visited = True class Graph(object): def __init__(self): self.vertex_dict = {} self.num_vertex = 0 # DFS ループで扱いやすくする。 def __iter__(self): return iter(self.vertex_dict.values()) def add_vertex(self, id): self.num_vertex = self.num_vertex + 1 new_vertex = Vertex(id) self.vertex_dict[id] = new_vertex return new_vertex def get_vertex(self, id): if id in self.vertex_dict: return self.vertex_dict[id] else: return None def add_edge(self, frm, to, weight=0): if frm not in self.vertex_dict: self.add_vertex(frm) if to not in self.vertex_dict: self.add_vertex(to) self.vertex_dict[frm].add_neighbor(self.vertex_dict[to], weight) # 有向グラフの場合は別 self.vertex_dict[to].add_neighbor(self.vertex_dict[frm], weight) def get_vertices(self): return self.vertex_dict.keys() def get_edges(self): edges = [] for v in self.vertex_dict.values(): for w in v.get_connections(): vid = v.get_vertex_id() wid = w.get_vertex_id() edges.append((vid, wid, v.get_weight(w))) return edges def dfs(graph, current_vertex, traversal_verticies): current_vertex.set_visited() traversal_verticies.append(current_vertex.get_vertex_id()) for neighbor in current_vertex.get_connections(): if not (neighbor.visited): dfs(graph, neighbor, traversal_verticies) def dfs_traversal(graph): n = 0 for current_vertex in graph: traversal_verticies = [] if not (current_vertex.visited): dfs(graph, current_vertex, traversal_verticies) if traversal_verticies: n += 1 print(n - 1) if __name__ == "__main__": graph = Graph() N, M = (int(i) for i in input().split()) for i in range(N): graph.add_vertex(i + 1) for i in range(M): a, b = (int(i) for i in input().split()) graph.add_edge(a, b) dfs_traversal(graph)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s110446094
Runtime Error
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
n, m = map(int, input().split()) ab = [map(int, input().split()) for _ in range(m)] a, b = [list(i) for i in zip(*ab)] can_stay = [] branch_stay = [] can_flag_a = 0 can_flag_b = 0 branch_node = 0 need_road = 0 can_stay.append(a[0]) can_stay.append(b[0]) for road in range(1, m): can_flag_a = 0 can_flag_b = 0 for cnt_can in range(len(can_stay)): if can_stay[cnt_can] == a[road]: can_flag_a = 1 for cnt_can in range(len(can_stay)): if can_stay[cnt_can] == b[road]: can_flag_b = 1 if can_flag_a == 1 and can_flag_b == 0: can_stay.append(b[road]) elif can_flag_a == 0 and can_flag_b == 1: can_stay.append(a[road]) elif can_flag_a == 0 and can_flag_b == 0: branch_stay.append([a[road], b[road]]) if len(branch_stay) >= 2: for cnt_road in range(len(branch_stay) - 1): del_flag = 0 for cnt_len in range(len(branch_stay[cnt_road])): for cnt_sub_len in range(len(branch_stay[cnt_road + 1])): if ( branch_stay[cnt_road][cnt_len] == branch_stay[cnt_road + 1][cnt_sub_len] ): del branch_stay[cnt_road][cnt_len] for length in range(branch_stay[cnt_road]): branch_stay[cnt_road + 1].append( branch_stay[cnt_road][length] ) break if del_flag == 1: del branch_stay[cnt_road] break if len(branch_stay) >= 1: for cnt_road in range(len(branch_stay)): del_flag = 0 for cnt_main in range(len(can_stay)): for cnt_sub in range(len(branch_stay[cnt_road])): if can_stay[cnt_main] == branch_stay[cnt_road][cnt_sub]: del branch_stay[cnt_road][cnt_sub] for cnt_add in range(len(branch_stay[cnt_road])): can_stay.append(branch_stay[cnt_road][cnt_add]) del_flag = 1 if del_flag == 1: del branch_stay[cnt_road] break if len(branch_stay) > 0: for cnt in range(len(branch_stay)): branch_node += len(branch_stay[cnt]) if len(branch_stay) > 0: need_road = n - len(can_stay) - branch_node + len(branch_stay) else: need_road = n - len(can_stay) print(need_road)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s674552024
Runtime Error
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
def visit(graph, node, used): used[node] = True for next in graph[node]: if not used[next]: visit(graph, next, used) nodes, edges = map(int, input().split()) graph = [[] for _ in range(nodes)] for _ in range(edges): a, b = map(int, input().split()) graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) comps = 0 used = [False for _ in range(nodes)] for i in range(nodes): if not used[i]: comps += 1 visit(graph, i, used) print(comps - 1)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s786450722
Accepted
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
def f(x): while p[x]>0: x = p[x] return x N,M = map(int,input().split()) p = [-1]*N for _ in range(M): A,B = map(lambda x:f(int(x)-1),input().split()) if A==B: continue elif A<B: A,B=B,A p[A] += p[B] p[B] = A print(sum(i<0 for i in p)-1)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s676464671
Wrong Answer
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
def solve(city_arr, road_arr): road_set = set(road_arr) tmp_cities = list(road_set) tmp_cities.sort() counta = len(city_arr) - len(road_set) for city, road in zip(city_arr, tmp_cities): if city != road: counta += 1 return counta if __name__ == "__main__": num_cities, num_roads = [int(i) for i in input().split()] roads = [int(i) for j in range(num_roads) for i in input().split()] cities = range(1, num_cities + 1) ans = solve(cities, roads) print(ans)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s017619760
Runtime Error
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
n, m = list(map(int, input().split())) res = [[x] for x in range(1, n + 1)] for _ in range(m): i, j = list(map(int, input().split())) y, z = None, None for x in res: if i in x or j in x: if y == None: y = x if j in x: break else: z = x res.remove(y) res.remove(z) res.append(y + z) print(len(res) - 1)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s573739976
Runtime Error
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
(N, M), *AB = [list(map(int, x.split())) for x in open(0).readlines()] d = {} g = 0 for a, b in AB: if a in d: d[b] = d[a] elif b in d: b[a] = d[b] else: g += 1 d[a] = d[b] = g for i in range(1, N + 1): if not i in d: g += 1 print(g - 1)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s060360904
Wrong Answer
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
(N, M), *AB = [list(map(int, x.split())) for x in open(0).readlines()]
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s660390712
Wrong Answer
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
(N, M), *AB = [list(map(int, x.split())) for x in open(0).readlines() if len(x) > 1] d = {} g = 0 for a, b in AB: pass
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s473703003
Accepted
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
from sys import setrecursionlimit, stdin def find(parent, i): t = parent[i] if t < 0: return i t = find(parent, t) parent[i] = t return t def unite(parent, i, j): i = find(parent, i) j = find(parent, j) if i == j: return parent[j] += parent[i] parent[i] = j readline = stdin.readline setrecursionlimit(10**6) N, M = map(int, readline().split()) parent = [-1] * N for _ in range(M): A, B = map(lambda x: int(x) - 1, readline().split()) unite(parent, A, B) print(sum(1 for i in range(N) if parent[i] < 0) - 1)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s144562093
Runtime Error
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
N, K = map(int, input().split()) A = [] for i in range(N): a = int(input()) A.append(a) def segfunc(x, y): return max(x, y) ide_ele = 0 class SegTree: def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num for i in range(n): self.tree[self.num + i] = init_val[i] for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): k += self.num self.tree[k] = x while k > 1: self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1]) k >>= 1 def query(self, l, r): res = self.ide_ele l += self.num r += self.num while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: res = self.segfunc(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res Ma = max(A) Tree = [0] * (Ma + 1) seg = SegTree(Tree, segfunc, ide_ele) ans = 0 for i in range(N): a = A[i] l = max(0, a - K) r = min(a + K, Ma) Ans = seg.query(l, r + 1) seg.update(a, Ans + 1) ans = max(ans, Ans + 1) print(ans)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s983623406
Wrong Answer
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
n, m = map(int, input().split()) ab = [list(map(int, input().split())) for i in range(m)] def tie(n, m, ab): k = [-1 for i in range(n)] l = 0 p, q = [], [] for i in range(m): a, b = ab[i] if k[a - 1] > 0 and k[b - 1] > 0: if k[a - 1] == k[b - 1]: continue else: p += [k[a - 1], k[b - 1]] q += [[k[a - 1], k[b - 1]]] elif k[a - 1] > 0: k[b - 1] = k[a - 1] elif k[b - 1] > 0: k[a - 1] = k[b - 1] else: k[a - 1] = l k[b - 1] = l l += 1 for i in k: if i < 0: l += 1 if len(p) > 0: return l - 1 - tie(len(set(k)), len(q), q) else: return l - 1 print(tie(n, m, ab))
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s851764463
Accepted
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
(n,m),*a=[map(int,t.split())for t in open(0)] p=[-1]*-~n for a in a: a,b=map(r:=lambda x:x*(p[x]<0)or r(p[x]),a) if a!=b: if p[a]>p[b]:a,b=b,a p[a]+=p[b];p[b]=a print(sum(i<0for i in p)-2)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the answer. * * *
s826120001
Accepted
p02536
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
import sys sys.setrecursionlimit(100002) input = lambda: sys.stdin.readline().rstrip() def main(a_s, b_s, n, m): graph = {} for node in range(1, n + 1): graph[node] = [] for i in range(m): a, b = a_s[i], b_s[i] graph[a].append(b) graph[b].append(a) uses = [False] * (n + 1) def check(node): uses[node] = True kids = graph[node] for kid in kids: if not uses[kid]: check(kid) next_graph_i = 1 for node in range(1, n + 1): if uses[node]: continue graph_i = next_graph_i check(node) next_graph_i = graph_i + 1 out = graph_i - 1 print(out) if True: n, m = map(int, input().split(" ")) a_s = [] b_s = [] for i in range(m): a, b = map(int, input().split(" ")) a_s.append(a) b_s.append(b) else: import random n = random.randint(2, 100000) m = random.randint(1, 100000) a_s = [] b_s = [] for i in range(m): a = random.randint(1, n - 1) b = random.randint(a + 1, n) a_s.append(a) b_s.append(b) main(a_s, b_s, n, m)
Statement There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal?
[{"input": "3 1\n 1 2", "output": "1\n \n\nInitially, there are three cities, and there is a road between City 1 and City\n2.\n\nSnuke can achieve the goal by building one new road, for example, between City\n1 and City 3. After that,\n\n * We can travel between 1 and 2 directly.\n * We can travel between 1 and 3 directly.\n * We can travel between 2 and 3 by following both roads (2 \\- 1 \\- 3)."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s575172419
Accepted
p03327
Input is given from Standard Input in the following format: N
print("ABD" if 999 < int(input()) else "ABC")
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s977333266
Accepted
p03327
Input is given from Standard Input in the following format: N
print("ABC" if (int(input()) <= 999) else "ABD")
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s667279400
Accepted
p03327
Input is given from Standard Input in the following format: N
print("ABD" if int(input()) > 999 else "ABC")
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s330997366
Accepted
p03327
Input is given from Standard Input in the following format: N
print("AB" + "CD"[len(input()) > 3])
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s262816817
Accepted
p03327
Input is given from Standard Input in the following format: N
[print("ABC") if int(input()) < 1000 else print("ABD")]
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s224705741
Accepted
p03327
Input is given from Standard Input in the following format: N
print(["ABC", "ABD"][int(input()) // 1000])
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s589622298
Runtime Error
p03327
Input is given from Standard Input in the following format: N
if(int(input()<1000):print("ABC") else:print("ABD")
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s086467833
Wrong Answer
p03327
Input is given from Standard Input in the following format: N
print("ABC" if int(input()) < 999 else "ABD")
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s400163487
Accepted
p03327
Input is given from Standard Input in the following format: N
print("AB", end="") print("C") if int(input()) < 1000 else print("D")
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s920744276
Runtime Error
p03327
Input is given from Standard Input in the following format: N
moji = map(int, input().split()) print(("ABC", "ABD")[moji >= 1000])
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s130374338
Wrong Answer
p03327
Input is given from Standard Input in the following format: N
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from functools import * from itertools import permutations, combinations, groupby import sys import bisect import string import math import time import random def Golf(): (*a,) = map(int, open(0)) def S_(): return input() def IS(): return input().split() def LS(): return [i for i in input().split()] def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i) - 1 for i in input().split()] def NI(n): return [int(input()) for i in range(n)] def NI_(n): return [int(input()) - 1 for i in range(n)] def StoI(): return [ord(i) - 97 for i in input()] def ItoS(nn): return chr(nn + 97) def LtoS(ls): return "".join([chr(i + 97) for i in ls]) def GI(V, E, Directed=False, index=0): org_inp = [] g = [[] for i in range(n)] for i in range(E): inp = LI() org_inp.append(inp) if index == 0: inp[0] -= 1 inp[1] -= 1 if len(inp) == 2: a, b = inp g[a].append(b) if not Directed: g[b].append(a) elif len(inp) == 3: a, b, c = inp aa = (inp[0], inp[2]) bb = (inp[1], inp[2]) g[a].append(bb) if not Directed: g[b].append(aa) return g, org_inp def GGI(h, w, search=None, replacement_of_found=".", mp_def={"#": 1, ".": 0}): # h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage mp = [1] * (w + 2) found = {} for i in range(h): s = input() for char in search: if char in s: found[char] = (i + 1) * (w + 2) + s.index(char) + 1 mp_def[char] = mp_def[replacement_of_found] mp += [1] + [mp_def[j] for j in s] + [1] mp += [1] * (w + 2) return h + 2, w + 2, mp, found def bit_combination(k, n=2): rt = [] for tb in range(n**k): s = [tb // (n**bt) % n for bt in range(k)] rt += [s] return rt def show(*inp, end="\n"): if show_flg: print(*inp, end=end) YN = ["YES", "NO"] mo = 10**9 + 7 inf = float("inf") l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() # sys.setrecursionlimit(10**7) input = lambda: sys.stdin.readline().rstrip() def ran_input(): import random n = random.randint(4, 16) rmin, rmax = 1, 10 a = [random.randint(rmin, rmax) for _ in range(n)] return n, a show_flg = False show_flg = True ans = 0 n = I() if n <= 999: ans = "ABC" + str(n + 1000)[1:] else: ans = "ABD" + str(1000 + n - 999)[1:] print(ans)
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s018063591
Runtime Error
p03327
Input is given from Standard Input in the following format: N
N = int(input()) INF = 10**6 dp = [INF] * (max(9, N)) for i in range(10): if 0 < i < 6: dp[i] = i elif i < 9: dp[i] = i % 6 + 1 for i in range(N): n = m = 1 while i + 9**n <= N: dp[i + 9**n] = min(dp[i + 9**n], dp[i] + 1) n += 1 while i + 6**m <= N: dp[i + 6**m] = min(dp[i + 6**m], dp[i] + 1) m += 1 print(dp[N])
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s631961710
Wrong Answer
p03327
Input is given from Standard Input in the following format: N
n_max = 100000 bs = [(6**i, 6) for i in range(1, 10)] bs.extend([(9**i, 9) for i in range(1, 10)]) bs = list(sorted(filter(lambda x: x[0] <= n_max, bs))) bms = [] s = 5 for b, i in bs: s += b * (i - 1) bms.append((b, i, s)) # print(bs) # print(bms, len(bms)) # m = 44852 m = int(input()) stack = [(m, 0, len(bms) - 1)] # print("search start!") result = 10000 while stack: m, n, bms_i = stack.pop() b, i, s = bms[bms_i] # print(m, n, bms_i, b, i, s) if n > result: # print("skip!", m, n, bms_i) continue if bms_i < 0: if m < 6 and result > m + n: result = m + n # print('get result!', result) continue for j in range(0, i): next_m = m - b * j if next_m > 0 and n + j < result: stack.append((next_m, n + j, bms_i - 1)) print(result)
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s023575046
Runtime Error
p03327
Input is given from Standard Input in the following format: N
package main import "fmt" func main() { var a int fmt.Scan(&a) if a > 1000 { fmt.Println("ABD") } else { fmt.Println("ABC") } }
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s488652807
Wrong Answer
p03327
Input is given from Standard Input in the following format: N
n = int(input()) if n <= 999: if len(str(n)) == 1: print("ABC00" + str(n)) elif len(str(n)) == 2: print("ABC0" + str(n)) else: print("ABC" + str(n)) else: a = str(n % 1000 + 1) if len(a) == 1: print("ABD00" + a) elif len(a) == 2: print("ABD0" + a) else: print("ABD" + a)
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s072172394
Wrong Answer
p03327
Input is given from Standard Input in the following format: N
print(["ABD", "ABC"][int(input()) // 1000])
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s107325543
Wrong Answer
p03327
Input is given from Standard Input in the following format: N
n = int(input()) a = [] for i in [6, 9]: j = 1 while i**j < 100000: a.append(i**j) j += 1 a.sort() dp = [i for i in range(n + 1)] dp[0] = 0 for c in a: for i in range(c + 1, n + 1): dp[i] = min(dp[i - c] + 1, dp[i]) print(dp[n])
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s684294188
Accepted
p03327
Input is given from Standard Input in the following format: N
print("ABC" if 1 <= int(input()) <= 999 else "ABD")
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s957281310
Wrong Answer
p03327
Input is given from Standard Input in the following format: N
n = int(input()) list = [] while n > 9**5: n = n - 9**5 list.append(1) while n > 6**6: n = n - 6**6 list.append(1) while n > 6**5: n = n - 6**5 list.append(1) for i in [4, 3, 2, 1]: for r in [ 9, 6, ]: while n > r**i: n = n - r**i list.append(r**i) length = len(list) + n print(length)
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s470346201
Accepted
p03327
Input is given from Standard Input in the following format: N
print(("ABC", "ABD")[int(input()) >= 1000])
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s885815027
Accepted
p03327
Input is given from Standard Input in the following format: N
print("ABC" if len(input().strip()) <= 3 else "ABD")
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s652467477
Accepted
p03327
Input is given from Standard Input in the following format: N
print(["ABD", "ABC"][int(input()) < 1000])
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s412975103
Accepted
p03327
Input is given from Standard Input in the following format: N
print("ABD" if (len(input()) > 3) else "ABC")
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s731061471
Accepted
p03327
Input is given from Standard Input in the following format: N
print("AB%s" % chr(67 + (len(input()) > 3)))
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s650455453
Accepted
p03327
Input is given from Standard Input in the following format: N
print("AB" + "CD"[int(input()) > 999])
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s712501770
Accepted
p03327
Input is given from Standard Input in the following format: N
print(["ABC", "ABD"][len(input()) == 4])
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s444865518
Accepted
p03327
Input is given from Standard Input in the following format: N
print("AB" + ["C", "D"][int(input()) > 999])
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. * * *
s185847940
Wrong Answer
p03327
Input is given from Standard Input in the following format: N
print("AB" + "C" if int(input()) < 1000 else "D")
Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
[{"input": "999", "output": "ABC\n \n\nThe 999-th round of AtCoder Beginner Contest is labeled as `ABC999`.\n\n* * *"}, {"input": "1000", "output": "ABD\n \n\nThe 1000-th round of AtCoder Beginner Contest is labeled as `ABD001`.\n\n* * *"}, {"input": "1481", "output": "ABD\n \n\nThe 1481-th round of AtCoder Beginner Contest is labeled as `ABD482`."}]