output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s623579724
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
def main(): n = int(input()) data = list(map(int, input().split())) if n == 1: print(data[0]) elif n == 2: print(data[1], data[0]) else: firs_value = [data[0]] second_value = [data[1], data[0]] def get_value(index, data): if index == 0: return firs_value elif index == 1: return second_value else: lis = get_value(index - 2, data) lis.append(data[index - 1]) lis.insert(0, data[index]) return lis result = get_value(n - 1, data) print(" ".join(str(n) for n in result)) if __name__ == '__main__': main()
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s224682369
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
def main(): n = int(input()) data = list(map(int, input().split())) if n == 1: print(data[0]) elif n == 2: print(data[1], data[0]) else: firs_value = [data[0]] second_value = [data[1], data[0]] def get_value(index, data): if index == 0: return firs_value elif index == 1: return second_value else: lis = get_value(index - 2, data) lis.append(data[index - 1]) lis.insert(0, data[index]) return lis result = get_value(n - 1, data) print(" ".join(str(n) for n in result)) if __name__ == '__main__': main()
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s179450858
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
N=int(input()) A=list(map(int,input().split())) print(*A[::-2]+*A[N%2::2])
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s988348567
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
input() input = list(input()) print(*input[::-2], *input[::2]
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s558883995
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
from collectiojns import deque n=int(input()) a=list(map(int,input().split())) b=deque() for i in range(n): b.append(a[i]) b=[::-1] print(*b)
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s474838086
Accepted
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) a = list(map(int, input().split())) o = [] # とりあえず後ろから1つ飛ばしで並べる。 for i in range(n)[::-2]: o.append(a[i]) # 前からも1つ飛ばしで並べる。 # 被らないように、要素数が奇数の時は、0番目ではなく1番目から並べる for i in range(n)[n % 2 :: 2]: o.append(a[i]) print(*o)
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s445865782
Accepted
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
a = int(input()) ar = input().split(" ") br = [0 for i in range(a)] n = a // 2 p = 0 if a % 2 == 0: t = "L" else: t = "R" for i, r in enumerate(ar): if i == 0: br[n] = r p += 1 else: if t == "L": br[n - p] = r t = "R" if a % 2 != 0: p += 1 else: br[n + p] = r t = "L" if a % 2 == 0: p += 1 print(" ".join(br))
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s174330927
Accepted
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) S = list(map(int, input().split())) S = S[::-1] x = S[::2] y = S[1::2] b = x + y[::-1] print(*b, sep=" ")
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s160412421
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math #from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9+7 INF = float('inf') ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int,input().split())) def SL(): return list(map(str,input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg); return def Y(): print("Yes"); return def N(): print("No"); return def E(): exit() def PE(arg): print(arg); exit() def YE(): print("Yes"); exit() def NE(): print("No"); exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD-2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if(len(kaijo_memo) > n): return kaijo_memo[n] if(len(kaijo_memo) == 0): kaijo_memo.append(1) while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n] if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1) while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD) return gyaku_kaijo_memo[n] def nCr(n,r): if(n == r): return 1 if(n < r or r < 0): return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n-r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) return divisors #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd (a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n -1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X//n: return base_10_to_n(X//n, n)+[X%n] return [X%n] def base_n_to_10(X, n): return sum(int(str(X)[-i])*n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n>=a: n = n//a count += 1 if a**count == n: return count else: return count+1 ############# # Main Code # ############# N = I() A = IL() iti = A[::2] ni = A[1::2] if N % 2: print(*((ni[::-1]+iti)[::-1]),sep=" ") else: print(*(ni[::-1]+iti),sep=" ")
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s734972823
Accepted
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n, *l = map(int, open(0).read().split()) k = l[-1 - n % 2 :: -2] + l[::2] print(*k[:: (-1) ** n], end=" ")
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s564496608
Wrong Answer
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
import sys n = int(input().strip()) al = list(map(int, input().strip().split(" "))) bl = [0] * n diff = 1 if n % 2 == 0 else -1 mid = int(n / 2) bl[mid] = al[0] deps = 1 a_index = 1 while 0 <= mid - deps * diff and mid + deps * diff < n and a_index < n: bl[mid - deps * diff] = al[a_index] a_index += 1 bl[mid + deps * diff] = al[a_index] a_index += 1 deps += 1 for b in bl: sys.stdout.write(str(b) + " ")
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s156388579
Wrong Answer
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) alist = list(map(int, input().split())) b = alist[0::2][::-1] + alist[1::2] for _ in b[::-1]: print(_, end=" ")
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s147968611
Wrong Answer
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
import sys sys.setrecursionlimit(10**6) from math import floor, ceil, sqrt, factorial, log from heapq import heappop, heappush, heappushpop from collections import Counter, defaultdict, deque from itertools import ( accumulate, permutations, combinations, product, combinations_with_replacement, ) from bisect import bisect_left, bisect_right from copy import deepcopy from operator import itemgetter from fractions import gcd mod = 10**9 + 7 inf = float("inf") ninf = -float("inf") # 整数input def ii(): return int(sys.stdin.readline().rstrip()) # int(input()) def mii(): return map(int, sys.stdin.readline().rstrip().split()) def limii(): return list(mii()) # list(map(int,input().split())) def lin(n: int): return [ii() for _ in range(n)] def llint(n: int): return [limii() for _ in range(n)] # 文字列input def ss(): return sys.stdin.readline().rstrip() # input() def mss(): return sys.stdin.readline().rstrip().split() def limss(): return list(mss()) # list(input().split()) def lst(n: int): return [ss() for _ in range(n)] def llstr(n: int): return [limss() for _ in range(n)] # 本当に貪欲法か? DP法では?? # 本当に貪欲法か? DP法では?? # 本当に貪欲法か? DP法では?? n = ii() arr = deque(limii()) b = deque([]) for i in range(n): if i % 2 == 1: x = arr.popleft() b.appendleft(str(x)) else: x = arr.popleft() b.append(str(x)) print(" ".join(list(b)))
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s491584928
Wrong Answer
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list(map(lambda x: int(x) - 1, stdin.readline().split())) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") # A def A(): a, b, c = LI() print(min(a + b, b + c, c + a)) return # B def B(): def check(s): x = len(s) if x % 2: return False if s[: x // 2] == s[x // 2 :]: return True s = S() for i in range(1, len(s)): if check(s[:-i]): print(len(s) - i) return # C def C(): II() a = LI() ans1 = a[-1::-2] ans2 = a[-2::-2] ans = ans1 + ans2 print(*ans) return # D def D(): return # Solve if __name__ == "__main__": C()
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s128624833
Accepted
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
N, *A = map(int, open(0).read().split()) print(*A[N - 1 :: -2] + A[N & 1 :: 2])
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s781675049
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) num = list(map(int, input().split())) new_list = [] for i in num: new_list.append(i) new_list.reverse() print(new_list)
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s722122596
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
input = list(input()) print(*input[::-2], *input[::2]
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s793249666
Wrong Answer
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
_ = input() a = input().split() a1 = list(reversed(a[1::2])) a2 = a[::2] print(" ".join(a1 + a2))
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s472765536
Wrong Answer
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
input() (*A,) = input().split() print(" ".join(A[::-2] + A[::2]))
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s212001267
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
from collections import deque N=int(input()) A=list(map(int,input().split())) l=deque() for i in range(N): if i%2==0: l.append(A[i]) else: l.appendleft(A[i]) print(*l if N%2==0 else *list(revrsed(l)))
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s123440866
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) a = input().split() b = [] for i in range(n): if n%2 == 0: if i%2== 1: b.insert(0,a[i]) else: b.append(a[i]) else: if i%2== 0: b.insert(0,a[i]) else: b.append(a[i]) result= map(b) print(result)
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s241852415
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
import sys stdin = sys.stdin sys.setrecursionlimit(10**7) i_i = lambda: int(i_s()) i_l = lambda: list(map(int, stdin.readline().split())) i_s = lambda: stdin.readline().rstrip() n = i_i() a = i_l() print(*a[::-2], *a[n % 2 :: 2])
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s419170113
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) a = list(map(int,input().split())) ans = '' for i in range(n): if i % 2 == 0: ans = ans + str(a[i]) + else: ans = str(a[i]) + ans print(ans)
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s791564121
Wrong Answer
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
if __name__ == "__main__": s = input() data = list(s) while len(data): data.pop() if len(data) % 2 == 0: half = int(len(data) / 2) if data[:half] == data[half:]: print("".join(data[:half])) break
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s682819580
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<cmath> #include<cstdio> #include<map> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,s,n) for(int i=(s);i<(n);i++) #define repr(i,n) for(int i=n-1;i>=0;i--) #define REPR(i,s,n) for(int i=(s);i>=(n);i--) #define pb push_back #define pf push_front typedef vector<int> vi; typedef vector<string> vs; typedef long long ll; typedef vector<ll> vll; ll gcd(ll x, ll y) { ll r; while ((r = x % y) != 0) { x = y; y = r; } return y; } ll lcm(ll x, ll y) { x /= gcd(x, y); y /= gcd(x, y); return (x*y); } int main() { int n; cin >> n; int a[n]; rep(i,n) cin >> a[i]; if(n%2==0){ for(int i=(n-1);i>0;i-=2) cout << a[i] << " "; for(int i=0;i<n;i+=2) cout << a[i] << " "; } else{ for(int i=(n-1);i>=0;i-=2) cout << a[i] << " "; for(int i=1;i<n;i+=2) cout << a[i] << " "; } cout << endl; return 0; }
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s402411277
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.*; public class Main { long MOD = (long) 1e9 + 7; InputStream in; OutputStream out; public Main() { this(System.in, System.out); } public Main(InputStream in, OutputStream out) { this.in = in; this.out = out; } void run() { Scanner sc = new Scanner(this.in); PrintWriter out = new PrintWriter(this.out); // write your code int n = sc.nextInt(); LinkedList<Integer> b = new LinkedList<>(); for (int i = 0; i < n; i++) { int a = sc.nextInt(); if (i % 2 == 0) { b.addLast(a); } else { b.addFirst(a); } } boolean f = true; for (int i = 0; i < n; i++) { int x = n % 2 == 0 ? b.removeFirst() : b.removeLast(); if (f) { f = false; out.print(x); } else { out.print(" " + x); } } out.println(); out.flush(); } void debug(Object... os) { System.err.println(Arrays.deepToString(os)); } public static void main(String[] args) { new Main().run(); } }
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s263183471
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) a = list(map(int, input().split(" ")) b=[] for item in a: b.append(item) b.reverse for item in b: print(item, end=" ")
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
Print n integers in a line with spaces in between. The i-th integer should be b_i. * * *
s417802379
Runtime Error
p03673
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
N=int(input()) A=list(map(int,input().split()) print(*A[::-2],*A[N%2::2])
Statement You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
[{"input": "4\n 1 2 3 4", "output": "4 2 1 3\n \n\n * After step 1 of the first operation, b becomes: 1.\n * After step 2 of the first operation, b becomes: 1.\n * After step 1 of the second operation, b becomes: 1, 2.\n * After step 2 of the second operation, b becomes: 2, 1.\n * After step 1 of the third operation, b becomes: 2, 1, 3.\n * After step 2 of the third operation, b becomes: 3, 1, 2.\n * After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.\n * After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.\n\nThus, the answer is `4 2 1 3`.\n\n* * *"}, {"input": "3\n 1 2 3", "output": "3 1 2\n \n\nAs shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third\noperation. Thus, the answer is `3 1 2`.\n\n* * *"}, {"input": "1\n 1000000000", "output": "1000000000\n \n\n* * *"}, {"input": "6\n 0 6 7 6 7 0", "output": "0 6 6 0 7 7"}]
For each randomAccess, print $a_p$ in a line.
s851893583
Wrong Answer
p02432
The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $d$ $x$ or 1 $p$ or 2 $d$ where the first digits 0, 1 and 2 represent push, randomAccess and pop operations respectively. randomAccess and pop operations will not be given for an empty array.
q = int(input()) a = [] end = 0 for i in range(q): ops = list(map(int, input().split())) if ops[0] == 0: end += 1 if ops[1] == 0: a.insert(0, ops[2]) else: a.insert(end, ops[2]) elif ops[0] == 1: print(a[ops[1]]) elif ops[0] == 2: end -= 1 if ops[1] == 0: a.pop(0)
Deque For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$. * randomAccess($p$): Print element $a_p$. * pop($d$): Delete the first element of $A$, if $d = 0$. Delete the last element of $A$, if $d = 1$. $A$ is a 0-origin array and it is empty in the initial state.
[{"input": "11\n 0 0 1\n 0 0 2\n 0 1 3\n 1 0\n 1 1\n 1 2\n 2 0\n 2 1\n 0 0 4\n 1 0\n 1 1", "output": "2\n 1\n 3\n 4\n 1"}]
For each randomAccess, print $a_p$ in a line.
s936463929
Accepted
p02432
The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $d$ $x$ or 1 $p$ or 2 $d$ where the first digits 0, 1 and 2 represent push, randomAccess and pop operations respectively. randomAccess and pop operations will not be given for an empty array.
from collections import deque def push(d, x): if d == 0: ary.appendleft(x) elif d == 1: ary.append(x) def random_access(p): print(ary[p]) def pop(d): if d == 0: ary.popleft() elif d == 1: ary.pop() q = int(input()) ary = deque() for _ in range(q): op = list(map(int, input().split())) if op[0] == 0: push(op[1], op[2]) elif op[0] == 1: random_access(op[1]) elif op[0] == 2: pop(op[1])
Deque For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$. * randomAccess($p$): Print element $a_p$. * pop($d$): Delete the first element of $A$, if $d = 0$. Delete the last element of $A$, if $d = 1$. $A$ is a 0-origin array and it is empty in the initial state.
[{"input": "11\n 0 0 1\n 0 0 2\n 0 1 3\n 1 0\n 1 1\n 1 2\n 2 0\n 2 1\n 0 0 4\n 1 0\n 1 1", "output": "2\n 1\n 3\n 4\n 1"}]
For each randomAccess, print $a_p$ in a line.
s731508314
Accepted
p02432
The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $d$ $x$ or 1 $p$ or 2 $d$ where the first digits 0, 1 and 2 represent push, randomAccess and pop operations respectively. randomAccess and pop operations will not be given for an empty array.
q = int(input()) a_list = [0] * (q * 2) head = tail = q for _ in range(q): com, *query = map(int, input().split()) if com == 0: if query[0] == 0: a_list[head] = query[1] if head == tail: tail += 1 head -= 1 else: a_list[tail] = query[1] if head == tail: head -= 1 tail += 1 elif com == 1: print(a_list[query[0] + head + 1]) else: if query[0] == 0: head += 1 else: tail -= 1
Deque For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$. * randomAccess($p$): Print element $a_p$. * pop($d$): Delete the first element of $A$, if $d = 0$. Delete the last element of $A$, if $d = 1$. $A$ is a 0-origin array and it is empty in the initial state.
[{"input": "11\n 0 0 1\n 0 0 2\n 0 1 3\n 1 0\n 1 1\n 1 2\n 2 0\n 2 1\n 0 0 4\n 1 0\n 1 1", "output": "2\n 1\n 3\n 4\n 1"}]
For each randomAccess, print $a_p$ in a line.
s496213734
Accepted
p02432
The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $d$ $x$ or 1 $p$ or 2 $d$ where the first digits 0, 1 and 2 represent push, randomAccess and pop operations respectively. randomAccess and pop operations will not be given for an empty array.
from collections import deque a = int(input()) res = deque() for i in range(a): temp = list(map(int, input().split())) if temp[0] == 0: if temp[1] == 0: res.appendleft(temp[2]) elif temp[1] == 1: res.append(temp[2]) elif temp[0] == 1: print(res[temp[1]]) else: if temp[1] == 0: res.popleft() elif temp[1] == 1: res.pop()
Deque For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$. * randomAccess($p$): Print element $a_p$. * pop($d$): Delete the first element of $A$, if $d = 0$. Delete the last element of $A$, if $d = 1$. $A$ is a 0-origin array and it is empty in the initial state.
[{"input": "11\n 0 0 1\n 0 0 2\n 0 1 3\n 1 0\n 1 1\n 1 2\n 2 0\n 2 1\n 0 0 4\n 1 0\n 1 1", "output": "2\n 1\n 3\n 4\n 1"}]
For each randomAccess, print $a_p$ in a line.
s471027615
Accepted
p02432
The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $d$ $x$ or 1 $p$ or 2 $d$ where the first digits 0, 1 and 2 represent push, randomAccess and pop operations respectively. randomAccess and pop operations will not be given for an empty array.
from collections import deque class MyDeque: def __init__(self): self.data = deque() def push(self, d, x): if d == 0: self.data.appendleft(x) elif d == 1: self.data.append(x) def random_access(self, p): print(self.data[p]) def pop(self, d): if d == 0: self.data.popleft() elif d == 1: self.data.pop() my_deque = MyDeque() q = int(input()) for _ in range(q): args = input().split(" ") if args[0] == "0": d = int(args[1]) x = int(args[2]) my_deque.push(d, x) elif args[0] == "1": p = int(args[1]) my_deque.random_access(p) elif args[0] == "2": d = int(args[1]) my_deque.pop(d)
Deque For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$. * randomAccess($p$): Print element $a_p$. * pop($d$): Delete the first element of $A$, if $d = 0$. Delete the last element of $A$, if $d = 1$. $A$ is a 0-origin array and it is empty in the initial state.
[{"input": "11\n 0 0 1\n 0 0 2\n 0 1 3\n 1 0\n 1 1\n 1 2\n 2 0\n 2 1\n 0 0 4\n 1 0\n 1 1", "output": "2\n 1\n 3\n 4\n 1"}]
For each randomAccess, print $a_p$ in a line.
s842742709
Accepted
p02432
The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $d$ $x$ or 1 $p$ or 2 $d$ where the first digits 0, 1 and 2 represent push, randomAccess and pop operations respectively. randomAccess and pop operations will not be given for an empty array.
# coding: utf-8 # Your code here! from collections import deque n = int(input()) Deq = deque() for i in range(n): command = input().split() com = int(command[0]) com1 = int(command[1]) if com == 0: if com1 == 1: Deq.append(command[2]) elif com1 == 0: Deq.appendleft(command[2]) elif com == 1: q = Deq[com1] print(q) elif com == 2: if com1 == 1: Deq.pop() elif com1 == 0: Deq.popleft()
Deque For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$. * randomAccess($p$): Print element $a_p$. * pop($d$): Delete the first element of $A$, if $d = 0$. Delete the last element of $A$, if $d = 1$. $A$ is a 0-origin array and it is empty in the initial state.
[{"input": "11\n 0 0 1\n 0 0 2\n 0 1 3\n 1 0\n 1 1\n 1 2\n 2 0\n 2 1\n 0 0 4\n 1 0\n 1 1", "output": "2\n 1\n 3\n 4\n 1"}]
Print an integer representing the answer. * * *
s475353158
Accepted
p02598
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_N
# 2020年6月17日 # 修行という概念がない場合、消化コストを大から小に並べて食べにくさを小から大に並べて順にマッチングさせれば良い。 # そうでない状態から2つを交換したときに最大値が下がる方向にしか行かないため。 # 修行をするなら最大値を引き下げるところに修行をするのが最適なので、 # 無修行状態の結果を優先度付きキューに入れる→K回最大値を取り出してコストを引いて再投入→を繰り返す。 # 本当か? やってるうちに最適な組み合わせが変わらないか? →変わらない。食べにくさを昇順に並べたときに消化コストが降順になるのが最善手なので。 # あとKが大きいのでこれだと間に合わない。 # 決め打ち二分探索か? # あ、それだわ。 # Python TLE 2秒以上 # PyPy 287ms n, k = list(map(int, input().split())) lengths = list(map(int, input().split())) def is_valid(unit): # k回以下の切断で実現可能か n_cut = sum(map(lambda p: (p + unit - 1) // unit - 1, lengths)) # print(unit, n_cut) return n_cut <= k unit_ok = 10**9 + 1 unit_ng = 0 # めぐる式二分探索 while abs(unit_ok - unit_ng) > 1: mid = (unit_ok + unit_ng) // 2 if is_valid(mid): unit_ok = mid else: unit_ng = mid print(unit_ok)
Statement We have N logs of lengths A_1,A_2,\cdots A_N. We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t. Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.
[{"input": "2 3\n 7 9", "output": "4\n \n\n * First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.\n * Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.\n * Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.\n\nIn this case, the longest length of a log will be 3.5, which is the shortest\npossible result. After rounding up to an integer, the output should be 4.\n\n* * *"}, {"input": "3 0\n 3 4 5", "output": "5\n \n\n* * *"}, {"input": "10 10\n 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202", "output": "292638192"}]
Print an integer representing the answer. * * *
s890704654
Accepted
p02598
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_N
N,K=map(int,input().split()) A=list(map(int,input().split())) L=0;R=10**9 while(R-L>1): M=L+R>>1;C=0 for i in A:C+=(i-1)//M if C<=K:R=M else:L=M print(R)
Statement We have N logs of lengths A_1,A_2,\cdots A_N. We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t. Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.
[{"input": "2 3\n 7 9", "output": "4\n \n\n * First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.\n * Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.\n * Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.\n\nIn this case, the longest length of a log will be 3.5, which is the shortest\npossible result. After rounding up to an integer, the output should be 4.\n\n* * *"}, {"input": "3 0\n 3 4 5", "output": "5\n \n\n* * *"}, {"input": "10 10\n 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202", "output": "292638192"}]
Print an integer representing the answer. * * *
s745383869
Wrong Answer
p02598
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_N
A, B = input().split() if int(A) <= 8 and int(B) <= 8: print("Yay!") else: print(":(")
Statement We have N logs of lengths A_1,A_2,\cdots A_N. We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t. Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.
[{"input": "2 3\n 7 9", "output": "4\n \n\n * First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.\n * Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.\n * Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.\n\nIn this case, the longest length of a log will be 3.5, which is the shortest\npossible result. After rounding up to an integer, the output should be 4.\n\n* * *"}, {"input": "3 0\n 3 4 5", "output": "5\n \n\n* * *"}, {"input": "10 10\n 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202", "output": "292638192"}]
Print an integer representing the answer. * * *
s630664519
Runtime Error
p02598
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_N
h, w, m = map(int, input().split()) bomb = [] x = [0] * (h + 1) y = [0] * (w + 1) for i in range(m): h1, w1 = map(int, input().split()) x[h1] += 1 y[w1] += 1 bomb.append((h1, w1)) maxx = max(x) maxy = max(y) r = [] c = [] for i in range(1, h + 1): if x[i] == maxx: r.append(i) for j in range(1, w + 1): if y[i] == maxy: c.append(i) for j in r: for k in c: if (j, k) not in bomb: print(maxx + maxy) exit() print(maxx + maxy - 1)
Statement We have N logs of lengths A_1,A_2,\cdots A_N. We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t. Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.
[{"input": "2 3\n 7 9", "output": "4\n \n\n * First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.\n * Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.\n * Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.\n\nIn this case, the longest length of a log will be 3.5, which is the shortest\npossible result. After rounding up to an integer, the output should be 4.\n\n* * *"}, {"input": "3 0\n 3 4 5", "output": "5\n \n\n* * *"}, {"input": "10 10\n 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202", "output": "292638192"}]
Print an integer representing the answer. * * *
s861532248
Wrong Answer
p02598
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_N
import sys import math def Ii(): return int(sys.stdin.readline()) def Mi(): return map(int, sys.stdin.readline().split()) def Li(): return list(map(int, sys.stdin.readline().split())) n, k = Mi() a = Li() sa = sum(a) list.sort(a, reverse=True) ma = sa // (n + k) + 1 div = [0] * n for i in range(n): div[i] = math.ceil(a[i] / ma) - 1 sd = sum(div) if sd > k: j = 0 for i in range(sd - k): if div[j] > 0: div[j] -= 1 j += 1 else: div[0] -= 1 j = 0 list.sort(div, reverse=True) for i in range(n): a[i] = math.ceil(a[i] / (div[i] + 1)) print(max(a))
Statement We have N logs of lengths A_1,A_2,\cdots A_N. We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t. Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.
[{"input": "2 3\n 7 9", "output": "4\n \n\n * First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.\n * Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.\n * Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.\n\nIn this case, the longest length of a log will be 3.5, which is the shortest\npossible result. After rounding up to an integer, the output should be 4.\n\n* * *"}, {"input": "3 0\n 3 4 5", "output": "5\n \n\n* * *"}, {"input": "10 10\n 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202", "output": "292638192"}]
Print an integer representing the answer. * * *
s674119191
Wrong Answer
p02598
Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_N
from heapq import heappop, heappush, heapify n, x = map(int, input().split()) a = [-1 * int(i) for i in input().split()] ans = [] heapify(ans) for i in a: heappush(ans, i) while x > 0: t = -1 * heappop(ans) t1, t2 = t // 2, t // 2 + t % 2 heappush(ans, -t1) heappush(ans, -t2) x -= 1 print(-1 * heappop(ans))
Statement We have N logs of lengths A_1,A_2,\cdots A_N. We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t. Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.
[{"input": "2 3\n 7 9", "output": "4\n \n\n * First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.\n * Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.\n * Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.\n\nIn this case, the longest length of a log will be 3.5, which is the shortest\npossible result. After rounding up to an integer, the output should be 4.\n\n* * *"}, {"input": "3 0\n 3 4 5", "output": "5\n \n\n* * *"}, {"input": "10 10\n 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202", "output": "292638192"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s799345541
Accepted
p02577
Input is given from Standard Input in the following format: N
print("Yes" if sum([int(c) for c in input()]) % 9 == 0 else "No")
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s340592892
Accepted
p02577
Input is given from Standard Input in the following format: N
print("No" if sum(map(int, list(input()))) % 9 else "Yes")
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s244680264
Wrong Answer
p02577
Input is given from Standard Input in the following format: N
print("YNeos"[sum(map(int, input())) % 9 :: 2])
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s178712406
Accepted
p02577
Input is given from Standard Input in the following format: N
n_str = str(input()) x = 0 for e in n_str: x += int(e) print("Yes") if x % 9 == 0 else print("No")
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s219775172
Accepted
p02577
Input is given from Standard Input in the following format: N
print(["No", "Yes"][sum(list(map(int, list(input())))) % 9 == 0])
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s038186199
Accepted
p02577
Input is given from Standard Input in the following format: N
print("No" if sum(list(map(int, list(input())))) % 9 else "Yes")
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s568287912
Accepted
p02577
Input is given from Standard Input in the following format: N
print("Yes" if sum(list(map(int, list(input())))) % 9 == 0 else "No")
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s574690842
Accepted
p02577
Input is given from Standard Input in the following format: N
import sys sys.setrecursionlimit(10**9) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(input()) def MI(): return map(int, input().split()) def MI1(): return map(int1, input().split()) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def MS(): return input().split() def LS(): return list(input()) def LLS(rows_number): return [LS() for _ in range(rows_number)] def printlist(lst, k=" "): print(k.join(list(map(str, lst)))) INF = float("inf") # from math import ceil, floor, log2 # from collections import deque, defaultdict # from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations # from heapq import heapify, heappop, heappush # import numpy as np # cumsum # from bisect import bisect_left, bisect_right def solve(): N = input() S = list(str(N)) sm = 0 for s in S: n = int(s) sm += n if sm % 9 == 0: print("Yes") else: print("No") if __name__ == "__main__": solve()
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s551215507
Accepted
p02577
Input is given from Standard Input in the following format: N
print(["No", "Yes"][sum(map(int, list(input()))) % 9 == 0])
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s076098819
Accepted
p02577
Input is given from Standard Input in the following format: N
def ok(s): if len(s) == 1: if s == "0" or s == "9": return "Yes" else: return "No" return ok(str(sum(map(int, s)))) print(ok(input()))
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s668306251
Accepted
p02577
Input is given from Standard Input in the following format: N
print("Yes" if sum(map(int, input())) % 9 == 0 else "No")
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s402870682
Accepted
p02577
Input is given from Standard Input in the following format: N
print(("Yes", "No")[sum(map(int, input())) % 9 > 0])
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s857767067
Accepted
p02577
Input is given from Standard Input in the following format: N
print("Yes" if sum(int(x) for x in input()) % 9 == 0 else "No")
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s141319700
Accepted
p02577
Input is given from Standard Input in the following format: N
import sys from io import StringIO import unittest import os # 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む) sys.setrecursionlimit(999999999) # 実装を行う関数 def resolve(test_def_name=""): n_s = list(input()) ans = 0 for n in n_s: ans += int(n) if ans % 9 == 0: print("Yes") else: print("No") # テストクラス class TestClass(unittest.TestCase): def assertIO(self, assert_input, output): stdout, sat_in = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(assert_input) resolve(sys._getframe().f_back.f_code.co_name) sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, sat_in self.assertEqual(out, output) def test_input_1(self): test_input = """123456789""" output = """Yes""" self.assertIO(test_input, output) def test_input_2(self): test_input = """0""" output = """Yes""" self.assertIO(test_input, output) def test_input_3(self): test_input = """31415926535897932384626433832795028841971693993751058209749445923078164062862089986280""" output = """No""" self.assertIO(test_input, output) # 自作テストパターン def test_original(self): pass # 実装orテストの呼び出し if __name__ == "__main__": if os.environ.get("USERNAME") is None: # AtCoder提出時の場合 resolve() else: # 自PCの場合 unittest.main()
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s277225225
Wrong Answer
p02577
Input is given from Standard Input in the following format: N
print("YNeos"[int(input()) % 9 == 0 :: 2])
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s606808029
Accepted
p02577
Input is given from Standard Input in the following format: N
a=int(input()) print("Yes"if a%9==0else"No")
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s222843457
Wrong Answer
p02577
Input is given from Standard Input in the following format: N
print("YNeos"[int(input()) % 9 :: 2])
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s228425459
Accepted
p02577
Input is given from Standard Input in the following format: N
print("YNeos"[int(input()) % 9 > 0 :: 2])
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s154856593
Runtime Error
p02577
Input is given from Standard Input in the following format: N
N = int(input()) Ls = list(map(int, input().split())) score = 0 for i in range(0, N - 2): a = Ls[i] for j in range(i + 1, N - 1): b = Ls[j] for k in range(j + 1, N): c = Ls[k] if (a + b > c) & (a + c > b) & (b + c > a) & (a != b) & (a != c) & (b != c): score += 1 L_list = [i, j, k] print(L_list) print(score)
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s246738604
Wrong Answer
p02577
Input is given from Standard Input in the following format: N
print("Yws" if int(input()) % 9 == 0 else "No")
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
If N is a multiple of 9, print `Yes`; otherwise, print `No`. * * *
s032966498
Wrong Answer
p02577
Input is given from Standard Input in the following format: N
print("YES" if int(input()) % 9 == 0 else "NO")
Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9.
[{"input": "123456789", "output": "Yes\n \n\nThe sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so\n123456789 is a multiple of 9.\n\n* * *"}, {"input": "0", "output": "Yes\n \n\n* * *"}, {"input": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280", "output": "No"}]
Print the number of seconds the bus will take from departure to arrival at the last employees' apartment. * * *
s680219469
Wrong Answer
p03366
Input is given from Standard Input in the following format: N S X_1 P_1 X_2 P_2 : X_N P_N
# -*- coding: utf-8 -*- from bisect import bisect from operator import add def inpl(): return map(int, input().split()) class Seg: def __init__(self, na, default, func): if isinstance(na, list): n = len(na) else: n = na i = 1 while 2**i <= n: i += 1 self.D = default self.H = i self.N = 2**i if isinstance(na, list): self.A = [default] * (self.N) + na + [default] * (self.N - n) for i in range(self.N - 1, 0, -1): self.A[i] = func(self.A[i * 2], self.A[i * 2 + 1]) else: self.A = [default] * (self.N * 2) self.F = func def find(self, i): return self.A[i + self.N] def update(self, i, x): i += self.N self.A[i] = x while i > 1: i = i // 2 self.A[i] = self.merge(self.A[i * 2], self.A[i * 2 + 1]) def merge(self, a, b): return self.F(a, b) def total(self): return self.A[1] def query(self, a, b): A = self.A l = a + self.N r = b + self.N res = self.D while l < r: if l % 2 == 1: res = self.merge(res, A[l]) l += 1 if r % 2 == 1: r -= 1 res = self.merge(res, A[r]) l >>= 1 r >>= 1 return res N, S = inpl() X = [0] P = [0] for _ in range(N): x, p = inpl() X.append(x) P.append(p) P.append(0) l = bisect(X, S) - 1 x = S seg = Seg(P, 0, add) ans = 0 while seg.total(): L = seg.query(0, l + 1) R = seg.total() - L if L >= R: ans += abs(x - X[l]) seg.update(l, 0) x = X[l] l -= 1 else: ans += abs(x - X[l + 1]) seg.update(l + 1, 0) x = X[l + 1] l += 1
Statement There are N apartments along a number line, numbered 1 through N. Apartment i is located at coordinate X_i. Also, the office of AtCoder Inc. is located at coordinate S. Every employee of AtCoder lives in one of the N apartments. There are P_i employees who are living in Apartment i. All employees of AtCoder are now leaving the office all together. Since they are tired from work, they would like to get home by the company's bus. AtCoder owns only one bus, but it can accommodate all the employees. This bus will leave coordinate S with all the employees and move according to the following rule: * Everyone on the bus casts a vote on which direction the bus should proceed, positive or negative. (The bus is autonomous and has no driver.) Each person has one vote, and abstaining from voting is not allowed. Then, the bus moves a distance of 1 in the direction with the greater number of votes. If a tie occurs, the bus moves in the negative direction. If there is an apartment at the coordinate of the bus after the move, all the employees who live there get off. * Repeat the operation above as long as there is one or more employees on the bus. For a specific example, see Sample Input 1. The bus takes one seconds to travel a distance of 1. The time required to vote and get off the bus is ignorable. Every employee will vote so that he himself/she herself can get off the bus at the earliest possible time. Strictly speaking, when a vote is taking place, each employee see which direction results in the earlier arrival at his/her apartment, assuming that all the employees follow the same strategy in the future. Based on this information, each employee makes the optimal choice, but if either direction results in the arrival at the same time, he/she casts a vote to the negative direction. Find the time the bus will take from departure to arrival at the last employees' apartment. It can be proved that, given the positions of the apartments, the numbers of employees living in each apartment and the initial position of the bus, the future movement of the bus is uniquely determined, and the process will end in a finite time.
[{"input": "3 2\n 1 3\n 3 4\n 4 2", "output": "4\n \n\nAssume that the bus moves in the negative direction first. Then, the\ncoordinate of the bus changes from 2 to 1, and the employees living in\nApartment 1 get off. The movement of the bus after that is obvious: it just\ncontinues moving in the positive direction. Thus, if the bus moves in the\nnegative direction first, the coordinate of the bus changes as 2 \u2192 1 \u2192 2 \u2192 3 \u2192\n4 from departure. The time it takes to get home for the employees living in\nApartment 1, 2, 3 are 1, 3, 4 seconds, respectively.\n\nNext, assume that the bus moves in the positive direction first. Then, the\ncoordinate of the bus changes from 2 to 3, and the employees living in\nApartment 2 get off. Afterwards, the bus starts heading to Apartment 1,\nbecause there are more employees living in Apartment 1 than in Apartment 3.\nThen, after arriving at Apartment 1, the bus heads to Apartment 3. Thus, if\nthe bus moves in the positive direction first, the coordinate of the bus\nchanges as 2 \u2192 3 \u2192 2 \u2192 1 \u2192 2 \u2192 3 \u2192 4 from departure. The time it takes to get\nhome for the employees living in Apartment 1, 2, 3 are 3, 1, 6 seconds,\nrespectively.\n\nTherefore, in the beginning, the employees living in Apartment 1 or 3 will try\nto move the bus in the negative direction. On the other hand, the employees\nliving in Apartment 2 will try to move the bus in the positive direction in\nthe beginning. There are a total of 3 + 2 = 5 employees living in Apartment 1\nand 3 combined, which is more than those living in Apartment 2, which is 4.\nThus, the bus will move in the negative direction first, and the coordinate of\nthe bus will change as 2 \u2192 1 \u2192 2 \u2192 3 \u2192 4 from departure.\n\n* * *"}, {"input": "6 4\n 1 10\n 2 1000\n 3 100000\n 5 1000000\n 6 10000\n 7 100", "output": "21\n \n\nSince the numbers of employees living in different apartments are literally\noff by a digit, the bus consistently head to the apartment where the most\nnumber of employees on the bus lives.\n\n* * *"}, {"input": "15 409904902\n 94198000 15017\n 117995501 7656764\n 275583856 313263626\n 284496300 356635175\n 324233841 607\n 360631781 148\n 472103717 5224\n 497641071 34695\n 522945827 816241\n 554305668 32\n 623788284 22832\n 667409501 124410641\n 876731548 12078\n 904557302 291749534\n 918215789 5", "output": "2397671583"}]
The inferred messages are printed each on a separate line.
s549270700
Wrong Answer
p00819
The input format is as follows. _n The order of messengers The message given to the King . . . The order of messengers The message given to the King _ The first line of the input contains a positive integer n, which denotes the number of data sets. Each data set is a pair of the order of messengers and the message given to the King. The number of messengers relaying a message is between 1 and 6 inclusive. The same person may not appear more than once in the order of messengers. The length of a message is between 1 and 25 inclusive.
n = int(input()) for i in range(n): order = input() message = input() for s in order: if s == "J": message = message[1:] + message[0] elif s == "C": message = message[len(message) - 1] + message[: len(message) - 1] elif s == "E": message = message[len(message) // 2 :] + message[: len(message) // 2] elif s == "A": message = message[::-1] elif s == "P": for c in message: if c == "9": c = "0" elif c >= "0" and c < "9": c = chr(ord(c) + 1) elif s == "M": for c in message: if c == "0": c = "9" elif c > "0" and c <= "9": c = chr(ord(c) - 1) print(message)
A: Unreliable Messengers The King of a little Kingdom on a little island in the Pacific Ocean frequently has childish ideas. One day he said, “You shall make use of a message relaying game when you inform me of something.” In response to the King’s statement, six servants were selected as messengers whose names were Mr. J, Miss C, Mr. E, Mr. A, Dr. P, and Mr. M. They had to relay a message to the next messenger until the message got to the King. Messages addressed to the King consist of digits (‘0’-‘9’) and alphabet characters (‘a’-‘z’, ‘A’-‘Z’). Capital and small letters are distinguished in messages. For example, “ke3E9Aa” is a message. Contrary to King’s expectations, he always received wrong messages, because each messenger changed messages a bit before passing them to the next messenger. Since it irritated the King, he told you who are the Minister of the Science and Technology Agency of the Kingdom, “We don’t want such a wrong message any more. You shall develop software to correct it!” In response to the King’s new statement, you analyzed the messengers’ mistakes with all technologies in the Kingdom, and acquired the following features of mistakes of each messenger. A surprising point was that each messenger made the same mistake whenever relaying a message. The following facts were observed. Mr. J rotates all characters of the message to the left by one. For example, he transforms “aB23d” to “B23da”. Miss C rotates all characters of the message to the right by one. For example, she transforms “aB23d” to “daB23”. Mr. E swaps the left half of the message with the right half. If the message has an odd number of characters, the middle one does not move. For example, he transforms “e3ac” to “ace3”, and “aB23d” to “3d2aB”. Mr. A reverses the message. For example, he transforms “aB23d” to “d32Ba”. Dr. P increments by one all the digits in the message. If a digit is ‘9’, it becomes ‘0’. The alphabet characters do not change. For example, he transforms “aB23d” to “aB34d”, and “e9ac” to “e0ac”. Mr. M decrements by one all the digits in the message. If a digit is ‘0’, it becomes ‘9’. The alphabet characters do not change. For example, he transforms “aB23d” to “aB12d”, and “e0ac” to “e9ac”. The software you must develop is to infer the original message from the final message, given the order of the messengers. For example, if the order of the messengers is A -> J -> M -> P and the message given to the King is “aB23d”, what is the original message? According to the features of the messengers’ mistakes, the sequence leading to the final message is A J M P “32Bad” --> “daB23” --> “aB23d” --> “aB12d” --> “aB23d”. As a result, the original message should be “32Bad”.
[{"input": "AJMP\n aB23d\n E\n 86AE\n AM\n 6\n JPEM\n WaEaETC302Q\n CP\n rTurnAGundam1isdefferentf", "output": "Bad\n AE86\n 7\n EC302QTWaEa\n TurnAGundam0isdefferentfr"}]
Print the number of problems that have a chance to be chosen for the problemset. * * *
s391174589
Accepted
p02824
Input is given from Standard Input in the following format: N M V P A_1 A_2 ... A_N
# 解説を見た def solve(N: int, M: int, V: int, P: int, A: "list[int]") -> int: """ 入れてよい票 < M*V M*V投票するとjを超えるスコアを持つ問題数がP以上になり、不可能 入れてよい票 >= M*V 可能 次の条件を満たせば可能といえる # 各問題への投票数は許容範囲内 # すべてのjudgeがV投票 # すべてのjudgeが同じ問題に2度以上投票していない 投票してよい問題abc...zを 許容される投票数だけ連続させた列(最大M=すべてのjudgeが投票した場合) aaaabbbcc...z 仮定より長さMV以上なので, 冒頭の区間(長さMV)に対し,judgeを0...M-1,0...M-1,...と割り当てることができる この割り当ては,3つの条件を満たす """ from itertools import accumulate def is_ok(j): if j < P: return True # P位以内にM回加点 X = A[j] + M # 加点後のj位のスコアX if X < A[P]: return False # A[j]にM回加点、P位に加点なしでも勝てん return (j - P) * X - (acc[j - 1] - acc[P - 1]) >= M * (V - (P + N - j)) # return (P - 1 + 1 + N - j) * M + sum(X - A[k] for k in range(P, j)) >= M * V # (P-1)位以内,j位以降にM回加点 # P位~(j-1)位は,加点後のj位を超えない範囲で加点 # X>=A[P]>=A[k] # なので,各kに対し,0点以上加点できる # 移項して,累積和でオーダーを落とした def binary_search(): ok = 1 ng = N + 1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok (*A,) = sorted(A, reverse=True) A = [0] + A # 0-indexed -> 1-indexed acc = tuple(accumulate(A)) return binary_search() def main(): import sys input = sys.stdin.readline N, M, V, P = map(int, input().split()) A = map(int, input().split()) print(solve(N, M, V, P, A)) if __name__ == "__main__": main()
Statement N problems are proposed for an upcoming contest. Problem i has an initial integer score of A_i points. M judges are about to vote for problems they like. Each judge will choose exactly V problems, independently from the other judges, and increase the score of each chosen problem by 1. After all M judges cast their vote, the problems will be sorted in non- increasing order of score, and the first P problems will be chosen for the problemset. Problems with the same score can be ordered arbitrarily, this order is decided by the chief judge. How many problems out of the given N have a chance to be chosen for the problemset?
[{"input": "6 1 2 2\n 2 1 1 3 0 2", "output": "5\n \n\nIf the only judge votes for problems 2 and 5, the scores will be 2 2 1 3 1 2.\nThe problemset will consist of problem 4 and one of problems 1, 2, or 6.\n\nIf the only judge votes for problems 3 and 4, the scores will be 2 1 2 4 0 2.\nThe problemset will consist of problem 4 and one of problems 1, 3, or 6.\n\nThus, problems 1, 2, 3, 4, and 6 have a chance to be chosen for the\nproblemset. On the contrary, there is no way for problem 5 to be chosen.\n\n* * *"}, {"input": "6 1 5 2\n 2 1 1 3 0 2", "output": "3\n \n\nOnly problems 1, 4, and 6 have a chance to be chosen.\n\n* * *"}, {"input": "10 4 8 5\n 7 2 3 6 1 6 5 4 6 5", "output": "8"}]
Print the number of problems that have a chance to be chosen for the problemset. * * *
s165749352
Wrong Answer
p02824
Input is given from Standard Input in the following format: N M V P A_1 A_2 ... A_N
N, M, V, P = [int(x) for x in input().split()] A = sorted([int(x) for x in input().split()], reverse=True) maxA = A[0] cnt = 0 for a in A: cnt += a >= maxA - M print(cnt)
Statement N problems are proposed for an upcoming contest. Problem i has an initial integer score of A_i points. M judges are about to vote for problems they like. Each judge will choose exactly V problems, independently from the other judges, and increase the score of each chosen problem by 1. After all M judges cast their vote, the problems will be sorted in non- increasing order of score, and the first P problems will be chosen for the problemset. Problems with the same score can be ordered arbitrarily, this order is decided by the chief judge. How many problems out of the given N have a chance to be chosen for the problemset?
[{"input": "6 1 2 2\n 2 1 1 3 0 2", "output": "5\n \n\nIf the only judge votes for problems 2 and 5, the scores will be 2 2 1 3 1 2.\nThe problemset will consist of problem 4 and one of problems 1, 2, or 6.\n\nIf the only judge votes for problems 3 and 4, the scores will be 2 1 2 4 0 2.\nThe problemset will consist of problem 4 and one of problems 1, 3, or 6.\n\nThus, problems 1, 2, 3, 4, and 6 have a chance to be chosen for the\nproblemset. On the contrary, there is no way for problem 5 to be chosen.\n\n* * *"}, {"input": "6 1 5 2\n 2 1 1 3 0 2", "output": "3\n \n\nOnly problems 1, 4, and 6 have a chance to be chosen.\n\n* * *"}, {"input": "10 4 8 5\n 7 2 3 6 1 6 5 4 6 5", "output": "8"}]
Print the number of problems that have a chance to be chosen for the problemset. * * *
s837106837
Wrong Answer
p02824
Input is given from Standard Input in the following format: N M V P A_1 A_2 ... A_N
n, m, v, p = map(int, input().split()) a = sorted(list(map(int, input().split()))) border = a[-p] pos = sum([max(0, border - i) for i in a[: -(p + 1)]]) for key, i in enumerate(a): border_n = border pos_n = pos if p < v: must = (v - p) * m pos_n -= max(0, border_n - i) border_n += max(0, (must - pos_n + n - p + 1) // (n - p)) if i + m >= border_n: print(n - key) break
Statement N problems are proposed for an upcoming contest. Problem i has an initial integer score of A_i points. M judges are about to vote for problems they like. Each judge will choose exactly V problems, independently from the other judges, and increase the score of each chosen problem by 1. After all M judges cast their vote, the problems will be sorted in non- increasing order of score, and the first P problems will be chosen for the problemset. Problems with the same score can be ordered arbitrarily, this order is decided by the chief judge. How many problems out of the given N have a chance to be chosen for the problemset?
[{"input": "6 1 2 2\n 2 1 1 3 0 2", "output": "5\n \n\nIf the only judge votes for problems 2 and 5, the scores will be 2 2 1 3 1 2.\nThe problemset will consist of problem 4 and one of problems 1, 2, or 6.\n\nIf the only judge votes for problems 3 and 4, the scores will be 2 1 2 4 0 2.\nThe problemset will consist of problem 4 and one of problems 1, 3, or 6.\n\nThus, problems 1, 2, 3, 4, and 6 have a chance to be chosen for the\nproblemset. On the contrary, there is no way for problem 5 to be chosen.\n\n* * *"}, {"input": "6 1 5 2\n 2 1 1 3 0 2", "output": "3\n \n\nOnly problems 1, 4, and 6 have a chance to be chosen.\n\n* * *"}, {"input": "10 4 8 5\n 7 2 3 6 1 6 5 4 6 5", "output": "8"}]
Print the number of problems that have a chance to be chosen for the problemset. * * *
s771080692
Wrong Answer
p02824
Input is given from Standard Input in the following format: N M V P A_1 A_2 ... A_N
n, m, v, p = map(int, input().split()) A = list(map(int, input().split())) a = sorted(A, reverse=True) key_num = a[p - 1] k = a.count(key_num) key_idx = a.index(key_num) + k c = a[key_idx:] C = list(set(c)) cnt = 0 for i in c: idx = len(C) - C.index(i) if key_num <= i + m: if v < key_idx + idx: cnt += 1 print(cnt + key_idx)
Statement N problems are proposed for an upcoming contest. Problem i has an initial integer score of A_i points. M judges are about to vote for problems they like. Each judge will choose exactly V problems, independently from the other judges, and increase the score of each chosen problem by 1. After all M judges cast their vote, the problems will be sorted in non- increasing order of score, and the first P problems will be chosen for the problemset. Problems with the same score can be ordered arbitrarily, this order is decided by the chief judge. How many problems out of the given N have a chance to be chosen for the problemset?
[{"input": "6 1 2 2\n 2 1 1 3 0 2", "output": "5\n \n\nIf the only judge votes for problems 2 and 5, the scores will be 2 2 1 3 1 2.\nThe problemset will consist of problem 4 and one of problems 1, 2, or 6.\n\nIf the only judge votes for problems 3 and 4, the scores will be 2 1 2 4 0 2.\nThe problemset will consist of problem 4 and one of problems 1, 3, or 6.\n\nThus, problems 1, 2, 3, 4, and 6 have a chance to be chosen for the\nproblemset. On the contrary, there is no way for problem 5 to be chosen.\n\n* * *"}, {"input": "6 1 5 2\n 2 1 1 3 0 2", "output": "3\n \n\nOnly problems 1, 4, and 6 have a chance to be chosen.\n\n* * *"}, {"input": "10 4 8 5\n 7 2 3 6 1 6 5 4 6 5", "output": "8"}]
Print the number of problems that have a chance to be chosen for the problemset. * * *
s358445648
Wrong Answer
p02824
Input is given from Standard Input in the following format: N M V P A_1 A_2 ... A_N
n, m, v, p = [int(item) for item in input().split()] A = [int(item) for item in input().split()] A.sort() for i in range(len(A)): af = A[i + 1 : -p + 1] sum = 0 for item in af: sum = sum + A[i] + m - item if sum >= (len(af) - n + v) * m: print(n - i) break
Statement N problems are proposed for an upcoming contest. Problem i has an initial integer score of A_i points. M judges are about to vote for problems they like. Each judge will choose exactly V problems, independently from the other judges, and increase the score of each chosen problem by 1. After all M judges cast their vote, the problems will be sorted in non- increasing order of score, and the first P problems will be chosen for the problemset. Problems with the same score can be ordered arbitrarily, this order is decided by the chief judge. How many problems out of the given N have a chance to be chosen for the problemset?
[{"input": "6 1 2 2\n 2 1 1 3 0 2", "output": "5\n \n\nIf the only judge votes for problems 2 and 5, the scores will be 2 2 1 3 1 2.\nThe problemset will consist of problem 4 and one of problems 1, 2, or 6.\n\nIf the only judge votes for problems 3 and 4, the scores will be 2 1 2 4 0 2.\nThe problemset will consist of problem 4 and one of problems 1, 3, or 6.\n\nThus, problems 1, 2, 3, 4, and 6 have a chance to be chosen for the\nproblemset. On the contrary, there is no way for problem 5 to be chosen.\n\n* * *"}, {"input": "6 1 5 2\n 2 1 1 3 0 2", "output": "3\n \n\nOnly problems 1, 4, and 6 have a chance to be chosen.\n\n* * *"}, {"input": "10 4 8 5\n 7 2 3 6 1 6 5 4 6 5", "output": "8"}]
Output the distance between the two red dragonflies in a line.
s347320446
Accepted
p00376
The input is given in the following format. $x_1$ $x_2$ The input line provides dragonflies’ head positions $x_1$ and $x_2$ ($0 \leq x_1, x_2 \leq 100$) as integers.
x_1, x_2 = map(int, input().split()) x = abs(x_2 - x_1) print(x)
Red Dragonfly It’s still hot every day, but September has already come. It’s autumn according to the calendar. Looking around, I see two red dragonflies at rest on the wall in front of me. It’s autumn indeed. When two red dragonflies’ positional information as measured from the end of the wall is given, make a program to calculate the distance between their heads.
[{"input": "20 30", "output": "10"}, {"input": "50 25", "output": "25"}]
If it is possible to remove all the stones from the vertices, print `YES`. Otherwise, print `NO`. * * *
s189892650
Runtime Error
p03809
The input is given from Standard Input in the following format: N A_1 A_2 … A_N a_1 b_1 : a_{N-1} b_{N-1}
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) #define setp(n) fixed << setprecision(n) template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll,ll> #define pi pair<int,int> #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define mp make_pair #define ins insert using namespace std; vector<vi> adj; vll A; vll dp; bool ng=false; void dfs(int v, int p){ if (ng) return; if (v!=0 && adj[v].size()==1){ dp[v] = A[v]; return; } ll sum=0,cnt=0; for(auto u:adj[v]){ if (u==p) continue; dfs(u,v); sum+=dp[u]; cnt++; } if (cnt==1){ if (sum==A[v]) dp[v]=A[v]; else{ ng=true; return; } } ll x = sum-A[v]; if (x<0){ng=true; return;} ll y = A[v]-x; if (y<0){ng=true; return;} dp[v] = y; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n; cin>>n; adj.resize(n); A.resize(n); dp.resize(n); rep(i,n) cin>>A[i]; rep(i,n-1){ int a,b; cin>>a>>b; a--; b--; adj[a].pb(b); adj[b].pb(a); } dfs(0,-1); if (ng){ cout<<"NO\n"; }else{ cout<<"YES\n"; } return 0; }
Statement There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeatedly performing the following operation: * Select a pair of different leaves. Then, remove exactly one stone from every vertex on the path between those two vertices. Here, a _leaf_ is a vertex of the tree whose degree is 1, and the selected leaves themselves are also considered as vertices on the path connecting them. Note that the operation cannot be performed if there is a vertex with no stone on the path.
[{"input": "5\n 1 2 1 1 2\n 2 4\n 5 2\n 3 2\n 1 3", "output": "YES\n \n\nAll the stones can be removed, as follows:\n\n * Select vertices 4 and 5. Then, there is one stone remaining on each vertex except 4.\n * Select vertices 1 and 5. Then, there is no stone on any vertex.\n\n* * *"}, {"input": "3\n 1 2 1\n 1 2\n 2 3", "output": "NO\n \n\n* * *"}, {"input": "6\n 3 2 2 2 2 2\n 1 2\n 2 3\n 1 4\n 1 5\n 4 6", "output": "YES"}]
If it is possible to remove all the stones from the vertices, print `YES`. Otherwise, print `NO`. * * *
s993110612
Wrong Answer
p03809
The input is given from Standard Input in the following format: N A_1 A_2 … A_N a_1 b_1 : a_{N-1} b_{N-1}
print("NO")
Statement There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeatedly performing the following operation: * Select a pair of different leaves. Then, remove exactly one stone from every vertex on the path between those two vertices. Here, a _leaf_ is a vertex of the tree whose degree is 1, and the selected leaves themselves are also considered as vertices on the path connecting them. Note that the operation cannot be performed if there is a vertex with no stone on the path.
[{"input": "5\n 1 2 1 1 2\n 2 4\n 5 2\n 3 2\n 1 3", "output": "YES\n \n\nAll the stones can be removed, as follows:\n\n * Select vertices 4 and 5. Then, there is one stone remaining on each vertex except 4.\n * Select vertices 1 and 5. Then, there is no stone on any vertex.\n\n* * *"}, {"input": "3\n 1 2 1\n 1 2\n 2 3", "output": "NO\n \n\n* * *"}, {"input": "6\n 3 2 2 2 2 2\n 1 2\n 2 3\n 1 4\n 1 5\n 4 6", "output": "YES"}]
If it is possible to remove all the stones from the vertices, print `YES`. Otherwise, print `NO`. * * *
s144947964
Accepted
p03809
The input is given from Standard Input in the following format: N A_1 A_2 … A_N a_1 b_1 : a_{N-1} b_{N-1}
""" https://atcoder.jp/contests/agc010/tasks/agc010_c 似たような問題を最近やらなかったっけ…? →Complete Compressか 部分木に注目してみる 部分木から飛び出すパスの個数をXとしてみよう 余ったパスは上に投げるしかない →部分木から飛び出すパスの本数の最小をYとすると、Y[根] == 0 が答え 根は葉でない頂点を適当に選ぶ 飛び出すパスの本数の最小はどう計算するか? 最大と最小を受け取る いい感じにつなげて最小と最大を導出したい まず、最大・最小間はすべて作れるのか? 2本飛び出している奴を接続すると、飛び出しは2減り、1余るので飛び出しが1ふえる…? →もしかして飛び出し本数の候補はより少ない? 容量が X で、子が全部葉、 a,bとする n組繋げたとすると、 a+b-2n 本飛び出す X = n + (a+b-2n) = a+b-n なので、nは一定値になる n = a+b-X nは、最小は0、最大は過半数でなければa+b+… にでき、そうでなければ最大値以外の和の範囲を取れる nがその条件を満たしているかを調べればいい """ from sys import stdin import sys sys.setrecursionlimit(200000) def dfs(v, p): if len(lis[v]) == 1: return A[v] chlis = [] for nex in lis[v]: if nex != p: chlis.append(dfs(nex, v)) chlis.sort() chsum = sum(chlis) n = chsum - A[v] if chlis[-1] * 2 <= chsum: if 0 <= n <= chsum // 2: pass else: print("NO") sys.exit() else: if 0 <= n <= chsum - chlis[-1]: pass else: print("NO") sys.exit() return chsum - 2 * n N = int(stdin.readline()) A = list(map(int, stdin.readline().split())) if N == 2: if A[0] == A[1]: print("YES") else: print("NO") sys.exit() lis = [[] for i in range(N)] for loop in range(N - 1): u, v = map(int, stdin.readline().split()) u -= 1 v -= 1 lis[u].append(v) lis[v].append(u) root = None for i in range(N): if len(lis[i]) > 1: root = i break ret = dfs(root, root) if ret == 0: print("YES") else: print("NO")
Statement There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeatedly performing the following operation: * Select a pair of different leaves. Then, remove exactly one stone from every vertex on the path between those two vertices. Here, a _leaf_ is a vertex of the tree whose degree is 1, and the selected leaves themselves are also considered as vertices on the path connecting them. Note that the operation cannot be performed if there is a vertex with no stone on the path.
[{"input": "5\n 1 2 1 1 2\n 2 4\n 5 2\n 3 2\n 1 3", "output": "YES\n \n\nAll the stones can be removed, as follows:\n\n * Select vertices 4 and 5. Then, there is one stone remaining on each vertex except 4.\n * Select vertices 1 and 5. Then, there is no stone on any vertex.\n\n* * *"}, {"input": "3\n 1 2 1\n 1 2\n 2 3", "output": "NO\n \n\n* * *"}, {"input": "6\n 3 2 2 2 2 2\n 1 2\n 2 3\n 1 4\n 1 5\n 4 6", "output": "YES"}]
If it is possible to remove all the stones from the vertices, print `YES`. Otherwise, print `NO`. * * *
s835391511
Wrong Answer
p03809
The input is given from Standard Input in the following format: N A_1 A_2 … A_N a_1 b_1 : a_{N-1} b_{N-1}
N = int(input()) A = [int(n) for n in input().split()] edges = {n + 1: [] for n in range(N)} for n in range(N - 1): a, b = [int(n) for n in input().split()] edges[a].append(b) edges[b].append(a) ends = [k for k, v in edges.items() if len(v) == 1] roots = set() def search(past, p): dest = edges[p] if len(dest) == 1: past.append(p) roots.update(past) else: for i in range(dest): if dest[i] != past[-1]: past.append(p) search(past, dest[i]) for end in ends: search([end], edges[end][0]) # 全ての基底ベクトルはendsに収納されたので、このベクトルがはる空間にAが含まれるかどうかを検索したいだけの人生だった(敗北)
Statement There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeatedly performing the following operation: * Select a pair of different leaves. Then, remove exactly one stone from every vertex on the path between those two vertices. Here, a _leaf_ is a vertex of the tree whose degree is 1, and the selected leaves themselves are also considered as vertices on the path connecting them. Note that the operation cannot be performed if there is a vertex with no stone on the path.
[{"input": "5\n 1 2 1 1 2\n 2 4\n 5 2\n 3 2\n 1 3", "output": "YES\n \n\nAll the stones can be removed, as follows:\n\n * Select vertices 4 and 5. Then, there is one stone remaining on each vertex except 4.\n * Select vertices 1 and 5. Then, there is no stone on any vertex.\n\n* * *"}, {"input": "3\n 1 2 1\n 1 2\n 2 3", "output": "NO\n \n\n* * *"}, {"input": "6\n 3 2 2 2 2 2\n 1 2\n 2 3\n 1 4\n 1 5\n 4 6", "output": "YES"}]
If it is possible to remove all the stones from the vertices, print `YES`. Otherwise, print `NO`. * * *
s328037082
Runtime Error
p03809
The input is given from Standard Input in the following format: N A_1 A_2 … A_N a_1 b_1 : a_{N-1} b_{N-1}
import sys sys.setrecursionlimit(10**5 + 5) def dfs(v, p, aaa): if len(links[v]) == 1: return aaa[v] children = [] for u in links[v]: if u == p: continue result = dfs(u, v, aaa) if result == -1: return -1 children.append(result) if len(children) == 1: if aaa[v] != children[0]: return -1 return children[0] c_sum = sum(children) c_max = max(children) o_max = c_sum - c_max if o_max >= c_max: max_pairs = c_sum // 2 else: max_pairs = o_max min_remain = c_sum - max_pairs if not min_remain <= aaa[v] <= c_sum: return -1 return aaa[v] * 2 - c_sum def solve(n, aaa, links): # 葉でない頂点探し s = 0 while len(links[s]) == 1: s += 1 return dfs(s, -1, aaa) == 0 n = int(input()) aaa = list(map(int, input().split())) links = [set() for _ in range(n)] for line in sys.stdin: a, b = map(int, line.split()) a -= 1 b -= 1 links[a].add(b) links[b].add(a) print("YES" if solve(n, aaa, links) else "NO")
Statement There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeatedly performing the following operation: * Select a pair of different leaves. Then, remove exactly one stone from every vertex on the path between those two vertices. Here, a _leaf_ is a vertex of the tree whose degree is 1, and the selected leaves themselves are also considered as vertices on the path connecting them. Note that the operation cannot be performed if there is a vertex with no stone on the path.
[{"input": "5\n 1 2 1 1 2\n 2 4\n 5 2\n 3 2\n 1 3", "output": "YES\n \n\nAll the stones can be removed, as follows:\n\n * Select vertices 4 and 5. Then, there is one stone remaining on each vertex except 4.\n * Select vertices 1 and 5. Then, there is no stone on any vertex.\n\n* * *"}, {"input": "3\n 1 2 1\n 1 2\n 2 3", "output": "NO\n \n\n* * *"}, {"input": "6\n 3 2 2 2 2 2\n 1 2\n 2 3\n 1 4\n 1 5\n 4 6", "output": "YES"}]
Print the number of combination in a line.
s322561505
Runtime Error
p00008
The input consists of several datasets. Each dataset consists of n (1 ≤ n ≤ 50) in a line. The number of datasets is less than or equal to 50.
import sys [ print( [ 670, 660, 633, 592, 540, 480, 415, 348, 282, 220, 165, 120, 84, 56, 35, 20, 10, 4, 1, ][abs(18 - int(e))] ) for e in sys.stdin ]
Sum of 4 Integers Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).
[{"input": "1", "output": "4"}]
Print the number of combination in a line.
s251979894
Wrong Answer
p00008
The input consists of several datasets. Each dataset consists of n (1 ≤ n ≤ 50) in a line. The number of datasets is less than or equal to 50.
n = int(input()) ans = 0 table = [ [a, b, c, d] for a in range(10) for b in range(10) for c in range(10) for d in range(10) ] for abcd in table: ans += sum(abcd) == n print(ans)
Sum of 4 Integers Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).
[{"input": "1", "output": "4"}]
Print the number of combination in a line.
s545573461
Wrong Answer
p00008
The input consists of several datasets. Each dataset consists of n (1 ≤ n ≤ 50) in a line. The number of datasets is less than or equal to 50.
num = int(input()) sum = 0 Range = 10 for a in range(Range): for b in range(Range): for c in range(Range): for d in range(Range): if num == a + b + c + d: sum += 1 print(sum)
Sum of 4 Integers Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).
[{"input": "1", "output": "4"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s290715790
Wrong Answer
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
# -*- coding: utf-8 -*- import sys [n, q] = [int(x) for x in sys.stdin.readline().rstrip().split()] counts = [0] * (n + 1) adjs = [[int(x) for x in sys.stdin.readline().rstrip().split()] for i in range(n - 1)] costs = [[int(x) for x in sys.stdin.readline().rstrip().split()] for i in range(q)] sorted(adjs, key=lambda x: x[0]) for cost in costs: counts[cost[0]] += cost[1] for adj in adjs: counts[adj[1]] += counts[adj[0]] print(" ".join(list(map(lambda x: str(x), counts[1:]))))
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s537544865
Runtime Error
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
N, Q, *D = map(int, open(0).read().split()) val = [0 for _ in range(N + 2)] E = [[] for _ in range(N + 2)] D = list(zip(*[iter(D)] * 2)) assert len(D) == N + Q - 1 for i in range(N + Q - 1): l, r = D[i][0], D[i][1] if i < N - 1: E[l].append(r) E[r].append(l) else: val[l] += r visited = [False for _ in range(N + 1)] def dfs(c): visited[c] = True for ch in E[c]: if not visited[ch]: val[ch] += val[c] dfs(ch) dfs(1) print(" ".join(map(str, val[1:])))
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s286759294
Accepted
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(N - 1)] px = [list(map(int, input().split())) for _ in range(Q)] class Tree: C = {} N, D = None, None def __init__(s, num): s.N = num def setC(s, a, b): if a in s.C: s.C[a].append(b) else: s.C[a] = [b] if b in s.C: s.C[b].append(a) else: s.C[b] = [a] def exe(s): L = [-1] * N A = [0] * N for p, x in px: p -= 1 A[p] += x S = [0] while S != []: t = S.pop() L[t] = 1 for i in s.C[t]: if L[i] == -1: A[i] += A[t] S.append(i) for i in range(N): print(A[i], end=" ") T = Tree(N) for a, b in ab: a -= 1 b -= 1 T.setC(a, b) T.exe()
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s978396851
Accepted
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
import sys input = sys.stdin.readline n, q = map(int, input().split()) l = [list(map(int, input().split())) for i in range(n - 1)] connection = [[] for i in range(n)] for i in range(n - 1): connection[l[i][0] - 1].append(l[i][1] - 1) connection[l[i][1] - 1].append(l[i][0] - 1) L = [list(map(int, input().split())) for i in range(q)] ctL = [0] * n for i in range(q): ctL[L[i][0] - 1] += L[i][1] def bfs(v): distance = [-1] * n distance[v] = ctL[v] next = [v] next2 = set() visited = [-1] * n visitct = 0 while len(next) != 0 and visitct != n: for i in range(len(next)): if visited[next[i]] == -1: visited[next[i]] = 1 visitct += 1 for j in range(len(connection[next[i]])): if visited[connection[next[i]][j]] == -1: distance[connection[next[i]][j]] = ( distance[next[i]] + ctL[connection[next[i]][j]] ) next2.add(connection[next[i]][j]) next = list(next2) next2 = set() return distance x = bfs(0) for i in range(n): x[i] = str(x[i]) print(" ".join(x))
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s261166675
Wrong Answer
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
N, Q = [int(s) for s in input().split()] e_list = [[int(s) for s in input().split()] for i in range(N - 1)] answer = [0 for i in range(N + 1)] for i in range(Q): a, b = [int(s) for s in input().split()] answer[a] += b for e in e_list: answer[e[1]] += answer[e[0]] answer.remove(0) print(*answer)
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s094883379
Runtime Error
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) s = [[0 for _ in range(2)] for _ in range(n)] for i in range(n): cnt = 0 now = i while True: now = p[now] - 1 s[i][0] += c[now] cnt += 1 if now == i: break s[i][1] = cnt ans = -(10**16) for j in range(n): if s[j][0] > 0 and k // s[j][1] > 0: # 何回か回る cnt1, cnt2 = k, k a = k // s[j][1] # 最大周回数 score1 = a * s[j][0] score2 = (a - 1) * s[j][0] cnt1 -= a * s[j][1] now = j pscore1 = 0 pscore_max1 = 0 for x in range(cnt1): now = p[now] - 1 pscore1 += c[now] pscore_max1 = max(pscore_max1, pscore1) score1 += pscore_max1 now = j pscore2 = 0 pscore_max2 = 0 for y in range(s[j][1]): now = p[now] - 1 pscore2 += c[now] pscore_max2 = max(pscore_max2, pscore2) score2 += pscore_max2 score_max = max(score1, score2) else: now = j score = 0 score_max = c[p[now] - 1] for x in range(min(k, s[j][1])): now = p[now] - 1 score += c[now] score_max = max(score_max, score) ans = max(ans, score_max) print(ans)
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s008805814
Wrong Answer
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
import sys from collections import defaultdict sys.setrecursionlimit(10**7) n, q = [int(x) for x in input().split()] ab = [[int(x) for x in input().split()] for _ in range(n - 1)] px = [[int(x) for x in input().split()] for _ in range(q)] s = [ 0, ] * n def calc(dd, i, num): global s if dd[i] == []: s[i - 1] += num return True else: s[i - 1] += num for item in dd[i]: calc(dd, item, num) return True dd = defaultdict(list) for key in range(1, n): dd[ab[key - 1][0]].append(ab[key - 1][1]) for item in px: calc(dd, item[0], item[1]) print(*s)
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s643951564
Wrong Answer
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
import sys input = sys.stdin.readline n, q = [int(i) for i in input().split()] def find(x): if par[x][0] < 0: return x else: px = find(par[x][0]) par[x][0] = px return px def unite(x, y): x = find(x) y = find(y) if x == y: return False else: # sizeの大きいほうがx if par[x][0] > par[y][0]: x, y = y, x par[x][0] += par[y][0] par[y][0] = x return True memo = [True] * n par = [[-1, 0, i] for i in range(n)] for i in range(n - 1): a, b = [int(i) for i in input().split()] unite(a - 1, b - 1) if memo[a - 1] and memo[b - 1]: par[b - 1][1] += 1 elif memo[b - 1] and not memo[a - 1]: par[b - 1][1] += 1 + par[a - 1][1] elif memo[a - 1] and not memo[b - 1]: par[a - 1][1] += 1 + par[b - 1][1] memo[a - 1] = False memo[b - 1] = False chk = [0] * n for i in range(q): p, x = [int(i) for i in input().split()] chk[p - 1] += x from operator import itemgetter par = sorted(par, key=itemgetter(1)) par = sorted(par, key=itemgetter(0)) # print(par) cnt = 0 for i in range(1, n): if par[i][0] >= 0 and par[i][1] == 1: chk[par[i][2]] += chk[par[i][0]] cnt = 0 if par[i][0] >= 0 and par[i][1] >= 2: if par[i][0] == par[i - 1][0] and par[i][1] > par[i - 1][1]: chk[par[i][2]] += chk[par[i - 1][2]] cnt = 0 if par[i][0] == par[i - 1][0] and par[i][1] == par[i - 1][1] and par[i][1] >= 2: cnt += 1 chk[par[i][2]] += chk[par[i - 1 - cnt][2]] chk = list(map(str, chk)) print(" ".join(chk))
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s569154511
Runtime Error
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
class TreeNode: def __init__(self): self.val = 0 self.vertex = [] def make_trees(n, A, B): trees = [] for i in range(n): trees.append(TreeNode()) for i in range(len(A)): a = A[i] - 1 b = B[i] - 1 trees[a].vertex.append(b) return trees def dfs(node: TreeNode, carry: int, trees): if node: node.val += carry for i in node.vertex: dfs(trees[i], node.val, trees) def dfs2(carry, i, trees, values): values[i] += carry for j in trees[i]: dfs2(values[i], j, trees, values) def sol(n, q, A, B, P, X): trees = make_trees(n, A, B) for i in range(len(P)): p = P[i] - 1 x = X[i] t = trees[p] # dfs, give point x t.val += x # accmulative run dfs(trees[0], 0, trees) # return " ".join([str(t.val) for t in trees]) # return n, q, A, B, P, X do_submit = True # do_submit = False def input_parse(input_str): lines = [x.strip() for x in input_str.split("\n") if x.strip()] parsed_lines = [list(map(str, line.split())) for line in lines] print(parsed_lines) n = int(parsed_lines[0][0]) q = int(parsed_lines[0][1]) A = [] B = [] P = [] X = [] for i in range(1, n - 1 + 1): a = int(parsed_lines[i][0]) b = int(parsed_lines[i][1]) A.append(a) B.append(b) for i in range(n, 1 + n + q - 1): p = int(parsed_lines[i][0]) x = int(parsed_lines[i][1]) P.append(p) X.append(x) # S = parsed_lines[1][0] # return n, k, S return n, q, A, B, P, X if not do_submit: n, q, A, B, P, X = input_parse( """ 4 3 1 2 2 3 2 4 2 10 1 100 3 1 """ ) print(sol(n, q, A, B, P, X)) n, q, A, B, P, X = input_parse( """ 6 2 1 2 1 3 2 4 3 6 2 5 1 10 1 10 """ ) print(sol(n, q, A, B, P, X)) n, q, A, B, P, X = input_parse( """ 10 5 1 2 1 3 1 4 2 5 2 6 3 7 4 8 4 9 7 10 7 3 3 100 1 2 5 10 4 11 """ ) print(sol(n, q, A, B, P, X)) else: n, q = list(map(int, input().split())) trees = [[] for i in range(n)] values = [0 for i in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) trees[a - 1].append(b - 1) for i in range(q): p, x = list(map(int, input().split())) # dfs, give point x values[p - 1] = values[p - 1] + x # accmulative run dfs2(0, 0, trees, values) # for x in values: print(x, end=" ")
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s620783430
Accepted
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
N, Q = map(int, input().split()) tree_data = [tuple(map(int, input().split())) for i in range(N - 1)] operation = [tuple(map(int, input().split())) for i in range(Q)] tree_data = sorted(tree_data) node = dict(zip(range(1, N + 1), [0] * N)) for o in operation: node[o[0]] += o[1] for n in tree_data: node[n[1]] += node[n[0]] print(" ".join(map(str, node.values())))
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s358258216
Wrong Answer
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
n, m = map(int, input().split()) s = [list(map(int, input().split())) for _ in range(n - 1)] t = [list(map(int, input().split())) for _ in range(m)] s.sort() list = [0] * n for i in range(m): a = t[i][0] - 1 list[a] += t[i][1] for j in range(n - 1): a = s[j][0] - 1 b = s[j][1] - 1 list[b] += list[a] print(*list)
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s799950554
Wrong Answer
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
# ki from collections import deque # input n, q = map(int, input().split()) ln = [list(map(int, input().split())) for i in range(n - 1)] lq = [list(map(int, input().split())) for i in range(q)] edge = [[] for i in range(n + 1)] for next in ln: parent = next[0] child = next[1] edge[parent].append(child) score = [0] * (n + 1) visited = [False] * (n + 1) for q in lq: score[q[0]] += q[1] que = deque() que.append(1) while que: node = que.popleft() if not visited[node]: visited[node] = True for next in edge[node]: if not visited[next]: score[next] += score[node] que.append(next) print(" ".join([str(n) for n in score][1:]))
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s812273263
Accepted
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
from collections import deque # pypyでも使える n, q = map(int, input().split()) edges = [[] for i in range(n)] # 枝がどことどこをつなぐかの情報を入れておく二次元配列 for i in range(n - 1): a, b = map(lambda x: int(x) - 1, input().split()) # ラムダ式は必見 # もっといい感じの書き方ないかな? edges[a].append(b) # edges[a]には、ノードaの相方を格納 edges[b].append(a) # edges[b]には、ノードbの相方を格納する決まり # nodesの重さを格納 nodes = [0] * n for i in range(q): p, x = map(int, input().split()) nodes[p - 1] += x # oyakoを、親についての単調増加にしたい->デフォで先頭要素でのソートになるので安心 # oyako.sort() # と思ったけどソートじゃ無理っぽい # 根から順に処理->bfs幅優先探索 que = deque([0]) color = [0] * n # 全てのノードに対して、未探索の0を入れる color[0] = 0 # colorは親としての処理を終えたかどうかを入れる。終えたら1にする # TLEなった。二重ループはだめねえ。 # ->oyako(edges)を、二次元配列にしてインデックスの数字を持つものをedges[i]に格納すれば while que: # qが空でないのはこう表現できる i = que.popleft() if color[i] == 0: for edge in edges[i]: if color[edge] == 0: # 相方が親じゃなければ(親ならすでに探索済みのはず) nodes[edge] += nodes[i] que.append(edge) color[i] = 1 # 綺麗にかけそうでこの書き方をしたけど大丈夫かな? for node in nodes: print(node, end=" ")
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s145511872
Wrong Answer
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
N, Q = map(int, input().split()) i = 1 AB = list() while i <= N - 1: AB.append(list(map(int, input().split()))) i += 1 print(AB) i = 1 PX = list() while i <= Q: PX.append(list(map(int, input().split()))) i += 1 print(PX) print(PX) V = [0 for i in range(N)] level = 0 tree = [[1]] while AB: i = 0 tree.append([]) delis = list() for a, b in AB: if a in tree[level]: tree[level + 1].append(b) delis.append(i) if b in tree[level]: tree[level + 1].append(a) delis.append(i) i += 1 print(AB) print(tree) level += 1 for j in delis: AB[j] = 0 print(j) AB = [i for i in AB if i != 0] print(tree) for p, x in PX: i = 0 for t in tree: if p in t: break i += 1 V[p - 1] += x i += 1 while i < len(tree): t = tree[i] for n in t: V[n - 1] += x i += 1 print(" ".join(map(str, V))) # print(T) # # j = 0 # for p,x in PX: # if p in AB[j]: # T[p-1] += x
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s074216879
Wrong Answer
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
N, Q = map(int, input().split()) AB = [tuple(int(i) for i in input().split()) for j in range(N - 1)] PX = [tuple(int(i) for i in input().split()) for j in range(Q)] # childのindex:ノードの番号 # indexのノードがもつ子ノードの番号のリストを収納 child = [[] for i in range(N + 1)] # N for a, b in AB: # (N-1)*2 child[a].append(b) # 1+1 # N + 2*(N-1)*2 = 5*N -4 value = [0] * (N + 1) # 1*(N+1) for p, x in PX: # Q value[p] += x # 1+1 # 2*Q + (N+1) stack = [1] # 1 while stack: # i = stack.pop() # 1 for j in child[i]: # stack.append(j) value[j] += value[i] ans = " ".join(map(str, value[1:])) print(ans) # import sys # readline = sys.stdin.readline # readlines = sys.stdin.readlines # N,Q = map(int,readline().split()) # AB = [tuple(int(x) for x in readline().split()) for _ in range(N-1)] # PX = [tuple(int(x) for x in readline().split()) for _ in range(Q)] # child = [[] for _ in range(N+1)] # for a,b in AB: # child[a].append(b) # child[b].append(a) # value = [0] * (N+1) # for p,x in PX: # value[p] += x # par = [None] * (N+1) # q = [1] # while q: # x = q.pop() # for y in child[x]: # if y == par[x]: # continue # value[y] += value[x] # q.append(y) # par[y] = x # ans = ' '.join(map(str,value[1:])) # print(ans)
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s056494256
Accepted
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
import sys sys.setrecursionlimit(10**7) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline().strip() INF = 10**18 MOD = 10**9 + 7 debug = True debug = False def dprint(*objects): if debug == True: print(*objects) def solve(): nodedict = {} preorder_list = [] class Node: def __init__(self, id): self.id = id self.childlist = [] self.p = 0 self.walked = False def __repr__(self): return str(self.__dict__) def preorder(self, p): if self.walked: return 0 self.p = self.p + p self.walked = True preorder_list.append(self.id) for child in self.childlist: child.preorder(self.p) return 0 N, Q = LI() for i in range(1, N + 1): nodedict[i] = Node(i) for i in range(N - 1): a, b = LI() nodedict[a].childlist.append(nodedict[b]) for i in range(Q): p, x = LI() nodedict[p].p += x # preorder nodedict[1].preorder(0) dprint(preorder_list) print(" ".join([str(nodedict[i].p) for i in range(1, N + 1)])) solve()
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s007413938
Runtime Error
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
n, q = map(int, input().split()) a = [0] * (n - 1) b = [0] * (n - 1) info = [[] for _ in range(n)] for i in range(n - 1): a[i], b[i] = map(int, input().split()) a[i] -= 1 b[i] -= 1 info[a[i]].append(b[i]) info[b[i]].append(a[i]) p = [0] * q x = [0] * q for j in range(q): p[j], x[j] = map(int, input().split()) p[j] -= 1 plus = [0] * n for j in range(q): plus[p[j]] += x[j] state = [0] * n state[0] = 1 cur = [0] child = [[] for _ in range(n)] par = [0] * n ranklist = [[1]] # print(cur) # print(info) while cur != []: cur2 = [] ranklist.append([]) for obj in cur: for obj2 in info[obj]: if state[obj2] == 0: state[obj2] = 1 # child[obj].append(obj2) par[obj2] = obj cur2.append(obj2) ranklist[-1].append(obj2) cur = cur2[:] ans = [0] * n ans[0] = plus[0] for l in ranklist: for t in l: ans[t] = ans[par[t]] + plus[t] print(" ".join(map(str, ans))) # from collections import deque n, q = map(int, input().split()) a = [0] * (n - 1) b = [0] * (n - 1) info = [[] for _ in range(n)] for i in range(n - 1): a[i], b[i] = map(int, input().split()) a[i] -= 1 b[i] -= 1 info[a[i]].append(b[i]) info[b[i]].append(a[i]) p = [0] * q x = [0] * q for j in range(q): p[j], x[j] = map(int, input().split()) p[j] -= 1 plus = [0] * n for j in range(q): plus[p[j]] += x[j] state = [0] * n state[0] = 1 cur = [0] child = [[] for _ in range(n)] par = [0] * n ranklist = [[1]] # print(cur) # print(info) while cur != []: cur2 = [] ranklist.append([]) for obj in cur: for obj2 in info[obj]: if state[obj2] == 0: state[obj2] = 1 # child[obj].append(obj2) par[obj2] = obj cur2.append(obj2) ranklist[-1].append(obj2) cur = cur2[:] ans = [0] * n ans[0] = plus[0] for l in ranklist: for t in l: ans[t] = ans[par[t]] + plus[t] print(" ".join(map(str, ans)))
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s158913364
Runtime Error
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
num, q = [int(s) for s in input().split()] count = [0 for s in range(num)] family = [[] for s in range(num)] for i in range(num - 1): a, b = [int(s) - 1 for s in input().split()] family[a].append(b) print(family) def countup(a, b): if len(family[a]) > 0: for k in family[a]: count[k] += b if len(family[k]) > 0: countup(k, b) for i in range(q): a, b = [int(s) - 1 for s in input().split()] b += 1 count[a] += b countup(a, b) answer = str(count[0]) for i in range(num - 1): answer += " " + str(count[i + 1]) print(answer)
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. * * *
s651087470
Wrong Answer
p02936
Input is given from Standard Input in the following format: N Q a_1 b_1 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q
n, q = map(int, input().split()) lis1 = [] for i in range(n - 1): tup1 = tuple(map(int, input().split())) lis1.append(tup1) lis2 = [] for i in range(q): tup2 = tuple(map(int, input().split())) lis2.append(tup2) lis = [0 for i in range(n)] for i in range(q): numPlus = lis2[i][0] plusValue = lis2[i][1] lisPlus = [numPlus - 1] for j in range(numPlus + 1, n + 1): if (numPlus, j) in lis1: lisPlus.append(j - 1) for l in range(j + 1, n + 1): if (j, l) in lis1: lisPlus.append(l - 1) for m in range(l + 1, n + 1): if (l, m) in lis1: lisPlus.append(m - 1) for y in range(m + 1, n + 1): if (m, y) in lis1: lisPlus.append(y - 1) for k in lisPlus: lis[k] += plusValue print(lis)
Statement Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
[{"input": "4 3\n 1 2\n 2 3\n 2 4\n 2 10\n 1 100\n 3 1", "output": "100 110 111 110\n \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n 1 2\n 1 3\n 2 4\n 3 6\n 2 5\n 1 10\n 1 10", "output": "20 20 20 20 20 20"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s748957311
Runtime Error
p03624
Input is given from Standard Input in the following format: S
alphabeta = "abcdefghijklmnopqrstuvwxyz" all_str = set(alphabeta) str = input() str = set(str) use = all_str - str print(sorted(use)[0])
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s941426684
Runtime Error
p03624
Input is given from Standard Input in the following format: S
s_list = list(input()) result = None for s_uni in range(ord('a'), ord('z') + 1): if not chr(s_uni) in s_list: result = chr(s_uni) break if result: print(result) else print('None')
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s540344852
Accepted
p03624
Input is given from Standard Input in the following format: S
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list(map(lambda x: int(x) - 1, stdin.readline().split())) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 alp = [chr(ord("a") + i) for i in range(26)] # A def A(): x, a, b = LI() if abs(x - a) > abs(x - b): print("B") else: print("A") return # B def B(): s = S() s = set(s) for i in s: alp.remove(i) if len(alp) == 0: print("None") else: print(alp[0]) return # C def C(): return # D def D(): return # E def E(): return # F def F(): return # G def G(): return # H def H(): return # Solve if __name__ == "__main__": B()
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s997244128
Accepted
p03624
Input is given from Standard Input in the following format: S
d = [0] * 26 for i in input(): d[ord(i) - 97] += 1 print(chr(97 + d.index(0)) if 0 in d else "None")
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]