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 `Yes` if w is beautiful. Print `No` otherwise. * * *
s962452641
Runtime Error
p04012
The input is given from Standard Input in the following format: w
w = input() a = "abcdefghijklmnopqrstuvwxyz" co = 0 ch = True for i in a: for j in w: if i = j: co += 1: if co % 2: ch = False break co = 0 if ch: print("yes") else: print("No")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s359746794
Runtime Error
p04012
The input is given from Standard Input in the following format: w
li = [0]*26 alpha2num = lambda c: ord(c) - ord("A") + 1 w = input().upper() for i in range(len(w)): k = alpha2num(w[i]) li[k] += 1 else: for j in li: if(not j %= 2): print("No") break else: print("Yes")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s172469321
Accepted
p04012
The input is given from Standard Input in the following format: w
strlist = list(input()) findlist = "qazwsxedcrfvtgbyhnujmikolp" flist = list(findlist) flag = "Yes" for a in flist: if strlist.count(a) % 2: flag = "No" print(flag)
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s835042965
Runtime Error
p04012
The input is given from Standard Input in the following format: w
w = list(input()) ans = "Yes" for i in w: cnt = 0 for j in w: if i == j: cnt += 1 if cnt%2 == 1: ans = "No" break print(ans
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s746200627
Runtime Error
p04012
The input is given from Standard Input in the following format: w
s=input() print("Yes" if all([s.count(i)%2==0] for i in set(s)] else "No")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s163787253
Runtime Error
p04012
The input is given from Standard Input in the following format: w
s=input();c=[f=0]*26 for i in s:c[ord(i)-97]+=1 for i in c:f+=i%2 print("YNeos"[!!f::2])
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s250181414
Runtime Error
p04012
The input is given from Standard Input in the following format: w
s,ans=input(),0;a=[s[i]for i in range(len(s))];a.sort() for i in a: if a.count(i)%2!=0:ans=1 if ans=0:print("Yes") else:print("No")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s845841903
Runtime Error
p04012
The input is given from Standard Input in the following format: w
a = defaultdict(int) for w in input(): a[w] += 1 print("Yes" if sum(c % 2 for c in a.values()) == 0 else "No")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s308140377
Accepted
p04012
The input is given from Standard Input in the following format: w
w = input() num = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for i in range(len(w)): if w[i] == "a": num[0] += 1 elif w[i] == "b": num[1] += 1 elif w[i] == "c": num[2] += 1 elif w[i] == "d": num[3] += 1 elif w[i] == "e": num[4] += 1 elif w[i] == "f": num[5] += 1 elif w[i] == "g": num[6] += 1 elif w[i] == "h": num[7] += 1 elif w[i] == "i": num[8] += 1 elif w[i] == "j": num[9] += 1 elif w[i] == "k": num[10] += 1 elif w[i] == "l": num[11] += 1 elif w[i] == "m": num[12] += 1 elif w[i] == "n": num[13] += 1 elif w[i] == "o": num[14] += 1 elif w[i] == "p": num[15] += 1 elif w[i] == "q": num[16] += 1 elif w[i] == "r": num[17] += 1 elif w[i] == "s": num[18] += 1 elif w[i] == "t": num[19] += 1 elif w[i] == "u": num[20] += 1 elif w[i] == "v": num[21] += 1 elif w[i] == "w": num[22] += 1 elif w[i] == "x": num[23] += 1 elif w[i] == "y": num[24] += 1 elif w[i] == "z": num[25] += 1 ans = "Yes" for i in range(len(num)): if num[i] % 2 == 1: ans = "No" break print(ans)
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s651138229
Runtime Error
p04012
The input is given from Standard Input in the following format: w
import sys S = input() alp = list(set(S)) cnts = [0] * len(alp) for i in range(len(S)): cnts(alp.index(S[i])) += 1 for a in cnts: if a % 2 == 1: print("No") sys.exit() print("Yes")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s035876876
Runtime Error
p04012
The input is given from Standard Input in the following format: w
s=input() p=list(set(list(s))) a=[] for i in p: a.append(s.count(i)) for x in a: if x%2!==0: print("No") exit() print("Yes")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s054140555
Wrong Answer
p04012
The input is given from Standard Input in the following format: w
# 2019/10/24 S = list(open(0).read()) set_S = list(set(S)) beautiful = [S.count(i) % 2 for i in set_S] print("Yes" if sum(beautiful) == 0 else "No")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s481487615
Runtime Error
p04012
The input is given from Standard Input in the following format: w
vimport sys w = input() checker = set(w) for i in checker: if w.count(i)%2 == 1: print("No") sys.exit() print("Yes")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s248515623
Runtime Error
p04012
The input is given from Standard Input in the following format: w
d = {c: list(input()) for c in "abc"} s = "a" while d[s]: s = d[s].pop(0) print(s.upper())
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print `4`.) * * *
s303676326
Wrong Answer
p02596
Input is given from Standard Input in the following format: K
1
Statement Takahashi loves the number 7 and multiples of K. Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.) If the sequence contains no multiples of K, print `-1` instead.
[{"input": "101", "output": "4\n \n\nNone of 7, 77, and 777 is a multiple of 101, but 7777 is.\n\n* * *"}, {"input": "2", "output": "-1\n \n\nAll elements in the sequence are odd numbers; there are no multiples of 2.\n\n* * *"}, {"input": "999983", "output": "999982"}]
Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print `4`.) * * *
s331416061
Wrong Answer
p02596
Input is given from Standard Input in the following format: K
K = int(input()) mod = K if K == 1: print(1) elif K % 2 == 0 or K % 5 == 0: print(-1) elif K % 7 != 0: x = 10 % mod X = [1] * K S = [1] * K for i in range(1, K + 1): X[i] = (X[i - 1] * x) % mod S[i] = S[i - 1] + X[i] if S[i] % mod == 0: print(i + 1) exit() print(-1) else: mod = K // 7 if mod == 1: print(1) else: x = 10 % mod y = 1 % mod X = [y] * K S = [y] * K for i in range(1, K + 1): X[i] = (X[i - 1] * x) % mod S[i] = S[i - 1] + X[i] if S[i] % mod == 0: print(i + 1) exit() print(-1)
Statement Takahashi loves the number 7 and multiples of K. Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.) If the sequence contains no multiples of K, print `-1` instead.
[{"input": "101", "output": "4\n \n\nNone of 7, 77, and 777 is a multiple of 101, but 7777 is.\n\n* * *"}, {"input": "2", "output": "-1\n \n\nAll elements in the sequence are odd numbers; there are no multiples of 2.\n\n* * *"}, {"input": "999983", "output": "999982"}]
Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print `4`.) * * *
s943866603
Wrong Answer
p02596
Input is given from Standard Input in the following format: K
#!/usr/bin/env python3 import sys def main(): input = sys.stdin.readline k = int(input()) if ( k % 10 == 2 or k % 10 == 4 or k % 10 == 5 or k % 10 == 6 or k % 10 == 8 or k % 10 == 0 ): print(-1) exit() elif k % 10 == 1: tmp = k * 7 ans = 1 while True: if str(tmp).count("7") == len(str(tmp)): print(ans + len(str(tmp)) - 1) break if tmp // 10 % 10 <= 7: num = 7 - tmp // 10 % 10 else: num = tmp // 10 % 10 - 7 tmp2 = k * num tmp = tmp // 10 + tmp2 ans += 1 if ans > 10**8: print(-1) break elif k % 10 == 3: tmp = k * 9 ans = 1 while True: if str(tmp).count("7") == len(str(tmp)): print(ans + len(str(tmp)) - 1) break num = ((tmp // 10 % 10) * 3 - 1) % 10 tmp2 = k * num tmp = tmp // 10 + tmp2 ans += 1 if ans > 5 * 10**7: print(-1) break elif k % 10 == 7: tmp = k * 1 ans = 1 while True: if str(tmp).count("7") == len(str(tmp)): print(ans + len(str(tmp)) - 1) break num = ((tmp // 10 % 10) * 7 + 1) % 10 tmp2 = k * num tmp = tmp // 10 + tmp2 ans += 1 if ans > 10**8: print(-1) break elif k % 10 == 9: tmp = k * 3 ans = 1 while True: if str(tmp).count("7") == len(str(tmp)): print(ans + len(str(tmp)) - 1) break num = ((tmp // 10 % 10) + 3) % 10 tmp2 = k * num ans += 1 if ans > 10**8: print(-1) break if __name__ == "__main__": main()
Statement Takahashi loves the number 7 and multiples of K. Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.) If the sequence contains no multiples of K, print `-1` instead.
[{"input": "101", "output": "4\n \n\nNone of 7, 77, and 777 is a multiple of 101, but 7777 is.\n\n* * *"}, {"input": "2", "output": "-1\n \n\nAll elements in the sequence are odd numbers; there are no multiples of 2.\n\n* * *"}, {"input": "999983", "output": "999982"}]
Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print `4`.) * * *
s996087562
Wrong Answer
p02596
Input is given from Standard Input in the following format: K
a = int(input("")) print(777777 / a)
Statement Takahashi loves the number 7 and multiples of K. Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.) If the sequence contains no multiples of K, print `-1` instead.
[{"input": "101", "output": "4\n \n\nNone of 7, 77, and 777 is a multiple of 101, but 7777 is.\n\n* * *"}, {"input": "2", "output": "-1\n \n\nAll elements in the sequence are odd numbers; there are no multiples of 2.\n\n* * *"}, {"input": "999983", "output": "999982"}]
Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print `4`.) * * *
s191534943
Wrong Answer
p02596
Input is given from Standard Input in the following format: K
print(int(input()) - 1)
Statement Takahashi loves the number 7 and multiples of K. Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.) If the sequence contains no multiples of K, print `-1` instead.
[{"input": "101", "output": "4\n \n\nNone of 7, 77, and 777 is a multiple of 101, but 7777 is.\n\n* * *"}, {"input": "2", "output": "-1\n \n\nAll elements in the sequence are odd numbers; there are no multiples of 2.\n\n* * *"}, {"input": "999983", "output": "999982"}]
Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print `4`.) * * *
s992573432
Runtime Error
p02596
Input is given from Standard Input in the following format: K
k = int(input()) if k % 2 == 0: print(-1) exit() elif k == 1: print(1) exit() elif k == 11: print(2) exit() elif k == 101: print(4) exit() elif 1001 % k == 0: print(6) exit() elif 10001 % k == 0: print(8) exit() elif 100001 % k == 0: print(10) exit() elif 1000001 % k == 0: print(12) exit() elif 10000001 % k == 0: print(14) exit() elif 100000001 % k == 0: print(16) exit() elif 1000000001 % k == 0: print(18) exit() elif 10000000001 % k == 0: print(20) exit() k = int(input()) if k % 2 == 0: print(-1) exit() elif k == 1: print(1) exit() elif k == 11: print(2) exit() elif k == 101: print(4) exit() elif 1001 % k == 0: print(6) exit() elif 10001 % k == 0: print(8) exit() elif 100001 % k == 0: print(10) exit() elif 1000001 % k == 0: print(12) exit() elif 10000001 % k == 0: print(14) exit() elif 100000001 % k == 0: print(16) exit() elif 1000000001 % k == 0: print(18) exit() elif 10000000001 % k == 0: print(20) exit() elif 100000000001 % k == 0: print(22) exit() elif 1000000000001 % k == 0: print(24) exit() elif 10000000000001 % k == 0: print(26) exit() else: print(k - 1)
Statement Takahashi loves the number 7 and multiples of K. Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.) If the sequence contains no multiples of K, print `-1` instead.
[{"input": "101", "output": "4\n \n\nNone of 7, 77, and 777 is a multiple of 101, but 7777 is.\n\n* * *"}, {"input": "2", "output": "-1\n \n\nAll elements in the sequence are odd numbers; there are no multiples of 2.\n\n* * *"}, {"input": "999983", "output": "999982"}]
Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print `4`.) * * *
s628616377
Runtime Error
p02596
Input is given from Standard Input in the following format: K
N, Q = map(int, input().split()) list_c = [int(a) for a in input().split()] List = [list(map(int, input().split())) for x in range(Q)] for i in range(Q): l = List[i][0] r = List[i][1] list_c_new = list_c[l - 1 : r] set_list = set(list_c_new) print(len(set_list))
Statement Takahashi loves the number 7 and multiples of K. Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.) If the sequence contains no multiples of K, print `-1` instead.
[{"input": "101", "output": "4\n \n\nNone of 7, 77, and 777 is a multiple of 101, but 7777 is.\n\n* * *"}, {"input": "2", "output": "-1\n \n\nAll elements in the sequence are odd numbers; there are no multiples of 2.\n\n* * *"}, {"input": "999983", "output": "999982"}]
Print the minimum possible hamming distance. * * *
s284535835
Wrong Answer
p03554
Input is given from Standard Input in the following format: N b_1 b_2 ... b_N Q l_1 r_1 l_2 r_2 : l_Q r_Q
class segment_tree: def __init__(self, N, operator_M, e_M): self.op_M = operator_M self.e_M = e_M self.N0 = 1 << (N - 1).bit_length() self.dat = [self.e_M] * (2 * self.N0) # 長さNの配列 initial で初期化 def build(self, initial): self.dat[self.N0 : self.N0 + len(initial)] = initial[:] for k in range(self.N0 - 1, 0, -1): self.dat[k] = self.op_M(self.dat[2 * k], self.dat[2 * k + 1]) # a_k の値を x に更新 def update(self, k, x): k += self.N0 self.dat[k] = x k //= 2 while k: self.dat[k] = self.op_M(self.dat[2 * k], self.dat[2 * k + 1]) k //= 2 # 区間[L,R]をopでまとめる def query(self, L, R): L += self.N0 R += self.N0 + 1 sl = sr = self.e_M while L < R: if R & 1: R -= 1 sr = self.op_M(self.dat[R], sr) if L & 1: sl = self.op_M(sl, self.dat[L]) L += 1 L >>= 1 R >>= 1 return self.op_M(sl, sr) def get(self, k): # k番目の値を取得。query[k,k]と同じ return self.dat[k + self.N0] # coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline (n,) = map(int, readline().split()) (*b,) = [0] + [*map(int, readline().split())] (q,) = map(int, readline().split()) left = [[] for i in range(n + 1)] mp = map(int, read().split()) for l, r in zip(mp, mp): left[r].append(l) from itertools import accumulate one = list(accumulate(b)) """ dp[i] = i までみたスコア(同じなら1点)の最大値 """ dp = segment_tree(n + 1, max, 0) for i in range(1, n + 1): if left[i]: v = min(left[i]) res = max(one[i] - one[l - 1] + dp.query(0, l - 1) for l in left[i]) # 1にする res = max( res, (i - (v - 1)) - (one[i] - one[v - 1]) + dp.query(0, v - 1) ) # 0にする dp.update(i, res) else: res = (1 - b[i]) + dp.query(0, i - 1) dp.update(i, res) print(n - dp.get(n))
Statement You are given a sequence a = \\{a_1, ..., a_N\\} with all zeros, and a sequence b = \\{b_1, ..., b_N\\} consisting of 0 and 1. The length of both is N. You can perform Q kinds of operations. The i-th operation is as follows: * Replace each of a_{l_i}, a_{l_i + 1}, ..., a_{r_i} with 1. Minimize the hamming distance between a and b, that is, the number of i such that a_i \neq b_i, by performing some of the Q operations.
[{"input": "3\n 1 0 1\n 1\n 1 3", "output": "1\n \n\nIf you choose to perform the operation, a will become \\\\{1, 1, 1\\\\}, for a\nhamming distance of 1.\n\n* * *"}, {"input": "3\n 1 0 1\n 2\n 1 1\n 3 3", "output": "0\n \n\nIf both operations are performed, a will become \\\\{1, 0, 1\\\\}, for a hamming\ndistance of 0.\n\n* * *"}, {"input": "3\n 1 0 1\n 2\n 1 1\n 2 3", "output": "1\n \n\n* * *"}, {"input": "5\n 0 1 0 1 0\n 1\n 1 5", "output": "2\n \n\nIt may be optimal to perform no operation.\n\n* * *"}, {"input": "9\n 0 1 0 1 1 1 0 1 0\n 3\n 1 4\n 5 8\n 6 7", "output": "3\n \n\n* * *"}, {"input": "15\n 1 1 0 0 0 0 0 0 1 0 1 1 1 0 0\n 9\n 4 10\n 13 14\n 1 7\n 4 14\n 9 11\n 2 6\n 7 8\n 3 12\n 7 13", "output": "5\n \n\n* * *"}, {"input": "10\n 0 0 0 1 0 0 1 1 1 0\n 7\n 1 4\n 2 5\n 1 3\n 6 7\n 9 9\n 1 5\n 7 9", "output": "1"}]
Print the minimum possible hamming distance. * * *
s273031504
Wrong Answer
p03554
Input is given from Standard Input in the following format: N b_1 b_2 ... b_N Q l_1 r_1 l_2 r_2 : l_Q r_Q
import sys readline = sys.stdin.readline readlines = sys.stdin.readlines import itertools N = int(readline()) B = [int(x) for x in readline().split()] Q = int(readline()) LR = sorted( [tuple(int(x) for x in line.split()) for line in readlines()], key=lambda x: x[1] ) """ Rが手前のものから処理。その時点で、Bと一致できているセルの個数を最大化したい 代わりに、「「00000」から見た改善量」をdpとして持つ。 区間[L,R] を最後に使うとき、手前はdp[0,...,L-1]の最大値でとりたい。 よって、dpの区間maxをBITで管理すればよい """ # 1とおいたときの改善量 improve_cum = [0] + list(itertools.accumulate(2 * x - 1 for x in B)) def BIT_update(tree, i, x): while i <= N and tree[i] < x: tree[i] = x i += i & (-i) def BIT_max(tree, i): ret = 0 while i: if ret < tree[i]: ret = tree[i] i -= i & (-i) return ret dp = [0] * (N + 1) for L, R in LR: x = improve_cum[R] - improve_cum[L - 1] # 区間[L,R] での改善量 x += BIT_max(dp, L - 1) # [0,L-1]での改善量の最大値 BIT_update(dp, R, x) base_score = sum(B) answer = base_score - max(dp) print(answer)
Statement You are given a sequence a = \\{a_1, ..., a_N\\} with all zeros, and a sequence b = \\{b_1, ..., b_N\\} consisting of 0 and 1. The length of both is N. You can perform Q kinds of operations. The i-th operation is as follows: * Replace each of a_{l_i}, a_{l_i + 1}, ..., a_{r_i} with 1. Minimize the hamming distance between a and b, that is, the number of i such that a_i \neq b_i, by performing some of the Q operations.
[{"input": "3\n 1 0 1\n 1\n 1 3", "output": "1\n \n\nIf you choose to perform the operation, a will become \\\\{1, 1, 1\\\\}, for a\nhamming distance of 1.\n\n* * *"}, {"input": "3\n 1 0 1\n 2\n 1 1\n 3 3", "output": "0\n \n\nIf both operations are performed, a will become \\\\{1, 0, 1\\\\}, for a hamming\ndistance of 0.\n\n* * *"}, {"input": "3\n 1 0 1\n 2\n 1 1\n 2 3", "output": "1\n \n\n* * *"}, {"input": "5\n 0 1 0 1 0\n 1\n 1 5", "output": "2\n \n\nIt may be optimal to perform no operation.\n\n* * *"}, {"input": "9\n 0 1 0 1 1 1 0 1 0\n 3\n 1 4\n 5 8\n 6 7", "output": "3\n \n\n* * *"}, {"input": "15\n 1 1 0 0 0 0 0 0 1 0 1 1 1 0 0\n 9\n 4 10\n 13 14\n 1 7\n 4 14\n 9 11\n 2 6\n 7 8\n 3 12\n 7 13", "output": "5\n \n\n* * *"}, {"input": "10\n 0 0 0 1 0 0 1 1 1 0\n 7\n 1 4\n 2 5\n 1 3\n 6 7\n 9 9\n 1 5\n 7 9", "output": "1"}]
Print the minimum possible hamming distance. * * *
s687067480
Wrong Answer
p03554
Input is given from Standard Input in the following format: N b_1 b_2 ... b_N Q l_1 r_1 l_2 r_2 : l_Q r_Q
#!/usr/bin/env python3 # coding: utf-8 from sys import stdin def cost_gain(lr): global bs l, r = lr sb = bs[l - 1 : r] cost = sum(1 for b in sb if b == "0") gain = sum(1 for b in sb if b == "1") return cost, gain def key(lr): cost, gain = cost_gain(lr) return (cost, -gain, lr) def solve(lr): global bs dist = sum(1 for b in bs if b == "1") while True: lr.sort(key=key) cost, gain = cost_gain(lr[0]) if cost >= gain: break l, r = lr[0] for i in range(l - 1, r): bs[i] = "*" dist += cost - gain return dist N = int(stdin.readline()) bs = [w for w in stdin.readline().split()] Q = int(stdin.readline()) lr = [] for i in range(Q): l, r = [int(w) for w in stdin.readline().split()] lr.append((l, r)) if len(bs) != N: raise if len(lr) != Q: raise print(solve(lr))
Statement You are given a sequence a = \\{a_1, ..., a_N\\} with all zeros, and a sequence b = \\{b_1, ..., b_N\\} consisting of 0 and 1. The length of both is N. You can perform Q kinds of operations. The i-th operation is as follows: * Replace each of a_{l_i}, a_{l_i + 1}, ..., a_{r_i} with 1. Minimize the hamming distance between a and b, that is, the number of i such that a_i \neq b_i, by performing some of the Q operations.
[{"input": "3\n 1 0 1\n 1\n 1 3", "output": "1\n \n\nIf you choose to perform the operation, a will become \\\\{1, 1, 1\\\\}, for a\nhamming distance of 1.\n\n* * *"}, {"input": "3\n 1 0 1\n 2\n 1 1\n 3 3", "output": "0\n \n\nIf both operations are performed, a will become \\\\{1, 0, 1\\\\}, for a hamming\ndistance of 0.\n\n* * *"}, {"input": "3\n 1 0 1\n 2\n 1 1\n 2 3", "output": "1\n \n\n* * *"}, {"input": "5\n 0 1 0 1 0\n 1\n 1 5", "output": "2\n \n\nIt may be optimal to perform no operation.\n\n* * *"}, {"input": "9\n 0 1 0 1 1 1 0 1 0\n 3\n 1 4\n 5 8\n 6 7", "output": "3\n \n\n* * *"}, {"input": "15\n 1 1 0 0 0 0 0 0 1 0 1 1 1 0 0\n 9\n 4 10\n 13 14\n 1 7\n 4 14\n 9 11\n 2 6\n 7 8\n 3 12\n 7 13", "output": "5\n \n\n* * *"}, {"input": "10\n 0 0 0 1 0 0 1 1 1 0\n 7\n 1 4\n 2 5\n 1 3\n 6 7\n 9 9\n 1 5\n 7 9", "output": "1"}]
For each dataset, select two students with the smallest difference in their scores, and output in a line (the absolute value of) the difference.
s704211707
Accepted
p01093
The input consists of multiple datasets, each in the following format. _n_ _a_ 1 _a_ 2 … _a n_ A dataset consists of two lines. The number of students _n_ is given in the first line. _n_ is an integer satisfying 2 ≤ _n_ ≤ 1000\. The second line gives scores of _n_ students. _a i_ (1 ≤ _i_ ≤ _n_) is the score of the _i_ -th student, which is a non-negative integer not greater than 1,000,000. The end of the input is indicated by a line containing a zero. The sum of _n_ 's of all the datasets does not exceed 50,000.
def main(): while True: s_num = int(input()) if s_num == 0: return s_dat = input() s_dat = s_dat.split(" ") for j in range(len(s_dat)): s_dat[j] = int(s_dat[j]) s_dat.sort() answer = sa(s_dat) print(answer) def sa(array): min_dist = 1000000 + 1 for i in range(len(array) - 1): dist = array[i + 1] - array[i] if dist <= min_dist: min_dist = dist return min_dist main()
Selection of Participants of an Experiment Dr. Tsukuba has devised a new method of programming training. In order to evaluate the effectiveness of this method, he plans to carry out a control experiment. Having two students as the participants of the experiment, one of them will be trained under the conventional method and the other under his new method. Comparing the final scores of these two, he will be able to judge the effectiveness of his method. It is important to select two students having the closest possible scores, for making the comparison fair. He has a list of the scores of all students who can participate in the experiment. You are asked to write a program which selects two of them having the smallest difference in their scores.
[{"input": "10 10 10 10 10\n 5\n 1 5 8 9 11\n 7\n 11 34 83 47 59 29 70\n 0", "output": "1\n 5"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s018449869
Accepted
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
num = int(input()) val = 0 for i in input().split(): val += int(i) print("YES" if val % 2 == 0 else "NO")
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s210159326
Runtime Error
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
n = int(input().strip()) a = [int(x) for x in input().strip().split()] flg = [-1 for i in range(n)] b = [] l = [[] for i in range(n)] for i in range(n - 1): b.append([int(x) - 1 for x in input().strip().split()]) for x in b: l[x[0]].append(x[1]) l[x[1]].append(x[0]) while True: minimum = a[0] idx = [] for i, x in enumerate(a): if flg[i] != -1 or x > minimum: continue if x < minimum: minimum = x idx = [i] else: idx.append(i) while True: w = [] for i in idx: flg[i] = 0 for x in l[i]: if flg[x] == -1 and a[x] != a[i]: flg[x] = 1 w.append(x) idx = [] for i in w: for x in l[i]: if flg[x] == -1: flg[x] = 0 for y in l[x]: if flg[y] == -1 and a[x] > a[y]: flg[x] = -1 break if flg[x] == 0: idx.append(x) if len(idx) == 0: break if -1 not in flg: break sep = "" s = "" for i, x in enumerate(flg): if x == 1: s += sep + str(i + 1) sep = " " print(s)
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s303538674
Runtime Error
p03807
The 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()) if sum(A)%2: print("NO") else: print("YES")
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s340659862
Runtime Error
p03807
The 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())) cnt=0 for i in a: if i%2=1: cnt+=1 if cnt%2==1: print('NO') else: print('YES')
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s346658837
Runtime Error
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
N=int(input()) L=list(map(int,input().split())) count=0 for i in range N: if L[i]%2==1: count+=1 if count%2==1: print("NO") else: print("YES")
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s432386761
Runtime Error
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
N = int(input()) A = [int(i) for i in input().split()] c = 0 for a in A: if a % 2 = 1: c += 1 if c % 2 == 0: print('YES') else: print('NO')
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s653667029
Runtime Error
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
N=int(input()) A=[int(i) for i in input().split()] count=0 for i in A: if i%2==1: count+=1 if count%2==0: print("YES") else: print("NO)
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s507825896
Runtime Error
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
n=int(input()) odd=0 even=0 a=list(map(int,input().split())) for i in range(n): if a[i]%2=1: odd+=1 else: even+=1 if odd%2==1: print("NO") else: print("YES")
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s929810347
Runtime Error
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
N = int(input()) A = [int(n) for n in input().split()] cnt = 0 for in range(N): if A[i] % 2 == 1: cnt += 1 if cnt % 2 == 0: print ('YES') else: print('NO')
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s313397763
Runtime Error
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
_ = input() As = [int(x) for x in input().split()] even_pair_count = 0 odd_pair_count = 0 even_pair = [] odd_pair = [] for a in As: if a%2 == 0: even_pair.append(1) if len(even_pair) == 2: even_pair = [] even_pair_count += 1 else: odd_pair.append(1) if len(odd_pair) == 2: odd_pair = [] odd_pair_count += 1 pair_num = even_pair_count + odd_pair_count rest_num = len(even_pair) + len(odd_pair) # print(pair_num) # print(rest_num) elif rest_num == 2: print("NO") if pair_num == 1: print("YES") elif (pair_num+rest_num) % 2 == 0: print("YES") else: print("NO")
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s476409464
Runtime Error
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
a = int(input()) b = input().split() x = [] for i in b: x.append(int(i)) count = 0 for i in x: if i % 2 != 0: count += 1 flag = 0 while True: z = divmod(count,2) #print(z) if z[0] == 1: break if z[1] == 1: flag = 1 break count = z[0] if flag == 1: print("NO") else: print("YES")a = int(input()) b = input().split() x = [] for i in b: x.append(int(i)) count = 0 for i in x: if i % 2 != 0: count += 1 flag = 0 while True: z = divmod(count,2) #print(z) if z[0] == 1: break if z[1] == 1: flag = 1 break count = z[0] if flag == 1: print("NO") else: print("YES")
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s394043626
Runtime Error
p03807
The 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())) odd = len(list(filter(lambda x: x % 2 != 0, A))) even = N - odd ans = "YES" if odd == 1 and even == 0: odd = odd elif odd % 2 == 1: ans = "NO" else: even += odd//2 while True: if even == 1: if even % 2 == 1: ans = "NO" break even //= 2 print(ans)
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s719446520
Runtime Error
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
numInput = int(input()) amount = numInput numOdd = int(numInput / 2) + (numInput % 2) numEven 0 int(numInput / 2) while True: if amount >= 2: if numOdd >= 2: numOdd -= 2 numEven += 1 amount -= 1 else: numEven -= 1 amount -= 1 else: break if amount == 1: print('YES') else: print('NO')
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s993661634
Accepted
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
n, *lst = map(int, open(0).read().split()) print("NO" if sum(lst) % 2 else "YES")
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s329350363
Runtime Error
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
if (input() % 2) == 0 print ("NO") else print("YES")
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s779553680
Runtime Error
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
import sys if sum(for n in map(int, next(sys.stdin).split()) if n % 2 == 1) % 2 == 0: print('YES') else: print('NO')
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s561646327
Runtime Error
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
N = input() A = input().split() count=0 for i in range(N): if A[i]%2==1: count+=1 if conut%2=1: print("NO") else: print("YES")
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s101931306
Runtime Error
p03807
The 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())) s=0 for i in range(n): s+=1 if a[i]%2==1 print('YES' if s%2==0 else 'NO')
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s653553391
Runtime Error
p03807
The 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())) if len(a)%3 == 0 print("YES") else: print("NO")
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s355254605
Wrong Answer
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
print( sum( [ 1 if i % 2 == 1 else 0 for i in [int(input()) % 1] + list(map(int, input().split(" "))) ] ) )
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
If it is possible to have only one integer on the blackboard, print `YES`. Otherwise, print `NO`. * * *
s335692364
Wrong Answer
p03807
The input is given from Standard Input in the following format: N A_1 A_2 … A_N
f = lambda x: int(x) % 2 n = int(input()) a = list(map(f, input().split())).count(1) print(["YNEOS"][n > 1 and a % 2 > 0 :: 2])
Statement There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard.
[{"input": "3\n 1 2 3", "output": "YES\n \n\nIt is possible to have only one integer on the blackboard, as follows:\n\n * Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.\n * Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.\n\n* * *"}, {"input": "5\n 1 2 3 4 5", "output": "NO"}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s513344247
Accepted
p02715
Input is given from Standard Input in the following format: N K
import sys from math import gcd from functools import reduce input = sys.stdin.buffer.readline class FLT: def __init__(self, mod=10**9 + 7): self.mod = mod def rep_sqr(self, base, k): ans = 1 while k > 0: if k & 1: ans = ans * base % self.mod base = base * base % self.mod k >>= 1 return ans def inv(self, a): """逆元を取る""" return self.rep_sqr(a, self.mod - 2) def gcd_list(numbers): return reduce(gcd, numbers) def euler_phi(n): phi = n for i in set(prime_factorize(n)): phi *= 1 - (1 / i) return int(phi) def prime_factorize(n): # Return list of prime factorized result a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a n, k = map(int, input().split()) MOD = 10**9 + 7 flt = FLT(MOD) memo = [-1 for _ in range(k + 1)] ans = 0 for i in range(1, k + 1): d = k // i if memo[d] == -1: memo[d] = flt.rep_sqr(d, n) ans += memo[d] * euler_phi(i) print(ans % MOD)
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s200231156
Accepted
p02715
Input is given from Standard Input in the following format: N K
# coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline read = sys.stdin.read def Eratosthenes(N): # N以下の素数のリストを返す N += 1 is_prime_list = [True] * N m = int(N**0.5) + 1 for i in range(3, m, 2): if is_prime_list[i]: is_prime_list[i * i :: 2 * i] = [False] * ((N - i * i - 1) // (2 * i) + 1) return [2] + [i for i in range(3, N, 2) if is_prime_list[i]] # p,n,k,b,*a = [int(i) for i in read().split()] # k以下、長さn n, k = map(int, input().split()) MOD = 10**9 + 7 res = [0] + [pow(k // i, n, MOD) for i in range(1, k + 1)] p = Eratosthenes(k) # print(res) for i in p: for j in range(i, k + 1, i): res[j // i] -= res[j] # print(res) print(sum(ri * i for i, ri in enumerate(res)) % MOD)
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s200332376
Wrong Answer
p02715
Input is given from Standard Input in the following format: N K
Big = 10**9 + 7 _ = list(map(int, input().split(" "))) N = _[0] K = _[1] gcd_list = [0 for _ in range(K)] for i in range(K): s = K - i - 1 gcd_list[s] = ( pow(K // K - i, N, Big) - (sum(gcd_list[2 * s + 1 :: s + 1])) % Big ) % Big answer = [(x + 1) * gcd_list[x] % Big for x in range(K)] print(sum(answer) % Big)
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s124277843
Accepted
p02715
Input is given from Standard Input in the following format: N K
from collections import defaultdict import os from functools import reduce import itertools import sys from math import gcd if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10**9) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # MOD = 998244353 def get_factorials(max, mod=None): """ 階乗 0!, 1!, 2!, ..., max! :param int max: :param int mod: """ ret = [1] n = 1 if mod: for i in range(1, max + 1): n *= i n %= mod ret.append(n) else: for i in range(1, max + 1): n *= i ret.append(n) return ret def mod_invs(max, mod): """ 逆元 0, 1/1, 1/2, 1/3, ..., 1/max :param int max: :param int mod: """ invs = [1] * (max + 1) invs[0] = 0 for x in range(2, max + 1): invs[x] = (-(mod // x) * invs[mod % x]) % mod return invs def factorial_invs(max, mod): """ 階乗 0!, 1!, 2!, ..., max! の逆元 :param int max: :param int mod: """ ret = [1] r = 1 for inv in mod_invs(max, mod)[1:]: r = r * inv % mod ret.append(r) return ret class Combination: def __init__(self, max, mod): """ :param int max: :param int mod: 3 以上の素数であること """ self._factorials = get_factorials(max, mod) self._finvs = factorial_invs(max, mod) self._mod = mod def ncr(self, n, r): """ :param int n: :param int r: :rtype: int """ if n < r: return 0 return ( self._factorials[n] * self._finvs[r] % self._mod * self._finvs[n - r] % self._mod ) N, K = list(map(int, sys.stdin.buffer.readline().split())) def test(N, K): s = 0 counts = defaultdict(int) for nums in itertools.product(range(1, K + 1), repeat=N): s += reduce(gcd, nums) counts[reduce(gcd, nums)] += 1 print(counts) print(s % MOD) # test(N, K) # comb = Combination(max=N + K, mod=MOD) # @debug def count_patterns(n): # gcd の約数が n となるように選ぶ方法の数 return pow(K // n, N, MOD) counts = [0] * (K + 1) for n in range(1, K + 1): cnt = count_patterns(n) counts[n] = cnt for n in reversed(range(1, K + 1)): i = n * 2 while i <= K: counts[n] -= counts[i] i += n # print(counts) ans = 0 for n in range(1, K + 1): ans += n * counts[n] % MOD ans %= MOD print(ans)
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s391490622
Runtime Error
p02715
Input is given from Standard Input in the following format: N K
n = int(input()) arr = list(map(int, input().split())) if n % 2 == 0: tp = sum(arr[::2]) print(max(sum(arr) - tp, tp)) elif n == 3: print(arr[0] + arr[2]) else: hoge = -(10**12) buf = [[hoge for i in range(3)] for j in range(n)] buf[0][0] = arr[0] buf[1][1] = arr[1] buf[2][2] = arr[2] buf[2][0] = arr[0] + arr[2] for i in range(3, n): buf[i][0] = buf[i - 2][0] + arr[i] buf[i][1] = max(buf[i - 3][0] + arr[i], buf[i - 2][1] + arr[i]) if i >= 4: buf[i][2] = max( [buf[i - 3][1] + arr[i], buf[i - 4][0] + arr[i], buf[i - 2][2] + arr[i]] ) else: buf[i][2] = max([buf[i - 3][1] + arr[i], buf[i - 2][2] + arr[i]]) print(max(buf[-1][2], buf[-2][1], buf[-3][0]))
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s593210559
Accepted
p02715
Input is given from Standard Input in the following format: N K
N, K = map(int, input().split()) pr = 10**9 + 7 a = 0 l = [None] * (K + 1) for i in range(K, 0, -1): t = pow(K // i, N, pr) c = i * 2 while c <= K: t -= l[c] c += i l[i] = t a = (a + t * i) % pr print(a)
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s853072994
Runtime Error
p02715
Input is given from Standard Input in the following format: N K
def resolve(): n = int(input()) s = input() r = [0] * n g = [0] * n b = [0] * n for i in range(n): if s[i] == "R": r[i] = 1 elif s[i] == "G": g[i] = 1 else: b[i] = 1 ans = 0 a = [r, g, b] for i in range(n): if a[0][i] == 1: for j in range(i + 1, n): if a[1][j] == 1: ans += sum(a[2][j + 1 : n]) a = [r, b, g] for i in range(n): if a[0][i] == 1: for j in range(i + 1, n): if a[1][j] == 1: ans += sum(a[2][j + 1 : n]) a = [g, r, b] for i in range(n): if a[0][i] == 1: for j in range(i + 1, n): if a[1][j] == 1: ans += sum(a[2][j + 1 : n]) a = [g, b, r] for i in range(n): if a[0][i] == 1: for j in range(i + 1, n): if a[1][j] == 1: ans += sum(a[2][j + 1 : n]) a = [b, r, g] for i in range(n): if a[0][i] == 1: for j in range(i + 1, n): if a[1][j] == 1: ans += sum(a[2][j + 1 : n]) a = [b, g, r] for i in range(n): if a[0][i] == 1: for j in range(i + 1, n): if a[1][j] == 1: ans += sum(a[2][j + 1 : n]) for i in range(1, n // 2 + 1): j = 0 while j + 2 * i <= n - 1: if {s[j], s[j + i], s[j + 2 * i]} == {"R", "G", "B"}: ans -= 1 j += 1 print(ans) resolve()
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s429011212
Accepted
p02715
Input is given from Standard Input in the following format: N K
MOD = 10**9 + 7 e, N = map(int, input().split()) def phi_table(N): phi = list(range(N + 1)) for p in range(2, N + 1): if phi[p] == p: for n in range(N // p, 0, -1): phi[p * n] -= phi[n] return phi L = int(N**0.66) H = int(N // (L + 1)) phi = phi_table(L) # f(n) = \sum_{i=1}^n phi(i) f_l = phi.copy() for n in range(L): f_l[n + 1] += f_l[n] f_h = [0] * (H + 1) # f(N//d) def f(n): return f_l[n] if n <= L else f_h[N // n] def compute_f(n): sq = int(n**0.5) x = n * (n + 1) // 2 for d in range(1, n + 1): m = n // d if m <= sq: break x -= f(m) for m in range(1, sq + 1): cnt = n // m - n // (m + 1) x -= f_l[m] * cnt return x for d in range(H, 0, -1): f_h[d] = compute_f(N // d) sq = int(N**0.5) answer = 0 for d in range(1, N + 1): n = N // d if n <= sq: break answer += pow(n, e, MOD) * phi[d] for n in range(1, sq + 1): low_d = N // (n + 1) high_d = N // n phi_sum = f(high_d) - f(low_d) answer += phi_sum * pow(n, e, MOD) answer %= MOD print(answer)
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s642463416
Accepted
p02715
Input is given from Standard Input in the following format: N K
n, k = map(int, input().split()) count_list = [0 for _ in range(k)] for num in reversed(range(1, k + 1)): # count = (k//num)**n count = pow(k // num, n, 1000000007) count_list[num - 1] = count for num in reversed(range(1, k + 1)): if k // num >= 2: for i in range(2, k // num + 1): count_list[num - 1] -= count_list[num * i - 1] score = 0 for idx, val in enumerate(count_list): score += (idx + 1) * val print(score % 1000000007)
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s482714182
Accepted
p02715
Input is given from Standard Input in the following format: N K
# E N, K = map(int, input().split()) MOD = 10**9 + 7 # e.g. # N=3,K=4 # gcd(A)=4 -> (4,4,4)=1**3=1 # gcd(A)=3 -> (3,3,3)=1**3=1 # gcd(A)=2 -> (2or4,2or4,2or4)-(4,4,4)=2**3-1**3=7 # gcd(A)=1 -> (1~4,1~4,1~4)-上全部=4**3-(2**3-1**3)-1**3-1**3=55 # and=1*4+1*3+7*2+55*1=76 # # gcd(A)=xとなるAをx=K,K-1,...,1として数えていく。 # A=(x or 2x or 3x or ...,x or 2x or 3x or ...,...)という形をしているが # 2x,3x,...がK以下ならxより大きい場合で既にカウントしてしまっている # (gcd(2x,2x)=2xをgcd(2x,2x)=xとして数えてしまっている) # ->2x,3xについてカウント済みならそれを引けばいい: Kから数えればいい ans = 0 # 出力する答え GCD = [0 for _ in range(K + 1)] # GCD[i]:gcd(A)=iとなるAの総数 for x in range(K, 0, -1): # gcd(A)=xとなるAを各xで数える Ai_cnt = K // x # 各Aiについてとりうる値の総数(x,2x,3x,...<=K) rep = 0 # 既にカウント済みなものをここに数えてまとめておく # 既にカウント済みがあるか数える check = 2 * x while check <= K: # これを満たすならK以下である rep += GCD[check] # 満たしたのでrepに足す check += x # 次のxの倍数について調べるために足す # repができたのでGCD[i]に記録 GCD[x] = pow(Ai_cnt, N, MOD) - rep # 繰り返し2乗法: O(logN) # kについては完成したので,ansに足す ans += x * (GCD[x]) ans %= MOD # 出力する前に計算量の確認 # 計算量はおよそ各xでK//x回の計算とpowが必要なので # sum(log(N)+K//x x:1toK) # <=K*(log_2(N)+sum(1/x 1toK)) # ~ K*(log_2(N)+log_e(K)) # < (10**5)*(2*log_2(10**5)) # < 4*10**6 # よってギリ間に合うと思われる print(ans)
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s079855622
Wrong Answer
p02715
Input is given from Standard Input in the following format: N K
from itertools import combinations def gcd(x, y): if y == 0: return x return gcd(y, x % y) def gcdn(l: list): if len(l) == 2: return gcd(*l) g = gcd(l[0], l[1]) for li in l[2:]: g = gcd(g, li) return g n, k = map(int, input().split()) comb = list(combinations(range(1, k + 1), n)) print(comb) cnt = 0 for l in comb: unq = len(list(set(l))) cnt += (gcdn(l) * k ** (unq - 1)) % (10**9 + 7) print(cnt)
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s240346142
Accepted
p02715
Input is given from Standard Input in the following format: N K
n, k = map(int, input().split()) MOD = 10**9 + 7 class mint: def __init__(self, i): self.i = i def __add__(self, m): t = self.i + (m.i if isinstance(m, mint) else m) if t > MOD: t -= MOD return mint(t) def __radd__(self, m): t = self.i + (m.i if isinstance(m, mint) else m) if t > MOD: t -= MOD return mint(t) def __mul__(self, m): return mint(self.i * m.i % MOD) def __sub__(self, m): t = self.i - m.i if t < 0: t += MOD return mint(t) def __pow__(self, m): i = self.i res = 1 while m > 0: if m & 1: res = res * i % MOD i = i * i % MOD m >>= 1 return mint(res) def __truediv__(self, m): return mint(self.i * m ** (MOD - 2) % MOD) def __repr__(self): return repr(self.i) l = [mint(0) for _ in range(k + 1)] for x in range(k, 0, -1): count = mint(k // x) ** n for tx in range(x + x, k + 1, x): count -= l[tx] l[x] = count ans = sum(mint(i) * x for i, x in enumerate(l)) print(ans)
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s346846999
Wrong Answer
p02715
Input is given from Standard Input in the following format: N K
mod = 10**9 + 7 N, K = map(int, input().split()) Ans = [1 for k in range(K)] c = K for j in range(N): Ans[0] = Ans[0] * (K) % mod for k in range(2, (K + 1) // 2 + 1): d = K // k if c == d: Ans[k - 1] = Ans[k - 2] else: for j in range(N): Ans[k - 1] = Ans[k - 1] * d % mod c = d print(Ans) for j in range(K, 1, -1): for l in range(j // 2, 0, -1): if j % l == 0: Ans[l - 1] -= Ans[j - 1] for j in range(K): Ans[j] *= j + 1 print(sum(Ans) % mod)
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7). * * *
s234324586
Accepted
p02715
Input is given from Standard Input in the following format: N K
N, K = [int(n) for n in input().split()] NUM = 1000000007 def modpow(a, b): # (a ** b) % NUM ans = 1 while b != 0: if b % 2 == 1: ans *= a ans %= NUM a = a * a a %= NUM b //= 2 return ans C = [0 for _ in range(K + 1)] for d in range(K): k = K - d # K ... 1 L = K // k C[k] = modpow(L, N) # A = 1*k ... L*k for l in range(2, L + 1): C[k] -= C[l * k] if C[k] < 0: C[k] += NUM C[k] %= NUM ans = 0 for k in range(1, K + 1): ans += k * C[k] ans %= NUM print(ans)
Statement Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
[{"input": "3 2", "output": "9\n \n\n\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2) =1+1+1+1+1+1+1+2=9\n\nThus, the answer is 9.\n\n* * *"}, {"input": "3 200", "output": "10813692\n \n\n* * *"}, {"input": "100000 100000", "output": "742202979\n \n\nBe sure to print the sum modulo (10^9+7)."}]
For each dataset, a line containing a single decimal integer indicating the score for the corresponding performance should be output. No other characters should be on the output line.
s424051353
Accepted
p00728
The input consists of a number of datasets, each corresponding to a contestant's performance. There are no more than 20 datasets in the input. A dataset begins with a line with an integer _n_ , the number of judges participated in scoring the performance (3 ≤ _n_ ≤ 100). Each of the _n_ lines following it has an integral score _s_ (0 ≤ _s_ ≤ 1000) marked by a judge. No other characters except for digits to express these numbers are in the input. Judges' names are kept secret. The end of the input is indicated by a line with a single zero in it.
a = int(input()) while a != 0: M = 0 m = 1000 sam = 0 for i in range(a): b = int(input()) sam += b M = max(M, b) m = min(m, b) print(int((sam - M - m) / (a - 2))) a = int(input())
A: ICPC Score Totalizer Software ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_a-1) The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business. One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance. Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer. You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.
[{"input": "1000\n 342\n 0\n 5\n 2\n 2\n 9\n 11\n 932\n 5\n 300\n 1000\n 0\n 200\n 400\n 8\n 353\n 242\n 402\n 274\n 283\n 132\n 402\n 523\n 0", "output": "7\n 300\n 326"}]
For each dataset, a line containing a single decimal integer indicating the score for the corresponding performance should be output. No other characters should be on the output line.
s771687915
Accepted
p00728
The input consists of a number of datasets, each corresponding to a contestant's performance. There are no more than 20 datasets in the input. A dataset begins with a line with an integer _n_ , the number of judges participated in scoring the performance (3 ≤ _n_ ≤ 100). Each of the _n_ lines following it has an integral score _s_ (0 ≤ _s_ ≤ 1000) marked by a judge. No other characters except for digits to express these numbers are in the input. Judges' names are kept secret. The end of the input is indicated by a line with a single zero in it.
# your code goes here n = int(input()) while n != 0: s = int(input()) x = s m = s for i in range(n - 1): # n-2?:? p = int(input()) if m > p: # s+=m m = p elif x < p: # s+=x x = p # else: s += p # print (s) s -= x s -= m s /= n - 2 print(int(s)) n = int(input())
A: ICPC Score Totalizer Software ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_a-1) The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business. One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance. Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer. You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.
[{"input": "1000\n 342\n 0\n 5\n 2\n 2\n 9\n 11\n 932\n 5\n 300\n 1000\n 0\n 200\n 400\n 8\n 353\n 242\n 402\n 274\n 283\n 132\n 402\n 523\n 0", "output": "7\n 300\n 326"}]
For each dataset, a line containing a single decimal integer indicating the score for the corresponding performance should be output. No other characters should be on the output line.
s567953499
Accepted
p00728
The input consists of a number of datasets, each corresponding to a contestant's performance. There are no more than 20 datasets in the input. A dataset begins with a line with an integer _n_ , the number of judges participated in scoring the performance (3 ≤ _n_ ≤ 100). Each of the _n_ lines following it has an integral score _s_ (0 ≤ _s_ ≤ 1000) marked by a judge. No other characters except for digits to express these numbers are in the input. Judges' names are kept secret. The end of the input is indicated by a line with a single zero in it.
while True: # 無限に繰り返す num = int(input()) # 標準入力 if num == 0: break # 入力値が0だった場合繰り返しを強制終了する else: # 0でなければ num_list = [] # 空リスト作成 for _ in range(num): # 入力回繰り返す num_list.append(int(input())) # 標準入力をし、リストに加える num_list.sort() # リストを小さい順に並べる num_list.pop(-1) # リストの最高点を削除する num_list.pop(0) # リストの最低点を削除する num = sum(num_list) # リストの値を合計する num1 = len(num_list) # リストの長さを取得する print(int(num / num1)) # リストの平均を出力する
A: ICPC Score Totalizer Software ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_a-1) The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business. One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance. Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer. You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.
[{"input": "1000\n 342\n 0\n 5\n 2\n 2\n 9\n 11\n 932\n 5\n 300\n 1000\n 0\n 200\n 400\n 8\n 353\n 242\n 402\n 274\n 283\n 132\n 402\n 523\n 0", "output": "7\n 300\n 326"}]
For each find operation, print the minimum element.
s856630698
Accepted
p02345
n q com0 x0 y0 com1 x1 y1 ... comq−1 xq−1 yq−1 In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
from collections import deque def pow_two_more_than(a): # print(a, a & (a - 1), bin(a), 1 << (len(bin(a))-2)) if (a & (a - 1)) == 0: return a # print(1 << (len(bin(a))-2)) return 1 << (len(bin(a)) - 2) class SegmentTree: def __init__(self, n, l): self.n = pow_two_more_than(n) self.tree = [2**31 - 1] * self.n + l + [2**31 - 1] * (self.n - len(l)) for i in reversed(range(1, self.n)): self.update_one_node(i) def update(self, index, m): x = self.n + index self.tree[x] = m while x >= 1: x //= 2 self.update_one_node(x) # print(self.tree) def find(self, rl, rr): # print(f"find: [{rl}, {rr})") # print(self.tree[self.n:]) min_num = 2**31 - 1 q = deque([1]) c = 0 while q: # print(q) t = q.popleft() # print(t) height = len(bin(t)) - 3 x = t ^ (1 << height) w = self.n >> height l, r = w * x, w * (x + 1) # print((l, r), height, end=" ") if rl <= l and r <= rr: # print("complatly in") min_num = min(min_num, self.tree[t]) elif r <= rl or rr <= l: pass # print("out") else: # print((l, r), (rl, rr)) # print("overlap") for c in self.get_childs(t): if c < self.n * 2: q.append(c) c += 1 # print(c) return min_num def update_one_node(self, m): self.tree[m] = min(self.tree[c] for c in self.get_childs(m)) # def update(self) def get_childs(self, m): return [2 * m, 2 * m + 1] N, Q = map(int, input().split()) CXY = [list(map(int, input().split())) for _ in range(Q)] # N, Q = 10**5, 10**5 # CXY = [[0, i, i] for i in range(Q//2)] + [[1, 0, 0] for i in range(Q-Q//2)] segtree = SegmentTree(N, [2**31 - 1] * N) for c, x, y in CXY: if c == 0: segtree.update(x, y) else: x, y = x, y + 1 r = segtree.find(x, y) print(r)
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations: * find(s, t): report the minimum element in as, as+1, . . . ,at. * update(i, x): change ai to x. Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
[{"input": "3 5\n 0 0 1\n 0 1 2\n 0 2 3\n 1 0 2\n 1 1 2", "output": "1\n 2"}, {"input": "1 3\n 1 0 0\n 0 0 5\n 1 0 0", "output": "2147483647\n 5"}]
For each find operation, print the minimum element.
s763546604
Accepted
p02345
n q com0 x0 y0 com1 x1 y1 ... comq−1 xq−1 yq−1 In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
class SegmentTreeRMQ: """Range Minimum Query""" def __init__(self, lst, max_num=float("inf")): """ Args: lst: 元のリスト max_num: セグ木の各ノードの初期値 """ self.MAX_NUM = max_num # セグ木のノードの最大値 N = len(lst) i, total = 1, 1 while True: if N <= i: break i *= 2 total += i self.N = i # セグ木の葉の数 self.nodes = [self.MAX_NUM for _ in range(total)] for i in range(len(lst)): self.update(i, lst[i]) def update(self, i, x): """元のリストlst[i]に対応するセグ木のノード値をxに変更し、セグ木全体を更新する""" ni = self._lst2node(i) self.nodes[ni] = x while ni > 0: ni = (ni - 1) // 2 l, r = ni * 2 + 1, ni * 2 + 2 self.nodes[ni] = min(self.nodes[l], self.nodes[r]) def query(self, a, b): """区間[a,b)のクエリに応答する""" return self._find(a, b, 0, 0, self.N) def _lst2node(self, i): """元の配列lst[i]は、セグ木のi+N-1番目のノード(Nは歯の数)""" return i + self.N - 1 def _find(self, a, b, k, l, r): """区間[a,b)のクエリに対して、担当区間[l,r)のノードkが応答する""" if r <= a or b <= l: # 区間がかぶらない場合 return self.MAX_NUM if a <= l and r <= b: # 担当区間がすっぽり含まれる場合 return self.nodes[k] # それ以外 ret1 = self._find(a, b, 2 * k + 1, l, (l + r) // 2) # 左の子に聞く ret2 = self._find(a, b, 2 * k + 2, (l + r) // 2, r) # 右の子に聞く return min(ret1, ret2) N, Q = map(int, input().split()) lst = [2**31 - 1 for _ in range(N)] rmq = SegmentTreeRMQ(lst, 2**31 - 1) for q in range(Q): com, x, y = map(int, input().split()) if com == 0: rmq.update(x, y) else: print(rmq.query(x, y + 1))
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations: * find(s, t): report the minimum element in as, as+1, . . . ,at. * update(i, x): change ai to x. Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
[{"input": "3 5\n 0 0 1\n 0 1 2\n 0 2 3\n 1 0 2\n 1 1 2", "output": "1\n 2"}, {"input": "1 3\n 1 0 0\n 0 0 5\n 1 0 0", "output": "2147483647\n 5"}]
For each find operation, print the minimum element.
s145720447
Accepted
p02345
n q com0 x0 y0 com1 x1 y1 ... comq−1 xq−1 yq−1 In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
class segtree: def __init__(self, initArr, segfunc, idele): n = len(initArr) stn = 2 ** ((n - 1).bit_length() + 1) - 1 arr = [idele for i in range(stn)] arr[stn // 2 : stn // 2 + n] = initArr for i in range(stn - 1, 1, -2): arr[(i - 1) // 2] = segfunc(arr[i - 1], arr[i]) self.arr = arr self.segfunc = segfunc self.idele = idele def update(self, idx, val): idx += len(self.arr) // 2 self.arr[idx] = val while idx > 0: idx = (idx - 1) // 2 self.arr[idx] = self.segfunc(self.arr[idx * 2 + 1], self.arr[idx * 2 + 2]) return None def query(self, x, y, i=0, l=0, r=-1): # [x, y)の半開区間を探索 if r < 0: r = len(self.arr) // 2 + 1 if r <= x or y <= l: return self.idele if x <= l and r <= y: return self.arr[i] return self.segfunc( self.query(x, y, 2 * i + 1, l, (l + r) // 2), self.query(x, y, 2 * i + 2, (l + r) // 2, r), ) N, Q = map(int, input().split()) st = segtree(list([2**31 - 1] * N), min, 2**31 - 1) for q in range(Q): com, x, y = map(int, input().split()) if com: print(st.query(x, y + 1)) else: st.update(x, y)
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations: * find(s, t): report the minimum element in as, as+1, . . . ,at. * update(i, x): change ai to x. Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
[{"input": "3 5\n 0 0 1\n 0 1 2\n 0 2 3\n 1 0 2\n 1 1 2", "output": "1\n 2"}, {"input": "1 3\n 1 0 0\n 0 0 5\n 1 0 0", "output": "2147483647\n 5"}]
For each find operation, print the minimum element.
s358294946
Accepted
p02345
n q com0 x0 y0 com1 x1 y1 ... comq−1 xq−1 yq−1 In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
import operator class SegmentTree: # http://tsutaj.hatenablog.com/entry/2017/03/29/204841 def __init__(self, size, fn=operator.add, default=0): """ :param int size: :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など """ # size 以上である最小の 2 冪 n = 1 while n < size: n *= 2 self._size = n self._tree = [default for _ in range(self._size * 2 - 1)] self._fn = fn def set(self, i, value): """ i 番目に value を設定 :param int i: :param int value: :return: """ x = self._size - 1 + i self._tree[x] = value while x > 0: x = (x - 1) // 2 self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2]) def add(self, i, value): """ もとの i 番目と value に fn を適用したものを i 番目に設定 :param int i: :param int value: :return: """ x = self._size - 1 + i self.set(i, self._fn(self._tree[x], value)) def get(self, from_i, to_i, k=0, L=None, r=None): """ [from_i, to_i) に fn を適用した結果を返す :param int from_i: :param int to_i: :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ :param int L: :param int r: :return: """ L = 0 if L is None else L r = self._size if r is None else r if from_i <= L and r <= to_i: return self._tree[k] if to_i <= L or r <= from_i: return None ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2) ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r) if ret_L is None: return ret_r if ret_r is None: return ret_L return self._fn(ret_L, ret_r) def __len__(self): return self._size N, Q = list(map(int, input().split())) com, X, Y = zip(*[input().split() for _ in range(Q)]) X = list(map(int, X)) Y = list(map(int, Y)) if __name__ == "__main__": st = SegmentTree(size=N + 1, fn=min, default=2**31 - 1) for c, x, y in zip(com, X, Y): if c == "0": st.set(x, y) if c == "1": print(st.get(x, y + 1))
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations: * find(s, t): report the minimum element in as, as+1, . . . ,at. * update(i, x): change ai to x. Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
[{"input": "3 5\n 0 0 1\n 0 1 2\n 0 2 3\n 1 0 2\n 1 1 2", "output": "1\n 2"}, {"input": "1 3\n 1 0 0\n 0 0 5\n 1 0 0", "output": "2147483647\n 5"}]
For each find operation, print the minimum element.
s350066022
Accepted
p02345
n q com0 x0 y0 com1 x1 y1 ... comq−1 xq−1 yq−1 In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
import sys input = sys.stdin.readline class SegmentTree: # リストからセグメントツリーを構成 def __init__(self, list_, ide_ele=0): tmp = 1 while tmp < len(list_): tmp *= 2 self.n = tmp self.l = [ide_ele] * (2 * self.n - 1) self.ide_ele = ide_ele self.init_val(list_) def func(self, x, y): return min(x, y) def init_val(self, list_): # list_の値で葉を埋める for i, val in enumerate(list_): self.l[self.n - 1 + i] = val # 下の段から初期値を埋めていく for i in range(self.n - 2, -1, -1): self.l[i] = self.func(self.l[i * 2 + 1], self.l[i * 2 + 2]) # i番目をvalで更新 def update(self, i, val): i = self.n - 1 + i self.l[i] = val while i > 0: i = (i - 1) // 2 self.l[i] = self.func(self.l[i * 2 + 1], self.l[i * 2 + 2]) # [a, b)の最小値を返す. l, rはノードkに対応した区間 def query(self, a, b, k, l, r): if r <= a or b <= l: # 存在しない区間を参照 return self.ide_ele # エラーを返す if a <= l and r <= b: # 区間を完全に含む return self.l[k] vl = self.query(a, b, k * 2 + 1, l, (l + r) // 2) vr = self.query(a, b, k * 2 + 2, (l + r) // 2, r) return self.func(vl, vr) def main(): N, Q = map(int, input().split()) tmp = (1 << 31) - 1 seg = SegmentTree([tmp] * N, ide_ele=tmp) # print("init") # print(seg.l) for i in range(Q): c, x, y = map(int, input().split()) if c == 0: # print("update: l[{}]={} -> {}".format(x, seg.l[x], y)) seg.update(x, y) else: # print("min: {}~{}".format(x, y)) print(seg.query(x, y + 1, 0, 0, seg.n)) # print(seg.l) if __name__ == "__main__": main()
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations: * find(s, t): report the minimum element in as, as+1, . . . ,at. * update(i, x): change ai to x. Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
[{"input": "3 5\n 0 0 1\n 0 1 2\n 0 2 3\n 1 0 2\n 1 1 2", "output": "1\n 2"}, {"input": "1 3\n 1 0 0\n 0 0 5\n 1 0 0", "output": "2147483647\n 5"}]
For each find operation, print the minimum element.
s194147136
Accepted
p02345
n q com0 x0 y0 com1 x1 y1 ... comq−1 xq−1 yq−1 In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x) - 1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) class SegmentTree: def __init__(self, func, arr, default): self.func = func self.arr = arr self.default = default self.arrlen = len(self.arr) self.bitlen = (len(self.arr) - 1).bit_length() + 1 self.bottomlen = pow(2, self.bitlen - 1) self.bottomst = pow(2, self.bitlen - 1) - 1 self.segtree = [self.default] * (2 * self.bottomlen - 1) self.segtree[self.bottomst : self.bottomst + self.arrlen] = self.arr for idx in range(self.bottomst - 1, -1, -1): self.segtree[idx] = self.func( self.segtree[2 * idx + 1], self.segtree[2 * idx + 2] ) # idx番目の値をxに変更(0-indexed) def update(self, idx: int, x: int): idx += self.bottomst self.segtree[idx] = x while idx > 0: idx = (idx - 1) // 2 self.segtree[idx] = self.func( self.segtree[2 * idx + 1], self.segtree[2 * idx + 2] ) # [a,b) の値を取得(0-indexed) def query(self, a: int, b: int, idx: int, l: int, r: int): if r <= a or b <= l: return self.default elif a <= l and r <= b: return self.segtree[idx] else: return self.func( self.query(a, b, 2 * idx + 1, l, (l + r) // 2), self.query(a, b, 2 * idx + 2, (l + r) // 2, r), ) # リセット def reset(self): self.segtree = [self.default] * (2 * self.bottomlen - 1) self.segtree[self.bottomst : self.bottomst + self.arrlen] = self.arr for idx in range(self.bottomst - 1, -1, -1): self.segtree[idx] = self.func( self.segtree[2 * idx + 1], self.segtree[2 * idx + 2] ) n, q = li() default = pow(2, 31) - 1 arr = [default] * n segtree = SegmentTree(min, arr, default) nbit = pow(2, (n - 1).bit_length()) for _ in range(q): command, a, b = li() if command == 0: segtree.update(a, b) elif command == 1: print(segtree.query(a, b + 1, 0, 0, nbit))
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations: * find(s, t): report the minimum element in as, as+1, . . . ,at. * update(i, x): change ai to x. Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
[{"input": "3 5\n 0 0 1\n 0 1 2\n 0 2 3\n 1 0 2\n 1 1 2", "output": "1\n 2"}, {"input": "1 3\n 1 0 0\n 0 0 5\n 1 0 0", "output": "2147483647\n 5"}]
For each find operation, print the minimum element.
s022541281
Runtime Error
p02345
n q com0 x0 y0 com1 x1 y1 ... comq−1 xq−1 yq−1 In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
import numpy as np n,q = map(int, input().split()) A = np.array([None] * n) for i in range(q): c,x,y = map(int,input().split()) if c == 0: A[x] = y else: a = np.min(A[x:y+1]) if a is None: a = "2147483647" else: a = str(a) print(a)
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations: * find(s, t): report the minimum element in as, as+1, . . . ,at. * update(i, x): change ai to x. Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
[{"input": "3 5\n 0 0 1\n 0 1 2\n 0 2 3\n 1 0 2\n 1 1 2", "output": "1\n 2"}, {"input": "1 3\n 1 0 0\n 0 0 5\n 1 0 0", "output": "2147483647\n 5"}]
For each find operation, print the minimum element.
s004905034
Wrong Answer
p02345
n q com0 x0 y0 com1 x1 y1 ... comq−1 xq−1 yq−1 In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations: * find(s, t): report the minimum element in as, as+1, . . . ,at. * update(i, x): change ai to x. Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
[{"input": "3 5\n 0 0 1\n 0 1 2\n 0 2 3\n 1 0 2\n 1 1 2", "output": "1\n 2"}, {"input": "1 3\n 1 0 0\n 0 0 5\n 1 0 0", "output": "2147483647\n 5"}]
For each find operation, print the minimum element.
s370683574
Accepted
p02345
n q com0 x0 y0 com1 x1 y1 ... comq−1 xq−1 yq−1 In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
# https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_A import sys input = sys.stdin.readline n, q = map(int, input().split()) class RMQ: def __init__(self, n, e): # 単位元 self.e = e # num_min:n以上の最小の2のべき乗 self.num_min = 2 ** (n - 1).bit_length() self.seg_min = [self.e] * 2 * self.num_min def init_min(self, init_min_val): # 初期値が指定されている場合 # set_val for i in range(n): self.seg_min[i + self.num_min - 1] = init_min_val[i] # built for i in range(self.num_min - 2, -1, -1): self.seg_min[i] = min(self.seg_min[2 * i + 1], self.seg_min[2 * i + 2]) def update_min(self, k, x): k += self.num_min - 1 self.seg_min[k] = x while k: k = (k - 1) // 2 self.seg_min[k] = min(self.seg_min[k * 2 + 1], self.seg_min[k * 2 + 2]) def query_min(self, p, q): q += 1 if q <= p: return self.e p += self.num_min - 1 q += self.num_min - 2 res = self.e while q - p > 1: if p & 1 == 0: res = min(res, self.seg_min[p]) if q & 1 == 1: res = min(res, self.seg_min[q]) q -= 1 p = p // 2 q = (q - 1) // 2 if p == q: res = min(res, self.seg_min[p]) else: res = min(min(res, self.seg_min[p]), self.seg_min[q]) return res e = (2**31) - 1 rmq = RMQ(n, e) for i in range(q): com, x, y = map(int, input().split()) if com == 0: rmq.update_min(x, y) else: ans = rmq.query_min(x, y) print(ans)
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations: * find(s, t): report the minimum element in as, as+1, . . . ,at. * update(i, x): change ai to x. Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
[{"input": "3 5\n 0 0 1\n 0 1 2\n 0 2 3\n 1 0 2\n 1 1 2", "output": "1\n 2"}, {"input": "1 3\n 1 0 0\n 0 0 5\n 1 0 0", "output": "2147483647\n 5"}]
For each find operation, print the minimum element.
s899057939
Accepted
p02345
n q com0 x0 y0 com1 x1 y1 ... comq−1 xq−1 yq−1 In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
import sys input = sys.stdin.readline class ABSsegtree: # 必要な配列の長さN,単位元ie,関数(2項演算)func,を渡す def __init__(self, N, ie, func): self.func = func self.getLEN = 1 # Length of list while self.getLEN < N: self.getLEN *= 2 self.getsize = self.getLEN * 2 # =len(ST) self.getLIN = self.getsize - self.getLEN # internal nodes without ST[0] self.ST = [ie] * self.getsize def update(self, i, x): # i(0-index)にxをいれる i += self.getLIN self.ST[i] = x while i > 1: i //= 2 self.ST[i] = self.func(self.ST[2 * i], self.ST[2 * i + 1]) def get_interval(self, a, b): # [a,b)での最小値を求めたい a += self.getLIN b += self.getLIN ret = self.func(self.ST[a], self.ST[b - 1]) while a + 1 < b: # 階層ごとに見る if a % 2 == 1: ret = self.func(self.ST[a], ret) a += 1 a //= 2 if b % 2 == 1: ret = self.func(self.ST[b - 1], ret) b //= 2 if a == b: pass else: ret = self.func(ret, self.ST[a]) return ret N, Q = map(int, input().split()) ins = ABSsegtree(N, pow(2, 31) - 1, min) for _ in range(Q): P, X, Y = map(int, input().split()) if P == 0: ins.update(X, Y) else: print(ins.get_interval(X, Y + 1))
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations: * find(s, t): report the minimum element in as, as+1, . . . ,at. * update(i, x): change ai to x. Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
[{"input": "3 5\n 0 0 1\n 0 1 2\n 0 2 3\n 1 0 2\n 1 1 2", "output": "1\n 2"}, {"input": "1 3\n 1 0 0\n 0 0 5\n 1 0 0", "output": "2147483647\n 5"}]
Output the total price.
s815014118
Accepted
p00378
The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters.
import math A, B, X = map(int, input().split()) ans = float("inf") for a in range(math.ceil(X / 1000) + 1): if X - 1000 * a < 0: b = 0 else: b = math.ceil((X - 1000 * a) / 500) ans = min(ans, A * a + B * b) print(ans)
Heat Stroke We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required.
[{"input": "180 100 2400", "output": "460"}, {"input": "200 90 2018", "output": "450"}]
Output the total price.
s729636761
Accepted
p00378
The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters.
A, B, X = map(int, input().split()) A = min(A, B * 2) B = min(A, B) n = -(-X // 500) print(n // 2 * A + n % 2 * B)
Heat Stroke We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required.
[{"input": "180 100 2400", "output": "460"}, {"input": "200 90 2018", "output": "450"}]
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point. The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
s066146328
Wrong Answer
p00682
The input contains multiple data sets, each representing a polygon. A data set is given in the following format. n x1 y1 x2 y2 ... xn yn The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them. The end of input is indicated by a data set with 0 as the value of n.
while 1: n = int(input()) if n == 0: break p = [complex(*map(int, input().split())) for _ in range(n)] s, pre = 0, p[0] while p: now = p.pop() s += now.real * pre.imag - now.imag * pre.real pre = now print(abs(s) / 2) input()
Area of Polygons Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons. Your job in this problem is to write a program that computes the area of polygons. A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon. You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking. * No point will occur as a vertex more than once. * Two sides can intersect only at a common endpoint (vertex). * The polygon has at least 3 vertices. Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
[{"input": "1 1\n 3 4\n 6 0\n \n 7\n 0 0\n 10 10\n 0 20\n 10 30\n 0 40\n 100 40\n 100 0\n \n 0", "output": "8.5\n 2 3800.0"}]
Print the answer. * * *
s258782879
Wrong Answer
p02650
Input is given from Standard Input in the following format: W H K
import sys def count_h(y1, y2, w): n = y1 * (w + 1) if y2 == y1: n += w + 1 else: n += int((y2 - y1 + 1) * (w + 1) / 2 + 1) return n - 2 def count_xy(x, y): return int(((x + 1) * (y + 1) + 1) / 2) + 1 - 2 def test_count(): assert count_xy(1, 1) == 1 assert count_xy(1, 2) == 2 assert count_xy(2, 2) == 4 assert count_h(0, 0, 3) == 2 assert count_h(0, 1, 3) == 3 assert count_h(0, 2, 3) == 5 assert (3 * 4) - count_xy(1, 1) - count_xy(1, 1) - count_h(2, 2, 2) - 3 == 0 def count_k(w, h, k): result = 0 for x1 in range(1, w + 1): count = 0 for y1 in range(1, h + 1): for y2 in range(y1, h + 1): dot = ( (1 + w) * (1 + h) - count_xy(x1, y1) - count_xy(w - x1, y2) - count_h(h - y1, h - y2, w) - 3 ) if dot == k: # print([x1, 0], [0, y1], [w, y2], "match") count = count + 1 if y1 == y2 else count + 2 else: # print([x1, 0], [0, y1], [w, y2], "not", dot) assert dot >= 0 for x2 in range(x1, w + 1): dot = ( (1 + w) * (1 + h) - count_xy(x1, y1) - count_xy(x2, h - y2) - count_h(w - x1, w - x2, h) - 3 ) if dot == k: # print([x1, 0], [0, y1], [w, y2], "match") count = count + 1 if x1 == x2 else count + 2 else: # print([x1, 0], [0, y1], [w, y2], "not", dot) assert dot >= 0 if w / 2 != x1: count *= 2 result += count return result w, h, k = map(int, sys.stdin.readline().split()) print(count_k(w, h, k))
Statement In a two-dimensional plane, we have a rectangle R whose vertices are (0,0), (W,0), (0,H), and (W,H), where W and H are positive integers. Here, find the number of triangles \Delta in the plane that satisfy all of the following conditions: * Each vertex of \Delta is a grid point, that is, has integer x\- and y-coordinates. * \Delta and R shares no vertex. * Each vertex of \Delta lies on the perimeter of R, and all the vertices belong to different sides of R. * \Delta contains at most K grid points strictly within itself (excluding its perimeter and vertices).
[{"input": "2 3 1", "output": "12\n \n\nFor example, the triangle with the vertices (1,0), (0,2), and (2,2) contains\njust one grid point within itself and thus satisfies the condition.\n\n* * *"}, {"input": "5 4 5", "output": "132\n \n\n* * *"}, {"input": "100 100 1000", "output": "461316"}]
Print the answer. * * *
s373444370
Runtime Error
p02650
Input is given from Standard Input in the following format: W H K
W, H, K = list(map(int, input().split())) counter = int(0) triangle_counter = 0 if W <= 2 or H == 1: print(0) else: for i in range(1, H): for j in range(1, W): for k in range(j, W): counter = 0 if j == k: # 三角形の1辺がy軸と垂直 for l in range(1, j): counter += int( (H - float(i)) / float(k) * l + float(i) / float(j) * l ) if counter <= K: triangle_counter += 2 else: # j < k for m in range(1, j): counter += int( (H - float(i)) / float(k) * m + float(i) / float(j) * m ) for n in range(j, W): counter += int( (H - float(i)) / float(k) * n + i - H * n / (float(k) - float(j) - H * j / (1 + j)) ) if counter == K: triangle_counter += 4 print(triangle_counter)
Statement In a two-dimensional plane, we have a rectangle R whose vertices are (0,0), (W,0), (0,H), and (W,H), where W and H are positive integers. Here, find the number of triangles \Delta in the plane that satisfy all of the following conditions: * Each vertex of \Delta is a grid point, that is, has integer x\- and y-coordinates. * \Delta and R shares no vertex. * Each vertex of \Delta lies on the perimeter of R, and all the vertices belong to different sides of R. * \Delta contains at most K grid points strictly within itself (excluding its perimeter and vertices).
[{"input": "2 3 1", "output": "12\n \n\nFor example, the triangle with the vertices (1,0), (0,2), and (2,2) contains\njust one grid point within itself and thus satisfies the condition.\n\n* * *"}, {"input": "5 4 5", "output": "132\n \n\n* * *"}, {"input": "100 100 1000", "output": "461316"}]
Print the answer. * * *
s092085216
Wrong Answer
p02650
Input is given from Standard Input in the following format: W H K
1
Statement In a two-dimensional plane, we have a rectangle R whose vertices are (0,0), (W,0), (0,H), and (W,H), where W and H are positive integers. Here, find the number of triangles \Delta in the plane that satisfy all of the following conditions: * Each vertex of \Delta is a grid point, that is, has integer x\- and y-coordinates. * \Delta and R shares no vertex. * Each vertex of \Delta lies on the perimeter of R, and all the vertices belong to different sides of R. * \Delta contains at most K grid points strictly within itself (excluding its perimeter and vertices).
[{"input": "2 3 1", "output": "12\n \n\nFor example, the triangle with the vertices (1,0), (0,2), and (2,2) contains\njust one grid point within itself and thus satisfies the condition.\n\n* * *"}, {"input": "5 4 5", "output": "132\n \n\n* * *"}, {"input": "100 100 1000", "output": "461316"}]
Print the answer. * * *
s766185058
Runtime Error
p02650
Input is given from Standard Input in the following format: W H K
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) x = a - b y = abs(x) if v * t >= (y + w * t): print("YES") else: print("NO")
Statement In a two-dimensional plane, we have a rectangle R whose vertices are (0,0), (W,0), (0,H), and (W,H), where W and H are positive integers. Here, find the number of triangles \Delta in the plane that satisfy all of the following conditions: * Each vertex of \Delta is a grid point, that is, has integer x\- and y-coordinates. * \Delta and R shares no vertex. * Each vertex of \Delta lies on the perimeter of R, and all the vertices belong to different sides of R. * \Delta contains at most K grid points strictly within itself (excluding its perimeter and vertices).
[{"input": "2 3 1", "output": "12\n \n\nFor example, the triangle with the vertices (1,0), (0,2), and (2,2) contains\njust one grid point within itself and thus satisfies the condition.\n\n* * *"}, {"input": "5 4 5", "output": "132\n \n\n* * *"}, {"input": "100 100 1000", "output": "461316"}]
Print the answer. * * *
s510581449
Wrong Answer
p02650
Input is given from Standard Input in the following format: W H K
w, h, k = (int(x) for x in input().split()) w -= 1 h -= 1 a = w * h * w b = h * w * h print((a + b) * 2)
Statement In a two-dimensional plane, we have a rectangle R whose vertices are (0,0), (W,0), (0,H), and (W,H), where W and H are positive integers. Here, find the number of triangles \Delta in the plane that satisfy all of the following conditions: * Each vertex of \Delta is a grid point, that is, has integer x\- and y-coordinates. * \Delta and R shares no vertex. * Each vertex of \Delta lies on the perimeter of R, and all the vertices belong to different sides of R. * \Delta contains at most K grid points strictly within itself (excluding its perimeter and vertices).
[{"input": "2 3 1", "output": "12\n \n\nFor example, the triangle with the vertices (1,0), (0,2), and (2,2) contains\njust one grid point within itself and thus satisfies the condition.\n\n* * *"}, {"input": "5 4 5", "output": "132\n \n\n* * *"}, {"input": "100 100 1000", "output": "461316"}]
Print the answer. * * *
s072305898
Runtime Error
p02650
Input is given from Standard Input in the following format: W H K
from math import gcd input1 = input().split() W = int(input1[0]) H = int(input1[1]) K = int(input1[2]) def NumOfGrid(tup1: list, tup2: list): return gcd((abs(tup1[0] - tup2[0]), abs(tup1[1] - tup2[1]))) - 1 def Sur(p1, p2, p3): p22 = [(p2[0] - p1[0]), (p2[1] - p1[1])] p23 = [(p3[0] - p1[0]), (p3[1] - p1[1])] return abs(p22[0] * p23[1] - p23[0] * p22[1]) / 2 def Koshiten(p1: list, p2: list, p3: list): return int( Sur(p1, p2, p3) - (NumOfGrid(p1, p2) + NumOfGrid(p2, p3) + NumOfGrid(p3, p1) - 3) - 1 ) def Triangles(p1, p2, p3, K): if Koshiten(p1, p2, p3) <= K: return True else: return False Result = 0 for a in range(2, H): p1 = [0, a] for b in range(2, W): p2 = [b, H] for c in range(2, W): p3 = [c, 0] if Triangles(p1, p2, p3, K) == True: Result += 1 for c in range(2, H): p3 = [W, c] if Triangles(p1, p2, p3, K) == True: Result += 1 print(Result)
Statement In a two-dimensional plane, we have a rectangle R whose vertices are (0,0), (W,0), (0,H), and (W,H), where W and H are positive integers. Here, find the number of triangles \Delta in the plane that satisfy all of the following conditions: * Each vertex of \Delta is a grid point, that is, has integer x\- and y-coordinates. * \Delta and R shares no vertex. * Each vertex of \Delta lies on the perimeter of R, and all the vertices belong to different sides of R. * \Delta contains at most K grid points strictly within itself (excluding its perimeter and vertices).
[{"input": "2 3 1", "output": "12\n \n\nFor example, the triangle with the vertices (1,0), (0,2), and (2,2) contains\njust one grid point within itself and thus satisfies the condition.\n\n* * *"}, {"input": "5 4 5", "output": "132\n \n\n* * *"}, {"input": "100 100 1000", "output": "461316"}]
Print the string S after lowercasing the K-th character in it. * * *
s824618682
Accepted
p03041
Input is given from Standard Input in the following format: N K S
import sys from io import StringIO import unittest def resolve(): N, K = map(int, input().split()) S = list(input()) S[K - 1] = S[K - 1].lower() print("".join(S)) class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """3 1 ABC""" output = """aBC""" self.assertIO(input, output) def test_入力例_2(self): input = """4 3 CABA""" output = """CAbA""" self.assertIO(input, output) if __name__ == "__main__": resolve()
Statement You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.
[{"input": "3 1\n ABC", "output": "aBC\n \n\n* * *"}, {"input": "4 3\n CABA", "output": "CAbA"}]
Print the string S after lowercasing the K-th character in it. * * *
s970515391
Wrong Answer
p03041
Input is given from Standard Input in the following format: N K S
S = input() if (int(S[:2]) == 0) and (int(S[2:4])) == 0: print("{}".format("NA")) elif (int(S[:2]) == 0) and (12 < int(S[2:4])): print("{}".format("NA")) elif 12 < (int(S[:2])) and (int(S[2:4]) == 0): print("{}".format("NA")) elif (12 < int(S[:2])) and (12 < int(S[2:4])): print("{}".format("NA")) elif (int(S[:2]) == 0) and (int(S[2:4]) < 13): print("{}".format("YYMM")) elif (int(S[:2]) < 13) and (int(S[2:4]) == 0): print("{}".format("MMYY")) elif 0 < (int(S[:2]) < 13) and (0 < int(S[2:4]) < 13): print("{}".format("AMBIGUOUS")) elif int(S[:2]) < 13: print("{}".format("MMYY")) else: print("{}".format("YYMM"))
Statement You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.
[{"input": "3 1\n ABC", "output": "aBC\n \n\n* * *"}, {"input": "4 3\n CABA", "output": "CAbA"}]
Print the string S after lowercasing the K-th character in it. * * *
s127715996
Runtime Error
p03041
Input is given from Standard Input in the following format: N K S
(a, b) = list(map(int, input().split())) print("".join([c if i != b - 1 else c.lower() for i, c in enumerate(s := input())]))
Statement You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.
[{"input": "3 1\n ABC", "output": "aBC\n \n\n* * *"}, {"input": "4 3\n CABA", "output": "CAbA"}]
Print the string S after lowercasing the K-th character in it. * * *
s315742140
Runtime Error
p03041
Input is given from Standard Input in the following format: N K S
N = int(input()) weights = [input() for _ in range(N - 1)] weights = [x.split() for x in weights] weights = [list(map(int, x)) for x in weights] color = [1 for _ in range(N + 1)] color[1] = 0 bi = [] if N > 2: for i in range(1, N + 1): n1 = None n2 = None l1 = 0 l2 = 0 for x in weights: if x[0] == i: if n1 == None: n1 = x[1] l1 = x[2] else: n2 = x[1] l2 = x[2] if x[1] == i: if n1 == None: n1 = x[1] l1 = x[2] else: n2 = x[1] l2 = x[2] if n1 != None and n2 != None: bi.append([n1, n2, l1 + l2]) w2 = weights + bi for _ in range(N): c = 0 for x in w2: if x[2] % 2 == 0: if color[x[0]] == 0 and color[x[1]] == 1 and x[2] % 2 == 0: color[x[1]] = color[x[0]] c = 1 if color[x[1]] == 0 and color[x[0]] == 1 and x[2] % 2 == 0: color[x[0]] = color[x[1]] c = 1 if c == 0: break for x in color[1:]: print(x)
Statement You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.
[{"input": "3 1\n ABC", "output": "aBC\n \n\n* * *"}, {"input": "4 3\n CABA", "output": "CAbA"}]
Print the string S after lowercasing the K-th character in it. * * *
s942101632
Accepted
p03041
Input is given from Standard Input in the following format: N K S
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 N, K = MAP() S = list(input()) S[K - 1] = S[K - 1].lower() print("".join(S))
Statement You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.
[{"input": "3 1\n ABC", "output": "aBC\n \n\n* * *"}, {"input": "4 3\n CABA", "output": "CAbA"}]
Print the string S after lowercasing the K-th character in it. * * *
s865163968
Runtime Error
p03041
Input is given from Standard Input in the following format: N K S
N, K = (i for i in input().split()) K = int(K) X = list(N) if X[K - 1] == "A": X[K - 1] = "a" if X[K - 1] == "B": X[K - 1] = "b" if X[K - 1] == "C": X[K - 1] = "c" print("".join(X))
Statement You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.
[{"input": "3 1\n ABC", "output": "aBC\n \n\n* * *"}, {"input": "4 3\n CABA", "output": "CAbA"}]
Print the string S after lowercasing the K-th character in it. * * *
s925229537
Runtime Error
p03041
Input is given from Standard Input in the following format: N K S
input() a = sorted(map(int, input().split())) print("{} {} {}".format(a[0], a[-1], sum(a)))
Statement You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.
[{"input": "3 1\n ABC", "output": "aBC\n \n\n* * *"}, {"input": "4 3\n CABA", "output": "CAbA"}]
Print the string S after lowercasing the K-th character in it. * * *
s465828627
Accepted
p03041
Input is given from Standard Input in the following format: N K S
icase = 0 if icase == 0: n, k = map(int, input().split()) s = input() if k == 1: s1 = "" s2 = s[0] s3 = s[1:] elif k == n: s1 = s[: n - 1] s2 = s[n - 1] s3 = "" else: s1 = s[: k - 1] s2 = s[k - 1] s3 = s[k:] if s2 == "A": s2 = "a" elif s2 == "B": s2 = "b" elif s2 == "C": s2 = "c" print(s1 + s2 + s3)
Statement You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.
[{"input": "3 1\n ABC", "output": "aBC\n \n\n* * *"}, {"input": "4 3\n CABA", "output": "CAbA"}]
Print the string S after lowercasing the K-th character in it. * * *
s615208708
Wrong Answer
p03041
Input is given from Standard Input in the following format: N K S
num, loc = map(int, input().split()) dummy = ["" for i in range(num)] moj = input() count = 0 for j in moj: dummy[count] = j count = count + 1 S = dummy[loc - 1] W = S.swapcase() dummy[loc - 1] = W print(dummy)
Statement You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.
[{"input": "3 1\n ABC", "output": "aBC\n \n\n* * *"}, {"input": "4 3\n CABA", "output": "CAbA"}]
Print the string S after lowercasing the K-th character in it. * * *
s819708647
Runtime Error
p03041
Input is given from Standard Input in the following format: N K S
N, M = input().split() N = int(N) M = int(M) list = [] A_list = [] for i in range(M): x, y, z = input().split() x, y, z = int(x), int(y), int(z) list.append([x, y, z]) A_list.append([list[0][0]]) for data in list: check = 0 for A_data in A_list: if data[0] in A_data: A_data.append(data[1]) check = 0 elif data[1] in A_data: A_data.append(data[0]) check = 0 elif not data[0] in A_data and not data[1] in A_data: check = 1 if check: A_list.append([data[0], data[1]]) print(len(A_list))
Statement You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.
[{"input": "3 1\n ABC", "output": "aBC\n \n\n* * *"}, {"input": "4 3\n CABA", "output": "CAbA"}]
Print the string S after lowercasing the K-th character in it. * * *
s209412477
Runtime Error
p03041
Input is given from Standard Input in the following format: N K S
N = int(input()) y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] one = [1] zero = [0] p = [1, 2, 3, 4, 5, 6, 7, 8, 9] q = [0, 1, 2] a = N // 1000 b = (N - (a * 1000)) // 100 c = (N - (a * 1000) - (b * 100)) // 10 d = N - (a * 1000) - (b * 100) - (c * 10) if ((a in one) and (b in q) or (a in zero) and (b in p)) and ( (c in one) and (d in q) or (c in zero) and (d in p) ): print("AMBIGUOUS") elif (a in y) and (b in y) and ((c in one) and (d in q) or (c in zero) and (d in p)): print("YYMM") elif ((a in one) and (b in q)) or ((a in zero) and (b in p)) and (c in y) and (d in y): print("MMYY") else: print("NA")
Statement You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.
[{"input": "3 1\n ABC", "output": "aBC\n \n\n* * *"}, {"input": "4 3\n CABA", "output": "CAbA"}]
Print the maximum number of friendly pairs. * * *
s814474557
Accepted
p03411
Input is given from Standard Input in the following format: N a_1 b_1 a_2 b_2 : a_N b_N c_1 d_1 c_2 d_2 : c_N d_N
def dfs(v, visited): """ :param v: X側の未マッチングの頂点の1つ :param visited: 空のsetを渡す(外部からの呼び出し時) :return: 増大路が見つかればTrue """ for u in edges[v]: if u in visited: continue visited.add(u) if matched[u] == -1 or dfs(matched[u], visited): matched[u] = v return True return False N = int(input()) red = [list(map(int, input().split())) for _ in range(N)] blue = [list(map(int, input().split())) for _ in range(N)] match = [] redg = [i for i in range(N)] blueg = [i for i in range(N)] for i in range(N): for j in range(N): if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]: match.append((i, j)) edges = [set() for _ in range(N)] matched = [-1] * N for i in range(len(match)): x, y = match[i] edges[x].add(y) # 増大路発見に成功したらTrue(=1)。合計することでマッチング数となる print(sum(dfs(s, set()) for s in range(N))) # # def get_edge(M, u, U=None): # if U == None: # for x in M[:]: # if x[0] == u: # return x[1] # elif x[1] == u: # return x[0] # # else: # for x in M[:]: # if x[0] == u and x[1] in U: # return x[1] # elif x[1] == u and x[0] in U: # return x[0] # return None # # # def get_nodes(M): # U = set() # V = set() # for x in M: # U.add(x[0]) # V.add(x[1]) # return (U, V) # # # def augpath(Si, Ti, M, E): # (U, V) = get_nodes(M) # Ti1 = set(x[1] for x in E if x[0] in Si and not x[1] in Ti) # # if Ti1 == set(): # return (M, None) # # elif Ti1.difference(V) == set(): # Si1 = set(x[0] for x in M if x[1] in Ti1) # (M, ui1) = augpath(Si1, Ti.union(Ti1), M, E) # # if ui1 == None: # return (M, None) # # else: # v = get_edge(M, ui1) # M.remove((ui1, v)) # # ui = get_edge(E, v, U=Si) # M.append((ui, v)) # # return (M, ui) # # else: # v = Ti1.difference(V).pop() # u = get_edge(E, v, U=Si) # M.append((u, v)) # # return (M, u) # # # def Hungary(U0, V0, E): # U_bef = set() # M = [] # cnt = 0 # length = len(U0) # # # CALC # while True: # # # INIT # (U, V) = get_nodes(M) # u = U0[cnt % length] # cnt = cnt + 1 # S0 = set() # S0.add(u) # T0 = set() # # # 終了条件(すべての頂点から始まる増大道を調べて、マッチング数が変わっていなければ、それ以上増えることはない) # if cnt % length == 0: # if U.difference(U_bef) == set(): # break # U_bef = U.copy() # # # 枝刈り(すでにマッチングしている頂点から始まる道は増大道ではない) # if u in U: # continue # # # CALC # (M, u) = augpath(S0, T0, M, E) # # return M # # # N = int(input()) # red = [list(map(int,input().split())) for _ in range(N)] # blue = [list(map(int,input().split())) for _ in range(N)] # match = [] # redg = [i for i in range(N)] # blueg = [i for i in range(N)] # # for i in range(N): # for j in range(N): # if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]: # match.append((i, j)) # # edges = Hungary(redg, blueg, match) # print(len(edges))
Statement On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
[{"input": "3\n 2 0\n 3 1\n 1 3\n 4 2\n 0 4\n 5 5", "output": "2\n \n\nFor example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).\n\n* * *"}, {"input": "3\n 0 0\n 1 1\n 5 2\n 2 3\n 3 4\n 4 5", "output": "2\n \n\nFor example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).\n\n* * *"}, {"input": "2\n 2 2\n 3 3\n 0 0\n 1 1", "output": "0\n \n\nIt is possible that no pair can be formed.\n\n* * *"}, {"input": "5\n 0 0\n 7 3\n 2 2\n 4 8\n 1 6\n 8 5\n 6 9\n 5 4\n 9 1\n 3 7", "output": "5\n \n\n* * *"}, {"input": "5\n 0 0\n 1 1\n 5 5\n 6 6\n 7 7\n 2 2\n 3 3\n 4 4\n 8 8\n 9 9", "output": "4"}]
Print the maximum number of friendly pairs. * * *
s680415715
Accepted
p03411
Input is given from Standard Input in the following format: N a_1 b_1 a_2 b_2 : a_N b_N c_1 d_1 c_2 d_2 : c_N d_N
def solve(): n = int(input()) a = [] b = [] c = [] d = [] for i in range(n): a_, b_ = map(int, input().split()) a.append(a_) b.append(b_) for i in range(n): c_, d_ = map(int, input().split()) c.append(c_) d.append(d_) import numpy as np a, b, c, d = np.array(a), np.array(b), np.array(c), np.array(d) arg = np.argsort(b)[::-1] a = a[arg] b = b[arg] argc = np.argsort(c) c = c[argc] d = d[argc] n_pair = 0 for i in range(n): c_, d_ = c[i], d[i] for j, a_ in enumerate(a): b_ = b[j] if a_ < c_ and b_ < d_: n_pair += 1 a = np.delete(a, j) b = np.delete(b, j) # print(a_, b_, c_, d_) break print(n_pair) solve()
Statement On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
[{"input": "3\n 2 0\n 3 1\n 1 3\n 4 2\n 0 4\n 5 5", "output": "2\n \n\nFor example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).\n\n* * *"}, {"input": "3\n 0 0\n 1 1\n 5 2\n 2 3\n 3 4\n 4 5", "output": "2\n \n\nFor example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).\n\n* * *"}, {"input": "2\n 2 2\n 3 3\n 0 0\n 1 1", "output": "0\n \n\nIt is possible that no pair can be formed.\n\n* * *"}, {"input": "5\n 0 0\n 7 3\n 2 2\n 4 8\n 1 6\n 8 5\n 6 9\n 5 4\n 9 1\n 3 7", "output": "5\n \n\n* * *"}, {"input": "5\n 0 0\n 1 1\n 5 5\n 6 6\n 7 7\n 2 2\n 3 3\n 4 4\n 8 8\n 9 9", "output": "4"}]
Print the maximum number of friendly pairs. * * *
s429968471
Accepted
p03411
Input is given from Standard Input in the following format: N a_1 b_1 a_2 b_2 : a_N b_N c_1 d_1 c_2 d_2 : c_N d_N
class Node: def __init__(self, idx=None): self.idx = idx self.edge = [] self.level = None self.par = None class Edge: def __init__(self, to, cap, rev=None): self.to = to self.cap = cap self.rev = rev from collections import deque class BipartiteMatching: def __init__(self, n, m): self.n = n self.m = m self.inf = 10**18 self.source = Node() self.sink = Node() self.lt = [Node(i) for i in range(n)] self.rt = [Node(i) for i in range(m)] for i in range(n): edge = Edge(self.lt[i], 1) rev = Edge(self.source, 0) edge.rev, rev.rev = rev, edge self.source.edge.append(edge) self.lt[i].edge.append(rev) for i in range(m): edge = Edge(self.sink, 1) rev = Edge(self.rt[i], 0) edge.rev, rev.rev = rev, edge self.rt[i].edge.append(edge) self.sink.edge.append(rev) def add(self, x, y): lt = self.lt[x] rt = self.rt[y] edge = Edge(rt, 1) rev = Edge(lt, 0) edge.rev, rev.rev = rev, edge lt.edge.append(edge) rt.edge.append(rev) def maximum_matching(self): flow = 0 while True: queue = deque([self.source]) self.source.level = 0 self.sink.level = None for i in range(self.n): self.lt[i].level = None for i in range(self.m): self.rt[i].level = None while queue: node = queue.popleft() for edge in node.edge: to = edge.to if edge.cap and to.level is None: to.level = node.level + 1 queue.append(to) if self.sink.level is None: break stack = [self.source] self.source.par = None self.sink.par = None for i in range(self.n): self.lt[i].par = None for i in range(self.m): self.rt[i].par = None while stack: node = stack.pop() if node is self.sink: break for edge in node.edge: to = edge.to if edge.cap and node.level < to.level: to.par = edge.rev stack.append(to) node = self.sink while node is not self.source: node.par.cap = 1 node.par.rev.cap = 0 node = node.par.to flow += 1 return flow N = int(input()) R = [tuple(map(int, input().split())) for _ in range(N)] B = [tuple(map(int, input().split())) for _ in range(N)] bip = BipartiteMatching(N, N) for i in range(N): a, b = R[i] for j in range(N): c, d = B[j] if a < c and b < d: bip.add(i, j) print(bip.maximum_matching())
Statement On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
[{"input": "3\n 2 0\n 3 1\n 1 3\n 4 2\n 0 4\n 5 5", "output": "2\n \n\nFor example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).\n\n* * *"}, {"input": "3\n 0 0\n 1 1\n 5 2\n 2 3\n 3 4\n 4 5", "output": "2\n \n\nFor example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).\n\n* * *"}, {"input": "2\n 2 2\n 3 3\n 0 0\n 1 1", "output": "0\n \n\nIt is possible that no pair can be formed.\n\n* * *"}, {"input": "5\n 0 0\n 7 3\n 2 2\n 4 8\n 1 6\n 8 5\n 6 9\n 5 4\n 9 1\n 3 7", "output": "5\n \n\n* * *"}, {"input": "5\n 0 0\n 1 1\n 5 5\n 6 6\n 7 7\n 2 2\n 3 3\n 4 4\n 8 8\n 9 9", "output": "4"}]
Print the maximum number of friendly pairs. * * *
s600852623
Accepted
p03411
Input is given from Standard Input in the following format: N a_1 b_1 a_2 b_2 : a_N b_N c_1 d_1 c_2 d_2 : c_N d_N
#!/usr/bin/env pypy3 import collections import itertools import sys #: The value representing "infinity." INF = 10**8 #: The maxium number of recursion. REC_LIMIT = 10000 #: Named tuple representing a edge in the flow network in question. FlowEdge = collections.namedtuple("FlowEdge", "source sink capacity") class FlowNetwork(object): """Class representing a flow network. :param int num_vertices: The number of vertices in the network. """ def __init__(self, num_vertices): self.adj_edges = [set() for _ in range(num_vertices)] self.flow = None self.rev_edge = dict() self.used = None def get_edges_from(self, vertex): """Returns the set of edges adjacent to the vertex. :param int vertex: The index of vertex. :returns: The set of edges adjacent to the vertex. :rtype: set """ return self.adj_edges[vertex] def add_edge(self, source, sink, capacity): """Add an edge u -> v to the flow network. :param int source: The vertex u. :param int sink: The vertex v. :param int capacity: The capacity of the edge. """ assert source != sink forward_edge = FlowEdge(source, sink, capacity) backward_edge = FlowEdge(sink, source, 0) self.rev_edge[forward_edge] = backward_edge self.rev_edge[backward_edge] = forward_edge self.adj_edges[source].add(forward_edge) self.adj_edges[sink].add(backward_edge) def dfs(self, source, sink, flow): """Finding augmenting paths using depth-first search. This method is not supposed to be used directly. Instead, use :meth:`FlowNetwork.ford_fulkerson`. """ if source == sink: return flow self.used[source] = True for edge in self.get_edges_from(source): rest = edge.capacity - self.flow[edge] if self.used[edge.sink] or rest <= 0: continue d = self.dfs(edge.sink, sink, min(flow, rest)) if d > 0: self.flow[edge] += d self.flow[self.rev_edge[edge]] -= d return d return 0 def ford_fulkerson(self, source, sink): """Computing maximum flow using the Ford-Fulkerson algorithm. :param int source: The source. :param int sink: The sink. :return: Maximum flow. """ self.flow = collections.defaultdict(int) max_flow = 0 while True: self.used = collections.defaultdict(bool) df = self.dfs(source, sink, INF) if df == 0: return max_flow else: max_flow += df def compute_max_num_pairs(num_points, red_points, blue_points): network = FlowNetwork(2 + 2 * num_points) source_idx = 2 * num_points sink_idx = source_idx + 1 # source -> each vertex # each vertex -> sink for i in range(num_points): network.add_edge(source_idx, i, 1) network.add_edge(num_points + i, sink_idx, 1) g = itertools.product( enumerate(red_points), enumerate(blue_points, start=num_points) ) for (ri, (rx, ry)), (bi, (bx, by)) in g: if rx < bx and ry < by: network.add_edge(ri, bi, 1) res = network.ford_fulkerson(source_idx, sink_idx) return res def main(): sys.setrecursionlimit(REC_LIMIT) num_points = int(input()) red_points = [tuple(int(z) for z in input().split()) for _ in range(num_points)] blue_points = [tuple(int(z) for z in input().split()) for _ in range(num_points)] res = compute_max_num_pairs(num_points, red_points, blue_points) print(res) if __name__ == "__main__": main()
Statement On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
[{"input": "3\n 2 0\n 3 1\n 1 3\n 4 2\n 0 4\n 5 5", "output": "2\n \n\nFor example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).\n\n* * *"}, {"input": "3\n 0 0\n 1 1\n 5 2\n 2 3\n 3 4\n 4 5", "output": "2\n \n\nFor example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).\n\n* * *"}, {"input": "2\n 2 2\n 3 3\n 0 0\n 1 1", "output": "0\n \n\nIt is possible that no pair can be formed.\n\n* * *"}, {"input": "5\n 0 0\n 7 3\n 2 2\n 4 8\n 1 6\n 8 5\n 6 9\n 5 4\n 9 1\n 3 7", "output": "5\n \n\n* * *"}, {"input": "5\n 0 0\n 1 1\n 5 5\n 6 6\n 7 7\n 2 2\n 3 3\n 4 4\n 8 8\n 9 9", "output": "4"}]
Print the maximum number of friendly pairs. * * *
s586705829
Accepted
p03411
Input is given from Standard Input in the following format: N a_1 b_1 a_2 b_2 : a_N b_N c_1 d_1 c_2 d_2 : c_N d_N
import sys import math import copy import random from heapq import heappush, heappop, heapify from functools import cmp_to_key from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(input()) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = float("inf") MOD = 10**9 + 7 divide = lambda x: pow(x, MOD - 2, MOD) def nck(n, k, kaijyo): return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD def npk(n, k, kaijyo): if k == 0 or k == n: return n % MOD return (kaijyo[n] * divide(kaijyo[n - k])) % MOD def fact_and_inv(SIZE): inv = [0] * SIZE # inv[j] = j^{-1} mod MOD fac = [0] * SIZE # fac[j] = j! mod MOD finv = [0] * SIZE # finv[j] = (j!)^{-1} mod MOD inv[1] = 1 fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2, SIZE): inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD fac[i] = fac[i - 1] * i % MOD finv[i] = finv[i - 1] * inv[i] % MOD return fac, finv def renritsu(A, Y): # example 2x + y = 3, x + 3y = 4 # A = [[2,1], [1,3]]) # Y = [[3],[4]] または [3,4] A = np.matrix(A) Y = np.matrix(Y) Y = np.reshape(Y, (-1, 1)) X = np.linalg.solve(A, Y) # [1.0, 1.0] return X.flatten().tolist()[0] class TwoDimGrid: # 2次元座標 -> 1次元 def __init__(self, h, w, wall="#"): self.h = h self.w = w self.size = (h + 2) * (w + 2) self.wall = wall self.get_grid() # self.init_cost() def get_grid(self): grid = [self.wall * (self.w + 2)] for i in range(self.h): grid.append(self.wall + getS() + self.wall) grid.append(self.wall * (self.w + 2)) self.grid = grid def init_cost(self): self.cost = [INF] * self.size def pos(self, x, y): # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed return y * (self.w + 2) + x def getgrid(self, x, y): return self.grid[y][x] def get(self, x, y): return self.cost[self.pos(x, y)] def set(self, x, y, v): self.cost[self.pos(x, y)] = v return def show(self): for i in range(self.h + 2): print(self.cost[(self.w + 2) * i : (self.w + 2) * (i + 1)]) def showsome(self, tgt): for t in tgt: print(t) return def showsomejoin(self, tgt): for t in tgt: print("".join(t)) return def search(self): grid = self.grid move = [(0, 1), (0, -1), (1, 0), (-1, 0)] move_eight = [ (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1), ] # for i in range(1, self.h+1): # for j in range(1, self.w+1): # cx, cy = j, i # for dx, dy in move_eight: # nx, ny = dx + cx, dy + cy def solve(): n = getN() anums = [] bnums = [] for i in range(n): anums.append(getList() + [0]) for i in range(n): anums.append(getList() + [1]) anums.sort() aaa = [] ans = 0 for num in anums: x, y, b = num if b == 0: aaa.append(y) aaa.sort() else: id = bisect_left(aaa, y) if id != 0: ans += 1 del aaa[id - 1] print(ans) # # an = [(max(x[0], x[1]), 0) for x in anums] # bn = [(min(x[0], x[1]), 1) for x in bnums] # # li = [] # for ann in an: # li.append(ann) # for bnn in bn: # li.append(bnn) # # li.sort() # ac = 0 # ans = 0 # for l in li: # if l[1] == 0: # ac += 1 # else: # if ac: # ans += 1 # ac -= 1 # # print(ans) def main(): n = getN() for _ in range(n): s = "".join([random.choice(["F", "T"]) for i in range(20)]) print(s) solve(s, 1, 0) return if __name__ == "__main__": # main() solve()
Statement On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
[{"input": "3\n 2 0\n 3 1\n 1 3\n 4 2\n 0 4\n 5 5", "output": "2\n \n\nFor example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).\n\n* * *"}, {"input": "3\n 0 0\n 1 1\n 5 2\n 2 3\n 3 4\n 4 5", "output": "2\n \n\nFor example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).\n\n* * *"}, {"input": "2\n 2 2\n 3 3\n 0 0\n 1 1", "output": "0\n \n\nIt is possible that no pair can be formed.\n\n* * *"}, {"input": "5\n 0 0\n 7 3\n 2 2\n 4 8\n 1 6\n 8 5\n 6 9\n 5 4\n 9 1\n 3 7", "output": "5\n \n\n* * *"}, {"input": "5\n 0 0\n 1 1\n 5 5\n 6 6\n 7 7\n 2 2\n 3 3\n 4 4\n 8 8\n 9 9", "output": "4"}]
Print the maximum number of friendly pairs. * * *
s699515077
Accepted
p03411
Input is given from Standard Input in the following format: N a_1 b_1 a_2 b_2 : a_N b_N c_1 d_1 c_2 d_2 : c_N d_N
N = int(input()) red = [list(map(int, input().split())) for _ in range(N)] blue = [list(map(int, input().split())) for _ in range(N)] red.sort() blue.sort() ret = 0 for c, d in blue: diff = 10**5 tmp = -1 for i, (a, b) in enumerate(red): if c > a and d > b: if diff > d - b: diff = d - b tmp = i if tmp > -1: red[tmp] = [10**5, 10**5] ret += 1 print(ret)
Statement On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
[{"input": "3\n 2 0\n 3 1\n 1 3\n 4 2\n 0 4\n 5 5", "output": "2\n \n\nFor example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).\n\n* * *"}, {"input": "3\n 0 0\n 1 1\n 5 2\n 2 3\n 3 4\n 4 5", "output": "2\n \n\nFor example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).\n\n* * *"}, {"input": "2\n 2 2\n 3 3\n 0 0\n 1 1", "output": "0\n \n\nIt is possible that no pair can be formed.\n\n* * *"}, {"input": "5\n 0 0\n 7 3\n 2 2\n 4 8\n 1 6\n 8 5\n 6 9\n 5 4\n 9 1\n 3 7", "output": "5\n \n\n* * *"}, {"input": "5\n 0 0\n 1 1\n 5 5\n 6 6\n 7 7\n 2 2\n 3 3\n 4 4\n 8 8\n 9 9", "output": "4"}]
Print the maximum number of friendly pairs. * * *
s328673866
Runtime Error
p03411
Input is given from Standard Input in the following format: N a_1 b_1 a_2 b_2 : a_N b_N c_1 d_1 c_2 d_2 : c_N d_N
from numpy import*;B=searchsorted;a,b=loadtxt(open(0),'i',skiprows=1);c=0;l=1<<29while l:h=l;l>>=1;y=sort(hstack((b%h-h,b%h)));c+=sum(B(y,h-a%h)-B(y,l-a%h))%2*l print(c)
Statement On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
[{"input": "3\n 2 0\n 3 1\n 1 3\n 4 2\n 0 4\n 5 5", "output": "2\n \n\nFor example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).\n\n* * *"}, {"input": "3\n 0 0\n 1 1\n 5 2\n 2 3\n 3 4\n 4 5", "output": "2\n \n\nFor example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).\n\n* * *"}, {"input": "2\n 2 2\n 3 3\n 0 0\n 1 1", "output": "0\n \n\nIt is possible that no pair can be formed.\n\n* * *"}, {"input": "5\n 0 0\n 7 3\n 2 2\n 4 8\n 1 6\n 8 5\n 6 9\n 5 4\n 9 1\n 3 7", "output": "5\n \n\n* * *"}, {"input": "5\n 0 0\n 1 1\n 5 5\n 6 6\n 7 7\n 2 2\n 3 3\n 4 4\n 8 8\n 9 9", "output": "4"}]