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 an integer representing the maximum number of books that can be read. * * *
s052488177
Wrong Answer
p02623
Input is given from Standard Input in the following format: N M K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
import sys data = sys.stdin conversion_data = [] for l in data: conversion_data.append([int(i) for i in l.split()]) table_a = conversion_data[1] table_b = conversion_data[2] N = conversion_data[0][0] M = conversion_data[0][1] limit = conversion_data[0][2] max = max([N, M]) total_time = 0 position_a = 0 position_b = 0 for i in range(max): if position_a <= N - 1: a = table_a[position_a] if (a + total_time) <= limit: total_time += a position_a += 1 if position_b <= M - 1: b = table_b[position_b] if (b + total_time) <= limit: total_time += b position_b += 1 print(position_a + position_b)
Statement We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it. It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M). Consider the following action: * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk. How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.
[{"input": "3 4 240\n 60 90 120\n 80 150 80 150", "output": "3\n \n\nIn this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd\nbooks from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st,\n2-nd, 3-rd, 4-th books from the top on Desk B, respectively.\n\nWe can read three books in 230 minutes, as shown below, and this is the\nmaximum number of books we can read within 240 minutes.\n\n * Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.\n * Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.\n * Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.\n\n* * *"}, {"input": "3 4 730\n 60 90 120\n 80 150 80 150", "output": "7\n \n\n* * *"}, {"input": "5 4 1\n 1000000000 1000000000 1000000000 1000000000 1000000000\n 1000000000 1000000000 1000000000 1000000000", "output": "0\n \n\nWatch out for integer overflows."}]
Print an integer representing the maximum number of books that can be read. * * *
s645958739
Wrong Answer
p02623
Input is given from Standard Input in the following format: N M K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
class queue: data = [] def __init__(self): self.data = [] def push(self, data): self.data.append(data) def pop(self): return self.data.pop(0) def peek(self): return self.data[0] t1 = queue() t2 = queue() s1 = input().split(" ") size1, size2, minutes = int(s1[0]), int(s1[1]), int(s1[2]) s2 = input().split(" ") for i in range(len(s2)): t1.push(int(s2[i])) s3 = input().split(" ") for i in range(len(s3)): t2.push(int(s3[i])) ans = 0 while True: time1 = 0 time2 = 0 if t1.data: time1 = t1.peek() if t2.data: time2 = t2.peek() if time1 == 0 and time2 == 0: break if minutes < min(time1, time2): break if time1 > time2: t1.pop() minutes -= time1 elif time2 > time1: t2.pop() minutes -= time2 ans += 1 print(ans)
Statement We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it. It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M). Consider the following action: * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk. How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.
[{"input": "3 4 240\n 60 90 120\n 80 150 80 150", "output": "3\n \n\nIn this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd\nbooks from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st,\n2-nd, 3-rd, 4-th books from the top on Desk B, respectively.\n\nWe can read three books in 230 minutes, as shown below, and this is the\nmaximum number of books we can read within 240 minutes.\n\n * Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.\n * Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.\n * Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.\n\n* * *"}, {"input": "3 4 730\n 60 90 120\n 80 150 80 150", "output": "7\n \n\n* * *"}, {"input": "5 4 1\n 1000000000 1000000000 1000000000 1000000000 1000000000\n 1000000000 1000000000 1000000000 1000000000", "output": "0\n \n\nWatch out for integer overflows."}]
Print an integer representing the maximum number of books that can be read. * * *
s169042204
Wrong Answer
p02623
Input is given from Standard Input in the following format: N M K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
n, m, k = map(int, input().split()) ln_a = list(map(int, input().split())) ln_b = list(map(int, input().split())) total = 10**9 output = 0 for i in range(1, len(ln_a) + len(ln_b) + 1): for j in range(i + 1): total = min(total, sum(ln_a[:j]) + sum(ln_a[: i - j])) if total <= k: output = i total = 10**9 print(output)
Statement We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it. It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M). Consider the following action: * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk. How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.
[{"input": "3 4 240\n 60 90 120\n 80 150 80 150", "output": "3\n \n\nIn this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd\nbooks from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st,\n2-nd, 3-rd, 4-th books from the top on Desk B, respectively.\n\nWe can read three books in 230 minutes, as shown below, and this is the\nmaximum number of books we can read within 240 minutes.\n\n * Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.\n * Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.\n * Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.\n\n* * *"}, {"input": "3 4 730\n 60 90 120\n 80 150 80 150", "output": "7\n \n\n* * *"}, {"input": "5 4 1\n 1000000000 1000000000 1000000000 1000000000 1000000000\n 1000000000 1000000000 1000000000 1000000000", "output": "0\n \n\nWatch out for integer overflows."}]
Print an integer representing the maximum number of books that can be read. * * *
s786587401
Wrong Answer
p02623
Input is given from Standard Input in the following format: N M K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
[n, m, k] = list(map(int, input().split())) aList = list(map(int, input().split())) bList = list(map(int, input().split())) numCount = 0 realVal = 0 fakeVal = 0 aList.append(1e10) bList.append(1e10) while True: if aList[0] < bList[0]: fakeVal += aList.pop(0) numCount += 1 else: fakeVal += bList.pop(0) numCount += 1 if not fakeVal > k: realVal = fakeVal else: numCount -= 1 break print(numCount)
Statement We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it. It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M). Consider the following action: * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk. How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.
[{"input": "3 4 240\n 60 90 120\n 80 150 80 150", "output": "3\n \n\nIn this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd\nbooks from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st,\n2-nd, 3-rd, 4-th books from the top on Desk B, respectively.\n\nWe can read three books in 230 minutes, as shown below, and this is the\nmaximum number of books we can read within 240 minutes.\n\n * Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.\n * Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.\n * Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.\n\n* * *"}, {"input": "3 4 730\n 60 90 120\n 80 150 80 150", "output": "7\n \n\n* * *"}, {"input": "5 4 1\n 1000000000 1000000000 1000000000 1000000000 1000000000\n 1000000000 1000000000 1000000000 1000000000", "output": "0\n \n\nWatch out for integer overflows."}]
Print an integer representing the maximum number of books that can be read. * * *
s902021226
Wrong Answer
p02623
Input is given from Standard Input in the following format: N M K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
N, M, K = [int(N) for N in input().split()] A = [int(A) for A in input().split()] B = [int(B) for B in input().split()] p = 0 if K >= (sum(A) + sum(B)): print(len(A) + len(B)) else: while K >= 0: try: if A[0] > B[0]: K -= B[0] p += 1 del B[0] else: K -= A[0] p += 1 del A[0] except: try: K -= B[0] p += 1 del B[0] except: K -= A[0] p += 1 del A[0] print(p - 1)
Statement We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it. It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M). Consider the following action: * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk. How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.
[{"input": "3 4 240\n 60 90 120\n 80 150 80 150", "output": "3\n \n\nIn this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd\nbooks from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st,\n2-nd, 3-rd, 4-th books from the top on Desk B, respectively.\n\nWe can read three books in 230 minutes, as shown below, and this is the\nmaximum number of books we can read within 240 minutes.\n\n * Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.\n * Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.\n * Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.\n\n* * *"}, {"input": "3 4 730\n 60 90 120\n 80 150 80 150", "output": "7\n \n\n* * *"}, {"input": "5 4 1\n 1000000000 1000000000 1000000000 1000000000 1000000000\n 1000000000 1000000000 1000000000 1000000000", "output": "0\n \n\nWatch out for integer overflows."}]
Print an integer representing the maximum number of books that can be read. * * *
s433985615
Runtime Error
p02623
Input is given from Standard Input in the following format: N M K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
arr1 = [] arr2 = [] satu = 0 num1, num2, time = map(int, input().split()) arr1 += map(int, input().split()) arr2 += map(int, input().split()) order1 = 0 order2 = 0 for n in range(num1 + num2): while time >= 0: if arr1[order1] <= arr2[order2]: time -= arr1[order1] order1 += 1 else: time -= arr2[order2] order2 += 1 satu += 1 print(satu)
Statement We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it. It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M). Consider the following action: * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk. How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.
[{"input": "3 4 240\n 60 90 120\n 80 150 80 150", "output": "3\n \n\nIn this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd\nbooks from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st,\n2-nd, 3-rd, 4-th books from the top on Desk B, respectively.\n\nWe can read three books in 230 minutes, as shown below, and this is the\nmaximum number of books we can read within 240 minutes.\n\n * Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.\n * Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.\n * Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.\n\n* * *"}, {"input": "3 4 730\n 60 90 120\n 80 150 80 150", "output": "7\n \n\n* * *"}, {"input": "5 4 1\n 1000000000 1000000000 1000000000 1000000000 1000000000\n 1000000000 1000000000 1000000000 1000000000", "output": "0\n \n\nWatch out for integer overflows."}]
Print an integer representing the maximum number of books that can be read. * * *
s463807787
Wrong Answer
p02623
Input is given from Standard Input in the following format: N M K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
n,m,k = list(map(int,input().split())) narr = list(map(int,input().split())) marr = list(map(int,input().split())) i,j=0,0 res=0 tot=0 while i<n or j<m: a1=999999999999 a2=999999999999 if i<n: a1 = narr[i] if j<m: a2 = marr[j] if a1<a2: i+=1 else: j+=1 tot+=min(a1,a2) res+=1 if tot > k: res-=1 break print(res)
Statement We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it. It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M). Consider the following action: * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk. How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.
[{"input": "3 4 240\n 60 90 120\n 80 150 80 150", "output": "3\n \n\nIn this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd\nbooks from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st,\n2-nd, 3-rd, 4-th books from the top on Desk B, respectively.\n\nWe can read three books in 230 minutes, as shown below, and this is the\nmaximum number of books we can read within 240 minutes.\n\n * Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.\n * Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.\n * Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.\n\n* * *"}, {"input": "3 4 730\n 60 90 120\n 80 150 80 150", "output": "7\n \n\n* * *"}, {"input": "5 4 1\n 1000000000 1000000000 1000000000 1000000000 1000000000\n 1000000000 1000000000 1000000000 1000000000", "output": "0\n \n\nWatch out for integer overflows."}]
Print an integer representing the maximum number of books that can be read. * * *
s028510857
Runtime Error
p02623
Input is given from Standard Input in the following format: N M K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
N, M, K = map(int, input().split()) time_A = list(map(int, input().split())) time_B = list(map(int, input().split())) max_books = 0 num_books = 0 allot_to_A = 0 allot_to_B = K time_bankA = allot_to_A time_bankB = allot_to_B read_in_B = [] baf_timeB = 0 for i in range(len(time_B)): if time_B[i] <= time_bankB: time_bankB -= time_B[i] num_books += 1 read_in_B.append(time_B[i]) else: baf_timeB = time_bankB if baf_timeB == 0: baf_timeB = K - sum(time_B) max_books = num_books tmp = max_books for i in range(len(time_A)): dif = 1 allot_to_A += time_A[i] allot_to_B -= time_A[i] if allot_to_B < 0: break time_to_reduce = time_A[i] while time_to_reduce > 0: if time_to_reduce <= baf_timeB: baf_timeB -= time_to_reduce break else: baf_timeB += read_in_B[-1] dif -= 1 del read_in_B[-1] tmp += dif max_books = max(tmp, max_books) print(max_books)
Statement We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it. It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M). Consider the following action: * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk. How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.
[{"input": "3 4 240\n 60 90 120\n 80 150 80 150", "output": "3\n \n\nIn this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd\nbooks from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st,\n2-nd, 3-rd, 4-th books from the top on Desk B, respectively.\n\nWe can read three books in 230 minutes, as shown below, and this is the\nmaximum number of books we can read within 240 minutes.\n\n * Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.\n * Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.\n * Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.\n\n* * *"}, {"input": "3 4 730\n 60 90 120\n 80 150 80 150", "output": "7\n \n\n* * *"}, {"input": "5 4 1\n 1000000000 1000000000 1000000000 1000000000 1000000000\n 1000000000 1000000000 1000000000 1000000000", "output": "0\n \n\nWatch out for integer overflows."}]
Print the number of ways modulo $10^9+7$ in a line.
s618487977
Wrong Answer
p02337
$n$ $k$ The first line will contain two integers $n$ and $k$.
# -*- coding: utf-8 -*- # ๆ–‡ๅญ—ๅˆ—ใฎๅ…ฅๅŠ› import math n, k = map(int, input().split()) def cmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod mod = 10**9 + 7 # ๅ‡บๅŠ›ใฎๅˆถ้™ N = 10**4 g1 = [1, 1] # ๅ…ƒใƒ†ใƒผใƒ–ใƒซ g2 = [1, 1] # ้€†ๅ…ƒใƒ†ใƒผใƒ–ใƒซ inverse = [0, 1] # ้€†ๅ…ƒใƒ†ใƒผใƒ–ใƒซ่จˆ็ฎ—็”จใƒ†ใƒผใƒ–ใƒซ for i in range(2, N + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) ans = 0 for i in range(1, n + 1): ansb = 0 for j in range(1, i + 1): ansb += ((-1) ** (i - j)) * cmb(i, j, mod) * (j**n) ansb /= math.factorial(i) ans += ansb print(int(ans))
You have $n$ balls and $k$ boxes. You want to put these balls into the boxes. Find the number of ways to put the balls under the following conditions: * Each ball is distinguished from the other. * Each box is **not** distinguished from the other. * Each ball can go into only one box and no one remains outside of the boxes. * Each box can contain an arbitrary number of balls (including zero). Note that you must print this count modulo $10^9+7$.
[{"input": "3 5", "output": "5"}, {"input": "5 3", "output": "41"}, {"input": "100 100", "output": "193120002"}]
Print the minimum total stamina the N people have to spend. * * *
s104977155
Accepted
p02767
Input is given from Standard Input in the following format: N X_1 X_2 ... X_N
_, *X = list(map(int, open(0).read().split())) print(min(map(lambda p: sum((x - p) ** 2 for x in X), range(min(X), max(X) + 1))))
Statement There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any **integer coordinate**. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting. Find the minimum total points of stamina the N people have to spend.
[{"input": "2\n 1 4", "output": "5\n \n\nAssume the meeting is held at coordinate 2. In this case, the first person\nwill spend (1 - 2)^2 points of stamina, and the second person will spend (4 -\n2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the\nminimum total stamina that the 2 people have to spend.\n\nNote that you can hold the meeting only at an integer coordinate.\n\n* * *"}, {"input": "7\n 14 14 2 13 56 2 37", "output": "2354"}]
Print the minimum total stamina the N people have to spend. * * *
s107849243
Wrong Answer
p02767
Input is given from Standard Input in the following format: N X_1 X_2 ... X_N
num = int(input()) pos = list(map(int, input().split())) maxpos = max(pos) minhealth = 1e9 count = 0 for i in range(maxpos): for j in pos: count += (j - i) ** 2 minhealth = min(minhealth, count) count = 0 print(minhealth)
Statement There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any **integer coordinate**. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting. Find the minimum total points of stamina the N people have to spend.
[{"input": "2\n 1 4", "output": "5\n \n\nAssume the meeting is held at coordinate 2. In this case, the first person\nwill spend (1 - 2)^2 points of stamina, and the second person will spend (4 -\n2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the\nminimum total stamina that the 2 people have to spend.\n\nNote that you can hold the meeting only at an integer coordinate.\n\n* * *"}, {"input": "7\n 14 14 2 13 56 2 37", "output": "2354"}]
Print the minimum total stamina the N people have to spend. * * *
s982999570
Wrong Answer
p02767
Input is given from Standard Input in the following format: N X_1 X_2 ... X_N
n = int(input()) point_list = list(map(int, input().split())) hp_list = [] for p in range(max(point_list)): hp = 0 for i in range(len(point_list)): hp += (point_list[i] - p) ** 2 hp_list.append(hp) print(min(hp_list))
Statement There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any **integer coordinate**. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting. Find the minimum total points of stamina the N people have to spend.
[{"input": "2\n 1 4", "output": "5\n \n\nAssume the meeting is held at coordinate 2. In this case, the first person\nwill spend (1 - 2)^2 points of stamina, and the second person will spend (4 -\n2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the\nminimum total stamina that the 2 people have to spend.\n\nNote that you can hold the meeting only at an integer coordinate.\n\n* * *"}, {"input": "7\n 14 14 2 13 56 2 37", "output": "2354"}]
Print the minimum total stamina the N people have to spend. * * *
s129048940
Wrong Answer
p02767
Input is given from Standard Input in the following format: N X_1 X_2 ... X_N
n = int(input()) list = [] list1 = [] list2 = [] list3 = [] c = 0 a = input().split() for i in range(0, len(a)): list1.append(int(a[i])) for j in range(1, 100): for item in list1: c = c + (item - j) ** 2 list2.append(c) l = len(list2) for z in range(0, l - 1): list3.append(list2[z + 1] - list2[z]) list3.sort() print(list3[0])
Statement There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any **integer coordinate**. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting. Find the minimum total points of stamina the N people have to spend.
[{"input": "2\n 1 4", "output": "5\n \n\nAssume the meeting is held at coordinate 2. In this case, the first person\nwill spend (1 - 2)^2 points of stamina, and the second person will spend (4 -\n2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the\nminimum total stamina that the 2 people have to spend.\n\nNote that you can hold the meeting only at an integer coordinate.\n\n* * *"}, {"input": "7\n 14 14 2 13 56 2 37", "output": "2354"}]
Print the minimum total stamina the N people have to spend. * * *
s879869522
Wrong Answer
p02767
Input is given from Standard Input in the following format: N X_1 X_2 ... X_N
number = input() coordinates = list(map(int, input().split())) coordinates.sort() coordinates.reverse() # print(coordinates) list = [] for i in range(coordinates[0]): total = 0 for j in range(len(coordinates)): total += (coordinates[j] - i) ** 2 list.insert(0, total) list.sort() print(list[0])
Statement There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any **integer coordinate**. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting. Find the minimum total points of stamina the N people have to spend.
[{"input": "2\n 1 4", "output": "5\n \n\nAssume the meeting is held at coordinate 2. In this case, the first person\nwill spend (1 - 2)^2 points of stamina, and the second person will spend (4 -\n2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the\nminimum total stamina that the 2 people have to spend.\n\nNote that you can hold the meeting only at an integer coordinate.\n\n* * *"}, {"input": "7\n 14 14 2 13 56 2 37", "output": "2354"}]
Print the minimum total stamina the N people have to spend. * * *
s864620759
Accepted
p02767
Input is given from Standard Input in the following format: N X_1 X_2 ... X_N
n = int(input()) a = input().split() print(min([sum([(int(i) - j) ** 2 for i in a]) for j in range(1, n + 10000)]))
Statement There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any **integer coordinate**. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting. Find the minimum total points of stamina the N people have to spend.
[{"input": "2\n 1 4", "output": "5\n \n\nAssume the meeting is held at coordinate 2. In this case, the first person\nwill spend (1 - 2)^2 points of stamina, and the second person will spend (4 -\n2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the\nminimum total stamina that the 2 people have to spend.\n\nNote that you can hold the meeting only at an integer coordinate.\n\n* * *"}, {"input": "7\n 14 14 2 13 56 2 37", "output": "2354"}]
Print the minimum total stamina the N people have to spend. * * *
s352340154
Accepted
p02767
Input is given from Standard Input in the following format: N X_1 X_2 ... X_N
import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x) - 1 printV = lambda x: print(*x, sep="\n") printH = lambda x: print(" ".join(map(str, x))) def IS(): return sys.stdin.readline()[:-1] def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LII(rows_number): return [II() for _ in range(rows_number)] def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def main(): N = II() X = LI() m = round(sum(X) / N) ans = 0 for x in X: ans += (x - m) ** 2 print(ans) if __name__ == "__main__": main()
Statement There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any **integer coordinate**. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting. Find the minimum total points of stamina the N people have to spend.
[{"input": "2\n 1 4", "output": "5\n \n\nAssume the meeting is held at coordinate 2. In this case, the first person\nwill spend (1 - 2)^2 points of stamina, and the second person will spend (4 -\n2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the\nminimum total stamina that the 2 people have to spend.\n\nNote that you can hold the meeting only at an integer coordinate.\n\n* * *"}, {"input": "7\n 14 14 2 13 56 2 37", "output": "2354"}]
Print the minimum total stamina the N people have to spend. * * *
s044413808
Wrong Answer
p02767
Input is given from Standard Input in the following format: N X_1 X_2 ... X_N
n = int(input()) za = list(map(int, input().split())) print(za) za_max = max(za) za_min = min(za) kouho = 0 kouho_sum = 0 ans = 9999999999999999999999999999999999999999999999999999999999999999999999999999 for zahyou in range(za_min, za_max + 1): for i in za: kouho = (i - zahyou) * (i - zahyou) kouho_sum = kouho_sum + kouho if ans > kouho_sum: ans = kouho_sum kouho_sum = 0 print(ans)
Statement There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any **integer coordinate**. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting. Find the minimum total points of stamina the N people have to spend.
[{"input": "2\n 1 4", "output": "5\n \n\nAssume the meeting is held at coordinate 2. In this case, the first person\nwill spend (1 - 2)^2 points of stamina, and the second person will spend (4 -\n2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the\nminimum total stamina that the 2 people have to spend.\n\nNote that you can hold the meeting only at an integer coordinate.\n\n* * *"}, {"input": "7\n 14 14 2 13 56 2 37", "output": "2354"}]
Print the minimum total stamina the N people have to spend. * * *
s138147385
Runtime Error
p02767
Input is given from Standard Input in the following format: N X_1 X_2 ... X_N
M = 10**9 + 7 n, a, b = map(int, input().split()) r = (pow(2, n, M) - 1) % M f = c = 1 for i in range(b): f = f * (i + 1) % M c = c * (n - i) % M if i + 1 == a: r = (r - c * pow(f, M - 2, M)) % M print((r - c * pow(f, M - 2, M) % M))
Statement There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any **integer coordinate**. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting. Find the minimum total points of stamina the N people have to spend.
[{"input": "2\n 1 4", "output": "5\n \n\nAssume the meeting is held at coordinate 2. In this case, the first person\nwill spend (1 - 2)^2 points of stamina, and the second person will spend (4 -\n2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the\nminimum total stamina that the 2 people have to spend.\n\nNote that you can hold the meeting only at an integer coordinate.\n\n* * *"}, {"input": "7\n 14 14 2 13 56 2 37", "output": "2354"}]
Print the minimum total stamina the N people have to spend. * * *
s870210322
Wrong Answer
p02767
Input is given from Standard Input in the following format: N X_1 X_2 ... X_N
#!python3.4 # -*- coding: utf-8 -*- # abc156/abc156_c import sys import math s2nn = lambda s: [int(c) for c in s.split(" ")] ss2nn = lambda ss: [int(s) for s in list(ss)] ss2nnn = lambda ss: [s2nn(s) for s in list(ss)] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [i2s() for _ in range(n)] ii2nn = lambda n: ss2nn(ii2ss(n)) ii2nnn = lambda n: ss2nnn(ii2ss(n)) def main(): N = i2n() X = i2nn() ave = math.ceil(sum(X) / N) print(sum(map(lambda x: (x - ave) ** 2, X))) return main()
Statement There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any **integer coordinate**. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting. Find the minimum total points of stamina the N people have to spend.
[{"input": "2\n 1 4", "output": "5\n \n\nAssume the meeting is held at coordinate 2. In this case, the first person\nwill spend (1 - 2)^2 points of stamina, and the second person will spend (4 -\n2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the\nminimum total stamina that the 2 people have to spend.\n\nNote that you can hold the meeting only at an integer coordinate.\n\n* * *"}, {"input": "7\n 14 14 2 13 56 2 37", "output": "2354"}]
Print the minimum total stamina the N people have to spend. * * *
s146025875
Runtime Error
p02767
Input is given from Standard Input in the following format: N X_1 X_2 ... X_N
N = input() People = list(map(int, input().split())) for P in range(1, max(People)): Distance = list(map(lambda x: (x - P) ** 2), People) Total_Distance = sum(Distance) Total_Distance_List = list(Total_Distance) print(min(Total_Distance_List))
Statement There are N people living on a number line. The i-th person lives at coordinate X_i. You are going to hold a meeting that all N people have to attend. The meeting can be held at any **integer coordinate**. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting. Find the minimum total points of stamina the N people have to spend.
[{"input": "2\n 1 4", "output": "5\n \n\nAssume the meeting is held at coordinate 2. In this case, the first person\nwill spend (1 - 2)^2 points of stamina, and the second person will spend (4 -\n2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the\nminimum total stamina that the 2 people have to spend.\n\nNote that you can hold the meeting only at an integer coordinate.\n\n* * *"}, {"input": "7\n 14 14 2 13 56 2 37", "output": "2354"}]
Print the maximum number of participants who can add zabuton to the stack. * * *
s175988693
Runtime Error
p03526
Input is given from Standard Input in the following format: N H_1 P_1 H_2 P_2 : H_N P_N
n = int(input()) men = [list(map(int, input().split())) for _ in range(n)] men.sort(key=lambda x: x[0] + x[1], x[0]) dp = [[0, 0] for _ in range(n + 1)] for i in range(1, n + 1): for j in range(i): if dp[j][0] <= men[i - 1][0]: if dp[j][1] + 1 == dp[i][1]: dp[i][0] = min(dp[i][0], dp[j][0] + men[i - 1][1]) elif dp[j][1] + 1 > dp[i][1]: dp[i][1] = dp[j][1] + 1 dp[i][0] = dp[j][0] + men[i - 1][1] ans = 0 for i in range(1, n + 1): ans = max(ans, dp[i][1]) print(ans)
Statement In the final of CODE FESTIVAL in some year, there are N participants. The _height_ and _power_ of Participant i is H_i and P_i, respectively. Ringo is hosting a game of stacking zabuton (cushions). The participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton. Initially, the stack is empty. When it is Participant i's turn, if there are H_i or less zabuton already stacked, he/she will add exactly P_i zabuton to the stack. Otherwise, he/she will give up and do nothing. Ringo wants to maximize the number of participants who can add zabuton to the stack. How many participants can add zabuton to the stack in the optimal order of participants?
[{"input": "3\n 0 2\n 1 3\n 3 4", "output": "2\n \n\nWhen the participants line up in the same order as the input, Participants 1\nand 3 will be able to add zabuton.\n\nOn the other hand, there is no order such that all three participants can add\nzabuton. Thus, the answer is 2.\n\n* * *"}, {"input": "3\n 2 4\n 3 1\n 4 1", "output": "3\n \n\nWhen the participants line up in the order 2, 3, 1, all of them will be able\nto add zabuton.\n\n* * *"}, {"input": "10\n 1 3\n 8 4\n 8 3\n 9 1\n 6 4\n 2 3\n 4 2\n 9 2\n 8 3\n 0 1", "output": "5"}]
Print the maximum number of participants who can add zabuton to the stack. * * *
s832683819
Runtime Error
p03526
Input is given from Standard Input in the following format: N H_1 P_1 H_2 P_2 : H_N P_N
N = int(input()) HP= [list(map(int,input().split()))+[_index] for _index in range(N)] HP.sort() HP2 = list(HP) HP2.sort(key=lambda x:(x[1],x[0])) #if not HP[-1][0]+HP[-1][1] == max(h+p for h,p in HP): # raise def check(_res): """ >>> check([(9, 1), (0, 1)]) False :param _res: :return: """ tmp_val = 0 for h, p, *_ in _res: if (tmp_val > h): return False tmp_val += p return True #print(HP2) res =[] for h,p,index in HP2: def can_insert(h,p,i): _res =list(res) _res.insert(i,(h,p)) return check(_res) for i in reversed(range(len(res)+1)): if can_insert(h,p,i): res.insert(i,(h,p)) break #else: # break for h,p,index in HP: print(len(res))
Statement In the final of CODE FESTIVAL in some year, there are N participants. The _height_ and _power_ of Participant i is H_i and P_i, respectively. Ringo is hosting a game of stacking zabuton (cushions). The participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton. Initially, the stack is empty. When it is Participant i's turn, if there are H_i or less zabuton already stacked, he/she will add exactly P_i zabuton to the stack. Otherwise, he/she will give up and do nothing. Ringo wants to maximize the number of participants who can add zabuton to the stack. How many participants can add zabuton to the stack in the optimal order of participants?
[{"input": "3\n 0 2\n 1 3\n 3 4", "output": "2\n \n\nWhen the participants line up in the same order as the input, Participants 1\nand 3 will be able to add zabuton.\n\nOn the other hand, there is no order such that all three participants can add\nzabuton. Thus, the answer is 2.\n\n* * *"}, {"input": "3\n 2 4\n 3 1\n 4 1", "output": "3\n \n\nWhen the participants line up in the order 2, 3, 1, all of them will be able\nto add zabuton.\n\n* * *"}, {"input": "10\n 1 3\n 8 4\n 8 3\n 9 1\n 6 4\n 2 3\n 4 2\n 9 2\n 8 3\n 0 1", "output": "5"}]
Print the maximum number of participants who can add zabuton to the stack. * * *
s289161319
Runtime Error
p03526
Input is given from Standard Input in the following format: N H_1 P_1 H_2 P_2 : H_N P_N
def main(): import sys input=sys.stdin.readline n = int(input()) hp = sorted([tuple(map(int, input().split())) for _ in [0]*n], key=lambda x: sum(x)) dp = [10**10]*(n+1) dp[0] = 0 for c, (h, p) in enumerate(hp): for k in range(c, -1, -1): if dp[k] <= h: dp[k+1] = min(dp[k+1], dp[k]+p) for i in range(n, -1, -1): if dp[i] != 10**10: print(i) break if __name__ == '__main__': main()
Statement In the final of CODE FESTIVAL in some year, there are N participants. The _height_ and _power_ of Participant i is H_i and P_i, respectively. Ringo is hosting a game of stacking zabuton (cushions). The participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton. Initially, the stack is empty. When it is Participant i's turn, if there are H_i or less zabuton already stacked, he/she will add exactly P_i zabuton to the stack. Otherwise, he/she will give up and do nothing. Ringo wants to maximize the number of participants who can add zabuton to the stack. How many participants can add zabuton to the stack in the optimal order of participants?
[{"input": "3\n 0 2\n 1 3\n 3 4", "output": "2\n \n\nWhen the participants line up in the same order as the input, Participants 1\nand 3 will be able to add zabuton.\n\nOn the other hand, there is no order such that all three participants can add\nzabuton. Thus, the answer is 2.\n\n* * *"}, {"input": "3\n 2 4\n 3 1\n 4 1", "output": "3\n \n\nWhen the participants line up in the order 2, 3, 1, all of them will be able\nto add zabuton.\n\n* * *"}, {"input": "10\n 1 3\n 8 4\n 8 3\n 9 1\n 6 4\n 2 3\n 4 2\n 9 2\n 8 3\n 0 1", "output": "5"}]
Print the maximum number of participants who can add zabuton to the stack. * * *
s129267170
Wrong Answer
p03526
Input is given from Standard Input in the following format: N H_1 P_1 H_2 P_2 : H_N P_N
n = int(input()) hp = [list(map(int, input().split())) for i in range(n)] hp.sort(key=lambda x: x[0] + x[1]) dp = [[10**18 for i in range(n + 1)] for j in range(n + 1)] dp[0][0] = 0 for i in range(1, n + 1): dp[i] = dp[i - 1][:] h, p = hp[i - 1] for j in range(1, i + 1): if dp[i - 1][j - 1] <= h: dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + p) for i in range(n + 1): if dp[-1][i] == 10**18: print(i - 1) break
Statement In the final of CODE FESTIVAL in some year, there are N participants. The _height_ and _power_ of Participant i is H_i and P_i, respectively. Ringo is hosting a game of stacking zabuton (cushions). The participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton. Initially, the stack is empty. When it is Participant i's turn, if there are H_i or less zabuton already stacked, he/she will add exactly P_i zabuton to the stack. Otherwise, he/she will give up and do nothing. Ringo wants to maximize the number of participants who can add zabuton to the stack. How many participants can add zabuton to the stack in the optimal order of participants?
[{"input": "3\n 0 2\n 1 3\n 3 4", "output": "2\n \n\nWhen the participants line up in the same order as the input, Participants 1\nand 3 will be able to add zabuton.\n\nOn the other hand, there is no order such that all three participants can add\nzabuton. Thus, the answer is 2.\n\n* * *"}, {"input": "3\n 2 4\n 3 1\n 4 1", "output": "3\n \n\nWhen the participants line up in the order 2, 3, 1, all of them will be able\nto add zabuton.\n\n* * *"}, {"input": "10\n 1 3\n 8 4\n 8 3\n 9 1\n 6 4\n 2 3\n 4 2\n 9 2\n 8 3\n 0 1", "output": "5"}]
Print the maximum number of participants who can add zabuton to the stack. * * *
s155546343
Wrong Answer
p03526
Input is given from Standard Input in the following format: N H_1 P_1 H_2 P_2 : H_N P_N
N = int(input()) HP = [list(map(int, input().split())) + [_index] for _index in range(N)] HP.sort() HP2 = list(HP) HP2.sort(key=lambda x: (x[1], -x[0])) # if not HP[-1][0]+HP[-1][1] == max(h+p for h,p in HP): # raise def check(_res): """ >>> check([(9, 1), (0, 1)]) False :param _res: :return: """ tmp_val = 0 for h, p, *_ in _res: if tmp_val > h: return False tmp_val += p return True # print(HP2) res = [] for h, p, index in HP2: def can_insert(h, p, i): _res = list(res) _res.insert(i, (h, p)) return check(_res) for i in reversed(range(len(res) + 1)): if can_insert(h, p, i): res.insert(i, (h, p)) break # else: # break print(len(res))
Statement In the final of CODE FESTIVAL in some year, there are N participants. The _height_ and _power_ of Participant i is H_i and P_i, respectively. Ringo is hosting a game of stacking zabuton (cushions). The participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton. Initially, the stack is empty. When it is Participant i's turn, if there are H_i or less zabuton already stacked, he/she will add exactly P_i zabuton to the stack. Otherwise, he/she will give up and do nothing. Ringo wants to maximize the number of participants who can add zabuton to the stack. How many participants can add zabuton to the stack in the optimal order of participants?
[{"input": "3\n 0 2\n 1 3\n 3 4", "output": "2\n \n\nWhen the participants line up in the same order as the input, Participants 1\nand 3 will be able to add zabuton.\n\nOn the other hand, there is no order such that all three participants can add\nzabuton. Thus, the answer is 2.\n\n* * *"}, {"input": "3\n 2 4\n 3 1\n 4 1", "output": "3\n \n\nWhen the participants line up in the order 2, 3, 1, all of them will be able\nto add zabuton.\n\n* * *"}, {"input": "10\n 1 3\n 8 4\n 8 3\n 9 1\n 6 4\n 2 3\n 4 2\n 9 2\n 8 3\n 0 1", "output": "5"}]
Print the maximum possible sum of the beauties of the remaining flowers. * * *
s728617166
Runtime Error
p03176
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N a_1 a_2 \ldots a_N
n = int(input()) h = list(map(int, input().split())) a = list(map(int, input().split())) dp = [-1] * n def f(x): if dp[x] == -1: maxi = 0 for i in range(x + 1, n): if h[i] < h[x]: continue else: maxi = max(maxi, f(i) + a[x]) maxi = max(maxi, a[x]) dp[x] = maxi return dp[x] print(max([f(i) for i in range(n)])) # print(dp)
Statement There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the following condition is met: * The heights of the remaining flowers are monotonically increasing from left to right. Find the maximum possible sum of the beauties of the remaining flowers.
[{"input": "4\n 3 1 4 2\n 10 20 30 40", "output": "60\n \n\nWe should keep the second and fourth flowers from the left. Then, the heights\nwould be 1, 2 from left to right, which is monotonically increasing, and the\nsum of the beauties would be 20 + 40 = 60.\n\n* * *"}, {"input": "1\n 1\n 10", "output": "10\n \n\nThe condition is met already at the beginning.\n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "9\n 4 2 5 8 3 6 1 7 9\n 6 8 8 4 6 3 5 7 5", "output": "31\n \n\nWe should keep the second, third, sixth, eighth and ninth flowers from the\nleft."}]
Print the maximum possible sum of the beauties of the remaining flowers. * * *
s005787185
Accepted
p03176
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N a_1 a_2 \ldots a_N
# by the authority of GOD author: manhar singh sachdev # import os, sys from io import BytesIO, IOBase from collections import deque def update(seg_tree, val, update_val, x): curr = deque([(1, x, 1)]) while len(curr): y = curr.popleft() if y[0] <= val <= y[1]: seg_tree[y[2]] = max(seg_tree[y[2]], update_val) if y[0] != y[1]: curr.append((y[0], (y[0] + y[1]) // 2, 2 * y[2])) curr.append(((y[0] + y[1]) // 2 + 1, y[1], 2 * y[2] + 1)) def trav(seg_tree, val, x): curr = deque([(1, x, 1)]) ans = 0 while len(curr): y = curr.popleft() if y[1] < val: ans = max(ans, seg_tree[y[2]]) elif y[0] <= val <= y[1] and y[0] != y[1]: curr.append((y[0], (y[0] + y[1]) // 2, 2 * y[2])) curr.append(((y[0] + y[1]) // 2 + 1, y[1], 2 * y[2] + 1)) return ans def main(): n = int(input()) h = list(map(int, input().split())) a = list(map(int, input().split())) x = 1 << n.bit_length() seg_tree = [0] * (x << 1) fin = 0 for i in range(n): k = trav(seg_tree, h[i], x) fin = max(fin, a[i] + k) update(seg_tree, h[i], a[i] + k, x) print(fin) # Fast IO Region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main()
Statement There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the following condition is met: * The heights of the remaining flowers are monotonically increasing from left to right. Find the maximum possible sum of the beauties of the remaining flowers.
[{"input": "4\n 3 1 4 2\n 10 20 30 40", "output": "60\n \n\nWe should keep the second and fourth flowers from the left. Then, the heights\nwould be 1, 2 from left to right, which is monotonically increasing, and the\nsum of the beauties would be 20 + 40 = 60.\n\n* * *"}, {"input": "1\n 1\n 10", "output": "10\n \n\nThe condition is met already at the beginning.\n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "9\n 4 2 5 8 3 6 1 7 9\n 6 8 8 4 6 3 5 7 5", "output": "31\n \n\nWe should keep the second, third, sixth, eighth and ninth flowers from the\nleft."}]
Print the maximum possible sum of the beauties of the remaining flowers. * * *
s905469573
Accepted
p03176
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N a_1 a_2 \ldots a_N
class NumArray(object): def __init__(self, nums): self.l = len(nums) self.tree = [0] * self.l + nums for i in range(self.l - 1, 0, -1): self.tree[i] = max(self.tree[i << 1], self.tree[i << 1 | 1]) def update(self, i, val): n = self.l + i self.tree[n] = val while n > 1: self.tree[n >> 1] = max(self.tree[n], self.tree[n ^ 1]) n >>= 1 def maxRange(self, i, j): m = self.l + i n = self.l + j res = 0 while m <= n: if m & 1: # res += self.tree[m] res = max(res, self.tree[m]) m += 1 m >>= 1 if n & 1 == 0: # res += self.tree[n] res = max(res, self.tree[n]) n -= 1 n >>= 1 return res N = int(input()) H = list(map(int, input().strip().split(" "))) V = list(map(int, input().strip().split(" "))) Ans = NumArray([0] * (N + 1)) for i in range(len(H)): h = H[i] ans1 = Ans.maxRange(0, h - 1) + V[i] Ans.update(h, ans1) print(max(Ans.tree))
Statement There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the following condition is met: * The heights of the remaining flowers are monotonically increasing from left to right. Find the maximum possible sum of the beauties of the remaining flowers.
[{"input": "4\n 3 1 4 2\n 10 20 30 40", "output": "60\n \n\nWe should keep the second and fourth flowers from the left. Then, the heights\nwould be 1, 2 from left to right, which is monotonically increasing, and the\nsum of the beauties would be 20 + 40 = 60.\n\n* * *"}, {"input": "1\n 1\n 10", "output": "10\n \n\nThe condition is met already at the beginning.\n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "9\n 4 2 5 8 3 6 1 7 9\n 6 8 8 4 6 3 5 7 5", "output": "31\n \n\nWe should keep the second, third, sixth, eighth and ninth flowers from the\nleft."}]
Print the maximum possible sum of the beauties of the remaining flowers. * * *
s954178029
Accepted
p03176
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N a_1 a_2 \ldots a_N
class SegTree: def __init__(self, N): # N: ๅ‡ฆ็†ใ™ใ‚‹ๅŒบ้–“ใฎ้•ทใ• self.N0 = 2 ** (N - 1).bit_length() self.INF = 2**31 - 1 self.seg_max = [-self.INF] * (2 * self.N0) def update(self, index, value): index += self.N0 - 1 self.seg_max[index] = value while index > 0: index = (index - 1) // 2 self.seg_max[index] = max( self.seg_max[index * 2 + 1], self.seg_max[index * 2 + 2] ) def query(self, first, last): first += self.N0 - 1 last += self.N0 - 1 ret = -self.INF while first <= last: if not first & 1: ret = max(ret, self.seg_max[first]) if last & 1: ret = max(ret, self.seg_max[last]) first = first // 2 last = last // 2 - 1 return ret N = int(input()) h = list(map(int, input().split())) a = list(map(int, input().split())) rnk2idx = {} for i in range(N): rnk2idx[h[i]] = i + 1 segtree = SegTree(N + 1) for i in range(1, N + 1): segtree.update(i, 0) for i in range(1, N + 1): idx = rnk2idx[i] segtree.update(idx, segtree.query(1, idx) + a[idx - 1]) print(segtree.query(1, N))
Statement There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the following condition is met: * The heights of the remaining flowers are monotonically increasing from left to right. Find the maximum possible sum of the beauties of the remaining flowers.
[{"input": "4\n 3 1 4 2\n 10 20 30 40", "output": "60\n \n\nWe should keep the second and fourth flowers from the left. Then, the heights\nwould be 1, 2 from left to right, which is monotonically increasing, and the\nsum of the beauties would be 20 + 40 = 60.\n\n* * *"}, {"input": "1\n 1\n 10", "output": "10\n \n\nThe condition is met already at the beginning.\n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "9\n 4 2 5 8 3 6 1 7 9\n 6 8 8 4 6 3 5 7 5", "output": "31\n \n\nWe should keep the second, third, sixth, eighth and ninth flowers from the\nleft."}]
Print the maximum possible sum of the beauties of the remaining flowers. * * *
s123299357
Runtime Error
p03176
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N a_1 a_2 \ldots a_N
import math def makeTree(x, y): if y > x: T[(x, (x + y) // 2)] = 0 makeTree(x, (x + y) // 2) T[((x + y) // 2 + 1, y)] = 0 makeTree((x + y) // 2 + 1, y) def rmq(r, l, x, y): if l < x or r > y: return 0 if r <= x and y <= l: return T[(x, y)] return max(rmq(r, l, x, (x + y) // 2), rmq(r, l, (x + y) // 2 + 1, y)) def udTree(i): T[(i, i)] = dp[i] x = i y = i d = 1 while d < 2**n: if x % (2 * d) == 0: T[(x, x + 2 * d - 1)] = max(T[(x, x + 2 * d - 1)], T[(x, y)]) y = x + 2 * d - 1 else: T[(y - 2 * d + 1, y)] = max(T[(y - 2 * d + 1, y)], T[(x, y)]) x = y - 2 * d + 1 d = y - x + 1 N = int(input()) H = list(map(int, input().split())) A = list(map(int, input().split())) Ho = [(i, H[i]) for i in range(N)] Ho = sorted(Ho, key=lambda x: x[1]) dp = [0 for i in range(N)] n = math.ceil(math.log2(N)) T = {} T[(0, 2**n - 1)] = 0 makeTree(0, 2**n - 1) for i in range(N): ind = Ho[i][0] if ind == 0: dp[ind] = A[ind] udTree(ind) else: dp[ind] = rmq(0, ind - 1, 0, 2**n - 1) + A[ind] udTree(ind) print(T[(0, 2**n - 1)])
Statement There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the following condition is met: * The heights of the remaining flowers are monotonically increasing from left to right. Find the maximum possible sum of the beauties of the remaining flowers.
[{"input": "4\n 3 1 4 2\n 10 20 30 40", "output": "60\n \n\nWe should keep the second and fourth flowers from the left. Then, the heights\nwould be 1, 2 from left to right, which is monotonically increasing, and the\nsum of the beauties would be 20 + 40 = 60.\n\n* * *"}, {"input": "1\n 1\n 10", "output": "10\n \n\nThe condition is met already at the beginning.\n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "9\n 4 2 5 8 3 6 1 7 9\n 6 8 8 4 6 3 5 7 5", "output": "31\n \n\nWe should keep the second, third, sixth, eighth and ninth flowers from the\nleft."}]
Print the maximum possible sum of the beauties of the remaining flowers. * * *
s423314894
Accepted
p03176
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N a_1 a_2 \ldots a_N
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(2147483647) INF = 10**20 def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() def S(): return sys.stdin.buffer.readline().rstrip().decode("utf-8") def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 class BIT: def __init__(self, size): self.bit = [0] * size self.size = size self.total = 0 def add(self, i, w): x = i + 1 self.total += w while x <= self.size: self.bit[x - 1] = max(self.bit[x - 1], w) x += x & -x return def sum(self, i): res = 0 x = i + 1 while x: res = max(res, self.bit[x - 1]) x -= x & -x return res n = I() H = LI() A = LI() D = {e: i for i, e in enumerate(sorted(H))} bit = BIT(n) for i in range(n): idx = D[H[i]] bit.add(idx, bit.sum(idx) + A[i]) print(bit.sum(n - 1))
Statement There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the following condition is met: * The heights of the remaining flowers are monotonically increasing from left to right. Find the maximum possible sum of the beauties of the remaining flowers.
[{"input": "4\n 3 1 4 2\n 10 20 30 40", "output": "60\n \n\nWe should keep the second and fourth flowers from the left. Then, the heights\nwould be 1, 2 from left to right, which is monotonically increasing, and the\nsum of the beauties would be 20 + 40 = 60.\n\n* * *"}, {"input": "1\n 1\n 10", "output": "10\n \n\nThe condition is met already at the beginning.\n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "9\n 4 2 5 8 3 6 1 7 9\n 6 8 8 4 6 3 5 7 5", "output": "31\n \n\nWe should keep the second, third, sixth, eighth and ninth flowers from the\nleft."}]
Print the maximum possible sum of the beauties of the remaining flowers. * * *
s129111088
Accepted
p03176
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N a_1 a_2 \ldots a_N
n, *a = map(int, open(0).read().split()) d = [0] * -~n for h, a in zip(a, a[n:]): i, s = h, 0 while i: s = max(s, d[i]) i -= i & -i s += a i = h while i <= n: d[i] = max(d[i], s) i += i & -i print(max(d))
Statement There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the following condition is met: * The heights of the remaining flowers are monotonically increasing from left to right. Find the maximum possible sum of the beauties of the remaining flowers.
[{"input": "4\n 3 1 4 2\n 10 20 30 40", "output": "60\n \n\nWe should keep the second and fourth flowers from the left. Then, the heights\nwould be 1, 2 from left to right, which is monotonically increasing, and the\nsum of the beauties would be 20 + 40 = 60.\n\n* * *"}, {"input": "1\n 1\n 10", "output": "10\n \n\nThe condition is met already at the beginning.\n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "9\n 4 2 5 8 3 6 1 7 9\n 6 8 8 4 6 3 5 7 5", "output": "31\n \n\nWe should keep the second, third, sixth, eighth and ninth flowers from the\nleft."}]
Print the maximum possible sum of the beauties of the remaining flowers. * * *
s174774588
Accepted
p03176
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N a_1 a_2 \ldots a_N
import sys input = sys.stdin.readline n = int(input()) h = [int(i) for i in input().split()] a = [int(i) for i in input().split()] sellogn = [] seln = 0 selfunc = max selone = 0 selb = [] def __init__(a, func=max, one=-(10**18)): global sellogn, seln, selfunc, selone, selb sellogn = (len(a) - 1).bit_length() seln = 1 << sellogn selfunc = func selone = one selb = [selone] * (2 * seln - 1) for i, j in enumerate(a): selb[i + seln - 1] = j for i in reversed(range(seln - 1)): selb[i] = selfunc(selb[i * 2 + 1], selb[i * 2 + 2]) def get_item(i): global sellogn, seln, selfunc, selone, selb return selb[i + seln - 1] def update(index, x): global sellogn, seln, selfunc, selone, selb i = index + seln - 1 selb[i] = x while i != 0: i = (i - 1) // 2 selb[i] = selfunc(selb[i * 2 + 1], selb[i * 2 + 2]) def update_func(index, x): global sellogn, seln, selfunc, selone, selb i = index + seln - 1 selb[i] = selfunc(selb[i], x) while i != 0: i = (i - 1) // 2 selb[i] = selfunc(selb[i * 2 + 1], selb[i * 2 + 2]) def get_segment(l, r): global sellogn, seln, selfunc, selone, selb l += seln r += seln s = selone t = selone while l < r: if l & 1: s = selfunc(s, selb[l - 1]) l += 1 if r & 1: r -= 1 t = selfunc(selb[r - 1], t) l >>= 1 r >>= 1 return selfunc(s, t) __init__([0] * (n + 1)) for i in range(n): j = get_segment(0, h[i] + 1) update_func(h[i], j + a[i]) print(get_segment(0, n + 1))
Statement There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the following condition is met: * The heights of the remaining flowers are monotonically increasing from left to right. Find the maximum possible sum of the beauties of the remaining flowers.
[{"input": "4\n 3 1 4 2\n 10 20 30 40", "output": "60\n \n\nWe should keep the second and fourth flowers from the left. Then, the heights\nwould be 1, 2 from left to right, which is monotonically increasing, and the\nsum of the beauties would be 20 + 40 = 60.\n\n* * *"}, {"input": "1\n 1\n 10", "output": "10\n \n\nThe condition is met already at the beginning.\n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "9\n 4 2 5 8 3 6 1 7 9\n 6 8 8 4 6 3 5 7 5", "output": "31\n \n\nWe should keep the second, third, sixth, eighth and ninth flowers from the\nleft."}]
Print the maximum possible sum of the beauties of the remaining flowers. * * *
s260262311
Runtime Error
p03176
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N a_1 a_2 \ldots a_N
from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline M = mod = 10**9 + 7 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip('\n').split()] def st():return input().rstrip('\n') def val():return int(input().rstrip('\n')) def li2():return [i for i in input().rstrip('\n')] def li3():return [int(i) for i in input().rstrip('\n')] class Node: def __init__(self,s,e): self.start=s self.end=e self.val = 0 self.left=None self.right=None def build(nums,l,r): if l == r: temp = Node(l,l) temp.val = 0 else: mid=(l+r)>>1 temp=Node(l,r) temp.left=build(nums,l,mid) temp.right=build(nums,mid+1,r) temp.val = temp.left.val + temp.right.val return temp def update(root,start,va): if root.start==root.end==start: root.val = va elif root.start<=start and root.end>=start: root.left=update(root.left,start,va) root.right=update(root.right,start,va) root.val = max(root.left.val,root.right.val) return root def query(root,start,end): if root.start>=start and root.end<=end:return root.val elif root.start>end or root.end<start:return 0 else: temp1 = query(root.left,start,end) temp2 = query(root.right,start,end) return max(temp1,temp2) root = build([],0,200005) n = val() h = li() a = li() ans = 0 for i in range(n): curr = query(root,-1,h[i]) temp = curr + a[i] ans = max(ans,temp) root = update(root,h[i],temp) print(ans)from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline M = mod = 10**9 + 7 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip('\n').split()] def st():return input().rstrip('\n') def val():return int(input().rstrip('\n')) def li2():return [i for i in input().rstrip('\n')] def li3():return [int(i) for i in input().rstrip('\n')] class Node: def __init__(self,s,e): self.start=s self.end=e self.val = 0 self.left=None self.right=None def build(nums,l,r): if l == r: temp = Node(l,l) temp.val = 0 else: mid=(l+r)>>1 temp=Node(l,r) temp.left=build(nums,l,mid) temp.right=build(nums,mid+1,r) temp.val = temp.left.val + temp.right.val return temp def update(root,start,va): if root.start==root.end==start: root.val = va elif root.start<=start and root.end>=start: root.left=update(root.left,start,va) root.right=update(root.right,start,va) root.val = max(root.left.val,root.right.val) return root def query(root,start,end): if root.start>=start and root.end<=end:return root.val elif root.start>end or root.end<start:return 0 else: temp1 = query(root.left,start,end) temp2 = query(root.right,start,end) return max(temp1,temp2) root = build([],0,200005) n = val() h = li() a = li() ans = 0 for i in range(n): curr = query(root,-1,h[i]) temp = curr + a[i] ans = max(ans,temp) root = update(root,h[i],temp) print(ans)
Statement There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the following condition is met: * The heights of the remaining flowers are monotonically increasing from left to right. Find the maximum possible sum of the beauties of the remaining flowers.
[{"input": "4\n 3 1 4 2\n 10 20 30 40", "output": "60\n \n\nWe should keep the second and fourth flowers from the left. Then, the heights\nwould be 1, 2 from left to right, which is monotonically increasing, and the\nsum of the beauties would be 20 + 40 = 60.\n\n* * *"}, {"input": "1\n 1\n 10", "output": "10\n \n\nThe condition is met already at the beginning.\n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "9\n 4 2 5 8 3 6 1 7 9\n 6 8 8 4 6 3 5 7 5", "output": "31\n \n\nWe should keep the second, third, sixth, eighth and ninth flowers from the\nleft."}]
Print the maximum possible sum of the beauties of the remaining flowers. * * *
s967248776
Runtime Error
p03176
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N a_1 a_2 \ldots a_N
n, m = map(int, input().split()) INF = 10**9 d = [[INF] * n for i in range(n)] for i in range(n): d[i][i] = 0 for i in range(m): a, b = map(int, input().split()) d[a - 1][b - 1] = 1 d[b - 1][a - 1] = 1 for i in range(n): for j in range(n): for k in range(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) for i in d: print(i.count(2))
Statement There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the following condition is met: * The heights of the remaining flowers are monotonically increasing from left to right. Find the maximum possible sum of the beauties of the remaining flowers.
[{"input": "4\n 3 1 4 2\n 10 20 30 40", "output": "60\n \n\nWe should keep the second and fourth flowers from the left. Then, the heights\nwould be 1, 2 from left to right, which is monotonically increasing, and the\nsum of the beauties would be 20 + 40 = 60.\n\n* * *"}, {"input": "1\n 1\n 10", "output": "10\n \n\nThe condition is met already at the beginning.\n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "9\n 4 2 5 8 3 6 1 7 9\n 6 8 8 4 6 3 5 7 5", "output": "31\n \n\nWe should keep the second, third, sixth, eighth and ninth flowers from the\nleft."}]
Print the maximum possible sum of the beauties of the remaining flowers. * * *
s137413335
Accepted
p03176
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N a_1 a_2 \ldots a_N
import operator class SegmentTree: def __init__(self, size, fn=operator.add, default=None, initial_values=None): """ :param int size: :param callable fn: ๅŒบ้–“ใซ้ฉ็”จใ™ใ‚‹้–ขๆ•ฐใ€‚ๅผ•ๆ•ฐใ‚’ 2 ใคๅ–ใ‚‹ใ€‚min, max, operator.xor ใชใฉ :param default: :param list initial_values: """ default = default or 0 # size ไปฅไธŠใงใ‚ใ‚‹ๆœ€ๅฐใฎ 2 ๅ†ชใ‚’ size ใจใ™ใ‚‹ n = 1 while n < size: n *= 2 self._size = n self._fn = fn self._tree = [default] * (self._size * 2 - 1) if initial_values: i = self._size - 1 for v in initial_values: self._tree[i] = v i += 1 i = self._size - 2 while i >= 0: self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2]) i -= 1 def set(self, i, value): """ i ็•ช็›ฎใซ value ใ‚’่จญๅฎš :param int i: :param 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 update(self, i, value): """ ใ‚‚ใจใฎ i ็•ช็›ฎใจ value ใซ fn ใ‚’้ฉ็”จใ—ใŸใ‚‚ใฎใ‚’ i ็•ช็›ฎใซ่จญๅฎš :param int i: :param value: :return: """ x = self._size - 1 + i self.set(i, self._fn(self._tree[x], value)) def get(self, from_i, to_i=None, 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: """ if to_i is None: return self._tree[self._size - 1 + from_i] 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 def resolve(): N = int(input()) H = list(map(int, input().split())) A = list(map(int, input().split())) Flowers = [] for i in range(N): Flowers.append((H[i], (A[i], i))) # ้ซ˜ใ•ใ‚’ๆ˜‡้ †ใซใ‚ฝใƒผใƒˆ Flowers.sort() seg = SegmentTree(N, fn=max) for i in range(N): h, (a, idx) = Flowers[i] maxV = seg.get(0, idx) # l=0, r=0 ใฎๆ™‚Noneใ‚’่ฟ”ใ™ไป•ๆง˜ if maxV == None: maxV = 0 seg.set(idx, maxV + a) ans = seg.get(0, N) print(ans) if __name__ == "__main__": resolve()
Statement There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the following condition is met: * The heights of the remaining flowers are monotonically increasing from left to right. Find the maximum possible sum of the beauties of the remaining flowers.
[{"input": "4\n 3 1 4 2\n 10 20 30 40", "output": "60\n \n\nWe should keep the second and fourth flowers from the left. Then, the heights\nwould be 1, 2 from left to right, which is monotonically increasing, and the\nsum of the beauties would be 20 + 40 = 60.\n\n* * *"}, {"input": "1\n 1\n 10", "output": "10\n \n\nThe condition is met already at the beginning.\n\n* * *"}, {"input": "5\n 1 2 3 4 5\n 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "9\n 4 2 5 8 3 6 1 7 9\n 6 8 8 4 6 3 5 7 5", "output": "31\n \n\nWe should keep the second, third, sixth, eighth and ninth flowers from the\nleft."}]
Print the number of possible ways to write integers, modulo 998244353. * * *
s474404875
Wrong Answer
p03199
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 : a_M b_M c_M
N, M = map(int, input().split()) mod = 998244353 factorial = [1 for i in range(2 * N + 1)] for i in range(1, 2 * N + 1): if i == 1: factorial[i] = 1 else: factorial[i] = factorial[i - 1] * i % mod def comb(n, k): return (factorial[n] * pow(factorial[n - k] * factorial[k], -1, mod)) % mod memo = [[0] * 2 for _ in range(N)] for i in range(M): a, b, c = map(int, input().split()) memo[max(a, b) - 1][c] += 1 ans = 0 for i in range(N - 1, 0, -1): tmp = 0 n_margin = 2 * (i + 1) - 1 - sum(memo[i]) if (memo[i][1] - memo[i - 1][1]) % 2: if memo[i][1] % 2: for j in range(0, n_margin + 1, 2): tmp += comb(n_margin, j) else: for j in range(1, n_margin + 1, 2): tmp += comb(n_margin, j) else: if memo[i][1] % 2: for j in range(1, n_margin + 1, 2): tmp += comb(n_margin, j) else: for j in range(0, n_margin + 1, 2): tmp += comb(n_margin, j) print(i, n_margin, tmp, sum(memo[i])) ans += tmp ans %= mod print(ans)
Statement Takahashi has an N \times N grid. The square at the i-th row and the j-th column of the grid is denoted by (i,j). Particularly, the top-left square of the grid is (1,1), and the bottom-right square is (N,N). An integer, 0 or 1, is written on M of the squares in the Takahashi's grid. Three integers a_i,b_i and c_i describe the i-th of those squares with integers written on them: the integer c_i is written on the square (a_i,b_i). Takahashi decides to write an integer, 0 or 1, on each of the remaining squares so that the condition below is satisfied. Find the number of such ways to write integers, modulo 998244353. * For all 1\leq i < j\leq N, there are even number of 1s in the square region whose top-left square is (i,i) and whose bottom-right square is (j,j).
[{"input": "3 3\n 1 1 1\n 3 1 0\n 2 3 1", "output": "8\n \n\nFor example, the following ways to write integers satisfy the condition:\n\n \n \n 101 111\n 011 111\n 000 011\n \n\n* * *"}, {"input": "4 5\n 1 3 1\n 2 4 0\n 2 3 1\n 4 2 1\n 4 4 1", "output": "32\n \n\n* * *"}, {"input": "3 5\n 1 3 1\n 3 3 0\n 3 1 0\n 2 3 1\n 3 2 1", "output": "0\n \n\n* * *"}, {"input": "4 8\n 1 1 1\n 1 2 0\n 3 2 1\n 1 4 0\n 2 1 1\n 1 3 0\n 3 4 1\n 4 4 1", "output": "4\n \n\n* * *"}, {"input": "100000 0", "output": "342016343"}]
Print the number of possible ways to write integers, modulo 998244353. * * *
s057412425
Runtime Error
p03199
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 : a_M b_M c_M
from collections import defaultdict Q = 998244353 D = defaultdict(int) N, M = map(int, input().split()) L = (N**2 - N) // 2 Ld = N ans = 1 diag = [-1] * (N + 1) A = [(0, 0, 0)] * M for _ in range(M): a, b, c = map(int, input().split()) if a == b: D[(a, b)] = c + 2 Ld -= 1 else: L -= 1 D[(a, b)] = c + 2 for i in range(N - 1): if ( D[(i, i)] >= 2 and D[(i, i + 1)] >= 2 and D[(i + 1, i)] >= 2 and D[(i + 1, i + 1)] >= 2 ): if not (D[(i, i)] + D[(i, i + 1)] + D[(i + 1, i)] + D[(i + 1, i + 1)]) % 2 == 0: ans = 0 print(ans * pow(2, L + Ld, Q))
Statement Takahashi has an N \times N grid. The square at the i-th row and the j-th column of the grid is denoted by (i,j). Particularly, the top-left square of the grid is (1,1), and the bottom-right square is (N,N). An integer, 0 or 1, is written on M of the squares in the Takahashi's grid. Three integers a_i,b_i and c_i describe the i-th of those squares with integers written on them: the integer c_i is written on the square (a_i,b_i). Takahashi decides to write an integer, 0 or 1, on each of the remaining squares so that the condition below is satisfied. Find the number of such ways to write integers, modulo 998244353. * For all 1\leq i < j\leq N, there are even number of 1s in the square region whose top-left square is (i,i) and whose bottom-right square is (j,j).
[{"input": "3 3\n 1 1 1\n 3 1 0\n 2 3 1", "output": "8\n \n\nFor example, the following ways to write integers satisfy the condition:\n\n \n \n 101 111\n 011 111\n 000 011\n \n\n* * *"}, {"input": "4 5\n 1 3 1\n 2 4 0\n 2 3 1\n 4 2 1\n 4 4 1", "output": "32\n \n\n* * *"}, {"input": "3 5\n 1 3 1\n 3 3 0\n 3 1 0\n 2 3 1\n 3 2 1", "output": "0\n \n\n* * *"}, {"input": "4 8\n 1 1 1\n 1 2 0\n 3 2 1\n 1 4 0\n 2 1 1\n 1 3 0\n 3 4 1\n 4 4 1", "output": "4\n \n\n* * *"}, {"input": "100000 0", "output": "342016343"}]
Print the number of possible ways to write integers, modulo 998244353. * * *
s761233573
Runtime Error
p03199
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 : a_M b_M c_M
N, M = map(int, input().strip().split(" ")) assert M == 0 print(pow(2, (N**2 - N * (N - 1) // 2), 998244353))
Statement Takahashi has an N \times N grid. The square at the i-th row and the j-th column of the grid is denoted by (i,j). Particularly, the top-left square of the grid is (1,1), and the bottom-right square is (N,N). An integer, 0 or 1, is written on M of the squares in the Takahashi's grid. Three integers a_i,b_i and c_i describe the i-th of those squares with integers written on them: the integer c_i is written on the square (a_i,b_i). Takahashi decides to write an integer, 0 or 1, on each of the remaining squares so that the condition below is satisfied. Find the number of such ways to write integers, modulo 998244353. * For all 1\leq i < j\leq N, there are even number of 1s in the square region whose top-left square is (i,i) and whose bottom-right square is (j,j).
[{"input": "3 3\n 1 1 1\n 3 1 0\n 2 3 1", "output": "8\n \n\nFor example, the following ways to write integers satisfy the condition:\n\n \n \n 101 111\n 011 111\n 000 011\n \n\n* * *"}, {"input": "4 5\n 1 3 1\n 2 4 0\n 2 3 1\n 4 2 1\n 4 4 1", "output": "32\n \n\n* * *"}, {"input": "3 5\n 1 3 1\n 3 3 0\n 3 1 0\n 2 3 1\n 3 2 1", "output": "0\n \n\n* * *"}, {"input": "4 8\n 1 1 1\n 1 2 0\n 3 2 1\n 1 4 0\n 2 1 1\n 1 3 0\n 3 4 1\n 4 4 1", "output": "4\n \n\n* * *"}, {"input": "100000 0", "output": "342016343"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s331575266
Runtime Error
p03463
Input is given from Standard Input in the following format: N A B
n, a, b = map(int, input().split()) if (n + b) % 2 == 0: print("Alice") elif (n + b) % 2 != 0: print("Bor
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s388788618
Accepted
p03463
Input is given from Standard Input in the following format: N A B
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 # A def A(): n, a, b = LI() if (b - a) % 2: print("Borys") else: print("Alice") return # B def B(): def f(m): if d[m] != None: return d[m] n = m for i in a: n = n - n % i d[m] = n return n k = I() a = LI() d = defaultdict(lambda: None) l, r = 0, int(1e18) while r - l > 1: m = (r + l) // 2 if f(m) < 2: l = m else: r = m mi = r l, r = 0, int(1e18) while r - l > 1: m = (r + l) // 2 if f(m) <= 2: l = m else: r = m ma = l if mi <= ma: if f(mi) != 2: print(-1) else: print(mi, ma) else: print(-1) return # C def C(): n = I() return # D def D(): n = I() return # E def E(): n = I() return # F def F(): n = I() return # Solve if __name__ == "__main__": A()
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s113465299
Accepted
p03463
Input is given from Standard Input in the following format: N A B
import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from decimal import * from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9 + 7 INF = float("inf") # ็„ก้™ๅคง def gcd(a, b): return fractions.gcd(a, b) # ๆœ€ๅคงๅ…ฌ็ด„ๆ•ฐ def lcm(a, b): return (a * b) // fractions.gcd(a, b) # ๆœ€ๅฐๅ…ฌๅ€ๆ•ฐ def iin(): return int(sys.stdin.readline()) # ๆ•ดๆ•ฐ่ชญใฟ่พผใฟ def ifn(): return float(sys.stdin.readline()) # ๆตฎๅ‹•ๅฐๆ•ฐ็‚น่ชญใฟ่พผใฟ def isn(): return sys.stdin.readline().split() # ๆ–‡ๅญ—ๅˆ—่ชญใฟ่พผใฟ def imn(): return map(int, sys.stdin.readline().split()) # ๆ•ดๆ•ฐmapๅ–ๅพ— def imnn(): return map(lambda x: int(x) - 1, sys.stdin.readline().split()) # ๆ•ดๆ•ฐ-1mapๅ–ๅพ— def fmn(): return map(float, sys.stdin.readline().split()) # ๆตฎๅ‹•ๅฐๆ•ฐ็‚นmapๅ–ๅพ— def iln(): return list(map(int, sys.stdin.readline().split())) # ๆ•ดๆ•ฐใƒชใ‚นใƒˆๅ–ๅพ— def iln_s(): return sorted(iln()) # ๆ˜‡้ †ใฎๆ•ดๆ•ฐใƒชใ‚นใƒˆๅ–ๅพ— def iln_r(): return sorted(iln(), reverse=True) # ้™้ †ใฎๆ•ดๆ•ฐใƒชใ‚นใƒˆๅ–ๅพ— def fln(): return list(map(float, sys.stdin.readline().split())) # ๆตฎๅ‹•ๅฐๆ•ฐ็‚นใƒชใ‚นใƒˆๅ–ๅพ— def join(l, s=""): return s.join(l) # ใƒชใ‚นใƒˆใ‚’ๆ–‡ๅญ—ๅˆ—ใซๅค‰ๆ› def perm(l, n): return itertools.permutations(l, n) # ้ †ๅˆ—ๅ–ๅพ— def perm_count(n, r): return math.factorial(n) // math.factorial(n - r) # ้ †ๅˆ—ใฎ็ทๆ•ฐ def comb(l, n): return itertools.combinations(l, n) # ็ต„ใฟๅˆใ‚ใ›ๅ–ๅพ— def comb_count(n, r): return math.factorial(n) // ( math.factorial(n - r) * math.factorial(r) ) # ็ต„ใฟๅˆใ‚ใ›ใฎ็ทๆ•ฐ def two_distance(a, b, c, d): return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2็‚น้–“ใฎ่ท้›ข def m_add(a, b): return (a + b) % MOD def print_list(l): print(*l, sep="\n") def sieves_of_e(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return is_prime N, A, B = imn() if (B - A) % 2 == 0: print("Alice") else: print("Borys")
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s313091133
Wrong Answer
p03463
Input is given from Standard Input in the following format: N A B
import math import queue from collections import defaultdict def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() def factorization(n): res = [] if n % 2 == 0: res.append(2) for i in range(3, math.floor(n // 2) + 1, 2): if n % i == 0: c = 0 for j in res: if i % j == 0: c = 1 if c == 0: res.append(i) return res def fact2(n): p = factorization(n) res = [] for i in p: c = 0 z = n while 1: if z % i == 0: c += 1 z /= i else: break res.append([i, c]) return res def fact(n): # ้šŽไน— ans = 1 m = n for _i in range(n - 1): ans *= m m -= 1 return ans def comb(n, r): # ใ‚ณใƒณใƒ“ใƒใƒผใ‚ทใƒงใƒณ if n < r: return 0 l = min(r, n - r) m = n u = 1 for _i in range(l): u *= m m -= 1 return u // fact(l) def printQueue(q): r = qb ans = [0] * r.qsize() for i in range(r.qsize() - 1, -1, -1): ans[i] = r.get() print(ans) def dq(): return queue.deque() class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): # root if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -1 * self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): # much time root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} # 1~n def bitArr(n): # ใƒ“ใƒƒใƒˆๅ…จๆŽข็ดข x = 1 zero = "0" * n ans = [] ans.append([0] * n) for i in range(2**n - 1): ans.append(list(map(lambda x: int(x), list((zero + bin(x)[2:])[-1 * n :])))) x += 1 return ans def arrsSum(a1, a2): for i in range(len(a1)): a1[i] += a2[i] return a1 def maxValue(a, b, v): v2 = v for i in range(v2, -1, -1): for j in range(v2 // a + 1): # j:aใฎๅ€‹ๆ•ฐ k = i - a * j if k % b == 0: return i return -1 n, a, b = readInts() if b - a - 1 % 2 == 1: print("Alice") else: print("Borys")
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s893445233
Accepted
p03463
Input is given from Standard Input in the following format: N A B
print("ABloircyes"[eval(input()[2:].replace(" ", "-")) % 2 :: 2])
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s165863628
Wrong Answer
p03463
Input is given from Standard Input in the following format: N A B
print("Borys")
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s512471402
Runtime Error
p03463
Input is given from Standard Input in the following format: N A B
N, A, B = map(int, input().split()) if (A-B) % 2 == 0: print("Alice) else: print("Borys")
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s144101209
Runtime Error
p03463
Input is given from Standard Input in the following format: N A B
N, A, B = map(int, input().split()) elif (B - A) % 2 == 0: print('Alice') else: print('Borys')
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s559208902
Runtime Error
p03463
Input is given from Standard Input in the following format: N A B
print('Draw')n, a, b = map(int, input().split()) if (b-a) % 2 == 0: ans = 'Alice' else: ans = 'Borys' print(ans)
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s254807099
Runtime Error
p03463
Input is given from Standard Input in the following format: N A B
n,a,b = map(int, input().split()) if b - a % 2 == 0: print("Alice") elif b - a % 2 == 1 print("Borys")
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s832436942
Runtime Error
p03463
Input is given from Standard Input in the following format: N A B
n,a,b = map(int, input().split()) if b - a % 2 == 0: print("Alice") elif b - a % 2 == 1 print("Borys")
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s542804191
Wrong Answer
p03463
Input is given from Standard Input in the following format: N A B
def getinputdata(): array_result = [] data = input() array_result.append(data.split(" ")) flg = 1 try: while flg: data = input() if data != "": array_result.append(data.split(" ")) flg = 1 else: flg = 0 finally: return array_result arr_data = getinputdata() # ใพใ™ใฎๆ•ฐ n = int(arr_data[0][0]) # ใ‚ขใƒชใ‚นใฎ้ง’ใฏใƒžใ‚นใฎไฝ็ฝฎ a = int(arr_data[0][1]) # ใƒœใƒชใ‚นใฎ้ง’ใฏๅˆฅใฎใƒžใ‚นใฎไฝ็ฝฎ b = int(arr_data[0][2]) print("Alice" if b - a % 2 == 0 else "Borys")
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s467246268
Runtime Error
p03463
Input is given from Standard Input in the following format: N A B
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <string> #include <sstream> #include <complex> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <array> #include <tuple> #include <random> using namespace std; typedef long long int ll; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for(int i = int(a); i < int(b); i++) #define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define INF 10000000000 ll a, b, c, n, m, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF; string s; int main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n >> a >> b; cout << ((abs(a - b - 1) % 2) ? "Alice" : "Borys") << endl; }
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s425031896
Runtime Error
p03463
Input is given from Standard Input in the following format: N A B
K = int(input()) A = [int(i) for i in input().split()] Max, Min = 0, 0 error = -1 def N_max(a, Max, Min): if Max > a and Min % a != 0: return a * (Min // a + 2) - 1 elif Max > a and Min % a == 0: return a * (Min // a + 1) - 1 else: return a * 2 - 1 def N_min(a, m): if m > a: return a * (m // a + 1) else: return a for i in range(K)[::-1]: if A[-1] == 2: if i == 0: # ๆœ€ๅพŒใฎๅ‡ฆ็† Max = N_max(A[i], Max, Min) Min = N_min(A[i], Min) print(Min, Max) break elif A[i - 1] / A[i] < 2: # ๆฌกใฎๅ€คใŒ2ๅ€ไปฅไธ‹๏ผˆๆœ€ๅพŒไปฅๅค–๏ผ‰ Max = N_max(A[i], Max, Min) Min = N_min(A[i], Min) else: print(error) break else: print(error) break
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s265788709
Runtime Error
p03463
Input is given from Standard Input in the following format: N A B
from math import ceil, floor K = int(input()) As = list(map(int, input().split())) L = 2 R = 2 for A in reversed(As): if R // A * A < L: print("-1") exit() L = ceil(L / A) * A R = floor(R / A) * A + A - 1 print(L, R)
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s928869708
Accepted
p03463
Input is given from Standard Input in the following format: N A B
_, A, B = list(map(int, input().split())) x = A + B print("Alice" if x % 2 == 0 else "Borys")
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s806089950
Accepted
p03463
Input is given from Standard Input in the following format: N A B
print("ABloircyes"[sum(map(int, input().split()[1:])) % 2 :: 2])
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins. * * *
s029302757
Runtime Error
p03463
Input is given from Standard Input in the following format: N A B
txt = input() txt = input.split() print(1, 1, 1)
Statement A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once. The player who can't make a move loses, and the other player wins. Both players want to win. Who wins if they play optimally?
[{"input": "5 2 4", "output": "Alice\n \n\nAlice can move her token to cell 3. After that, Borys will be unable to move\nhis token to cell 3, so he will have to move his token to cell 5. Then, Alice\nmoves her token to cell 4. Borys can't make a move and loses.\n\n* * *"}, {"input": "2 1 2", "output": "Borys\n \n\nAlice can't make the very first move and loses.\n\n* * *"}, {"input": "58 23 42", "output": "Borys"}]
Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever. * * *
s017554597
Wrong Answer
p03033
Input is given from Standard Input in the following format: N Q S_1 T_1 X_1 : S_N T_N X_N D_1 : D_Q
n, q = map(int, input().split()) stx = [tuple(map(int, input().split())) for _ in range(n)] d = [int(input()) for _ in range(q)]
Statement There is an infinitely long street that runs west to east, which we consider as a number line. There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5. Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point. Find the distance each of the Q people will walk.
[{"input": "4 6\n 1 3 2\n 7 13 10\n 18 20 13\n 3 4 2\n 0\n 1\n 2\n 3\n 5\n 8", "output": "2\n 2\n 10\n -1\n 13\n -1\n \n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate\n2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at\ntime 3. The first roadwork has ended, but the fourth roadwork has begun, so\nthis person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they\nwalk forever. The output for these cases is -1."}]
Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever. * * *
s233308808
Accepted
p03033
Input is given from Standard Input in the following format: N Q S_1 T_1 X_1 : S_N T_N X_N D_1 : D_Q
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): """ ใจใ‚Šใ‚ใˆใš๏ผŒS,TใฏXใ ใ‘ๅทฆใซใšใ‚‰ใ—ใฆ๏ผŒ0็ง’ใฎๆ™‚ใซใฉใฎๆ™‚้–“ใชใ‚‰Xใงๆญขใพใ‚‹ใ‹ใซใ™ใ‚‹๏ผŽ ใใฎใ‚ใจ๏ผŒใ‚ฐใƒฉใƒ•(x-tใ‚ฐใƒฉใƒ•)ใ‚’ๆ›ธใ„ใฆ๏ผŒ็ธฆๆฃ’ใ‚’ๅทฆใ‹ใ‚‰ๅ‹•ใ‹ใ—ใฆใ„ใ๏ผˆใ‚คใƒ™ใƒณใƒˆใ‚ฝใƒผใƒˆ๏ผ‰ ้€š่กŒๆญขใ‚ใจใชใ‚‹Xใ‚’่ค‡ๆ•ฐๆŒใฃใฆใŠใๅฟ…่ฆใŒใ‚ใ‚Š๏ผŒ่ฟฝๅŠ ๏ผŒๅ‚็…ง๏ผŒๅ‰Š้™คใฎๆฉŸ่ƒฝใŒๆฌฒใ—ใ„ """ ############################## from bisect import bisect_left, bisect_right, insort_right class SquareSkipList: # SkipList ใฎๅฑคๆ•ฐใ‚’ 2 ใซใ—ใŸๆ„Ÿใ˜ใฎไฝ•ใ‹ # std::multiset ใฎไปฃ็”จใซใชใ‚‹ def __init__(self, values=None, sorted_=False, square=1000, seed=42): # values: ๅˆๆœŸๅ€คใฎใƒชใ‚นใƒˆ # sorted_: ๅˆๆœŸๅ€คใŒใ‚ฝใƒผใƒˆๆธˆใฟใงใ‚ใ‚‹ใ‹ # square: ๆœ€ๅคงใƒ‡ใƒผใ‚ฟๆ•ฐใฎๅนณๆ–นๆ น # seed: ไนฑๆ•ฐใฎใ‚ทใƒผใƒ‰ ### pop้–ขๆ•ฐใฏใ€€for ใ‚’ๅ›žใ™ใฎใง้‡ใ‚ใ€ไฝฟใ†ใชใ‚‰ square ใƒ‘ใƒฉใƒกใƒผใ‚ฟใ‚’ๅคงใใ‚ใซใ™ใ‚‹ในใ self.cnt = 0 # ่ฆ็ด ๆ•ฐใ‚’ๆŒใฃใฆใŠใใ‹ inf = float("inf") self.square = square if values is None: self.rand_y = seed self.layer1 = [inf] self.layer0 = [[]] else: self.layer1 = layer1 = [] self.layer0 = layer0 = [] if not sorted_: values.sort() y = seed l0 = [] for v in values: y ^= (y & 0x7FFFF) << 13 y ^= y >> 17 y ^= (y & 0x7FFFFFF) << 5 if y % square == 0: layer0.append(l0) l0 = [] layer1.append(v) else: l0.append(v) layer1.append(inf) layer0.append(l0) self.rand_y = y def add(self, x): # ่ฆ็ด ใฎ่ฟฝๅŠ  # O(sqrt(n)) # xorshift y = self.rand_y y ^= (y & 0x7FFFF) << 13 y ^= y >> 17 y ^= (y & 0x7FFFFFF) << 5 self.rand_y = y if y % self.square == 0: layer1, layer0 = self.layer1, self.layer0 idx1 = bisect_right(layer1, x) layer1.insert(idx1, x) layer0_idx1 = layer0[idx1] idx0 = bisect_right(layer0_idx1, x) layer0.insert( idx1 + 1, layer0_idx1[idx0:] ) # layer0 ใฏ dict ใง็ฎก็†ใ—ใŸๆ–นใŒ่‰ฏใ„ใ‹ใ‚‚ใ—ใ‚Œใชใ„ # dict ๅพฎๅฆ™ใ ใฃใŸ del layer0_idx1[idx0:] else: idx1 = bisect_right(self.layer1, x) insort_right(self.layer0[idx1], x) self.cnt += 1 # ่ฟฝๅŠ  def remove(self, x): # ่ฆ็ด ใฎๅ‰Š้™ค # O(sqrt(n)) # x ใŒๅญ˜ๅœจใ—ใชใ„ๅ ดๅˆใ€x ไปฅไธŠใฎๆœ€ๅฐใฎ่ฆ็ด ใŒๅ‰Š้™คใ•ใ‚Œใ‚‹ idx1 = bisect_left(self.layer1, x) layer0_idx1 = self.layer0[idx1] idx0 = bisect_left(layer0_idx1, x) if idx0 == len(layer0_idx1): del self.layer1[idx1] self.layer0[idx1] += self.layer0.pop(idx1 + 1) else: del layer0_idx1[idx0] self.cnt -= 1 def search_higher_equal(self, x): # x ไปฅไธŠใฎๆœ€ๅฐใฎๅ€คใ‚’่ฟ”ใ™ O(log(n)) idx1 = bisect_left(self.layer1, x) layer0_idx1 = self.layer0[idx1] idx0 = bisect_left(layer0_idx1, x) if idx0 == len(layer0_idx1): return self.layer1[idx1] return layer0_idx1[idx0] def search_higher(self, x): # x ใ‚’่ถ…ใˆใ‚‹ๆœ€ๅฐใฎๅ€คใ‚’่ฟ”ใ™ O(log(n)) idx1 = bisect_right(self.layer1, x) layer0_idx1 = self.layer0[idx1] idx0 = bisect_right(layer0_idx1, x) if idx0 == len(layer0_idx1): return self.layer1[idx1] return layer0_idx1[idx0] def search_lower(self, x): # x ๆœชๆบ€ใฎๆœ€ๅคงใฎๅ€คใ‚’่ฟ”ใ™ O(log(n)) # xๆœชๆบ€ใฎใ‚‚ใฎใŒใชใ„ๅ ดๅˆ๏ผŒinfใŒ่ฟ”ใ‚‹ใ‹ใ‚‚๏ผ๏ผ๏ผ idx1 = bisect_left(self.layer1, x) layer0_idx1 = self.layer0[idx1] idx0 = bisect_left(layer0_idx1, x) if idx0 == 0: # layer0_idx1 ใŒ็ฉบใฎๅ ดๅˆใจใ™ในใฆ x ไปฅไธŠใฎๅ ดๅˆ return self.layer1[idx1 - 1] return layer0_idx1[idx0 - 1] def pop(self, idx): # ๅฐใ•ใ„ๆ–นใ‹ใ‚‰ idx ็•ช็›ฎใฎ่ฆ็ด ใ‚’ๅ‰Š้™คใ—ใฆใใฎ่ฆ็ด ใ‚’่ฟ”ใ™๏ผˆ0-indexed๏ผ‰ # O(sqrt(n)) # for ใ‚’ๅ›žใ™ใฎใง้‡ใ‚ใ€ไฝฟใ†ใชใ‚‰ square ใƒ‘ใƒฉใƒกใƒผใ‚ฟใ‚’ๅคงใใ‚ใซใ™ใ‚‹ในใ self.cnt -= 1 layer0 = self.layer0 s = -1 for i, l0 in enumerate(layer0): s += len(l0) + 1 if s >= idx: break if s == idx: layer0[i] += layer0.pop(i + 1) return self.layer1.pop(i) else: return layer0[i].pop(idx - s) def all(self): print(self.layer1) print(self.layer0) def len(self): return self.cnt ############################## N, Q = MI() L = [] # 0ใชใ‚‰่ฟฝๅŠ ๏ผŒ1ใชใ‚‰ๅ‰Š้™ค๏ผŒ2ใชใ‚‰ใ‚ฏใ‚จใƒช๏ผŒๅŠ้–‹ๅŒบ้–“ใชใฎใง้ †็•ชๅคงไบ‹ for _ in range(N): s, t, x = MI() s -= x t -= x L.append([s, 0, x]) L.append([t, 1, x]) # ๅˆถ็ด„ใ‚ˆใ‚ŠDใฏๆ˜‡้ † for _ in range(Q): d = I() L.append([d, 2, 0]) # 3ใคใซๆƒใˆใฆใŠใใ‹ L.sort() anss = [] inf = 10**10 ssl = SquareSkipList(square=2000) ssl.add(inf) for t, q, x in L: if q == 0: ssl.add(x) elif q == 2: temp = ssl.search_higher_equal(-1) # ๆœ€ๅฐๅ€คๆคœ็ดข if temp == inf: ans = -1 else: ans = temp anss.append(ans) else: ssl.remove(x) for i in range(Q): print(anss[i]) main()
Statement There is an infinitely long street that runs west to east, which we consider as a number line. There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5. Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point. Find the distance each of the Q people will walk.
[{"input": "4 6\n 1 3 2\n 7 13 10\n 18 20 13\n 3 4 2\n 0\n 1\n 2\n 3\n 5\n 8", "output": "2\n 2\n 10\n -1\n 13\n -1\n \n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate\n2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at\ntime 3. The first roadwork has ended, but the fourth roadwork has begun, so\nthis person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they\nwalk forever. The output for these cases is -1."}]
Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever. * * *
s778415045
Wrong Answer
p03033
Input is given from Standard Input in the following format: N Q S_1 T_1 X_1 : S_N T_N X_N D_1 : D_Q
n, q = map(int, input().split()) stx = [list(map(int, input().split())) for _ in range(n)] ds = [int(input()) for _ in range(q)] coords = set() coords.add(0) for s, t, x in stx: coords.add(s - x) coords.add(t - x) i = 0 index = {} position = [-1] * len(coords) + [1000000000000000] for c in sorted(coords): index[c] = i position[i] = c i += 1 stop = [-1] * (len(coords) + 1) for s, t, x in stx: start = index[s - x] end = index[t - x] for i in range(start, end): if stop[i] == -1 or stop[i] > x: stop[i] = x i = 0 for d in ds: while position[i] < d: i += 1 print(stop[i])
Statement There is an infinitely long street that runs west to east, which we consider as a number line. There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5. Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point. Find the distance each of the Q people will walk.
[{"input": "4 6\n 1 3 2\n 7 13 10\n 18 20 13\n 3 4 2\n 0\n 1\n 2\n 3\n 5\n 8", "output": "2\n 2\n 10\n -1\n 13\n -1\n \n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate\n2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at\ntime 3. The first roadwork has ended, but the fourth roadwork has begun, so\nthis person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they\nwalk forever. The output for these cases is -1."}]
Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever. * * *
s876305003
Wrong Answer
p03033
Input is given from Standard Input in the following format: N Q S_1 T_1 X_1 : S_N T_N X_N D_1 : D_Q
import sys input = sys.stdin.readline class MinSegTree: """ 0-indexed query : [L, R) """ def __init__(self, size): self.size = 1 << (size.bit_length()) # ๅฎŒๅ…จไบŒๅˆ†ๆœจใซใ™ใ‚‹ self.data = [INF] * (2 * self.size - 1) def build(self, rawData): self.data[self.size - 1 : self.size - 1 + len(rawData)] = rawData for i in range(self.size - 1)[::-1]: self.data[i] = min(self.data[2 * i + 1], self.data[2 * i + 2]) def update(self, index, value): index += self.size - 1 self.data[index] = value while index >= 0: index = (index - 1) // 2 self.data[index] = min(self.data[2 * index + 1], self.data[2 * index + 2]) def query(self, left, right): L = left + self.size R = right + self.size ret = INF while L < R: if R & 1: R -= 1 ret = min(ret, self.data[R - 1]) if L & 1: ret = min(ret, self.data[L - 1]) L += 1 L >>= 1 R >>= 1 return ret N, Q = map(int, input().split()) INF = float("inf") events = [] for i in range(N): S, T, X = map(int, input().split()) events.append((S - X, True, i, X)) events.append((T - X, False, i, X)) events.sort() tree = MinSegTree(N) D = [int(input()) for _ in range(Q)] M = len(events) now = 0 ans = [] for d in D: while now < M and events[now][0] <= d: _, isStart, i, x = events[now] if isStart: tree.update(i, x) else: tree.update(i, INF) now += 1 print(tree.data[0])
Statement There is an infinitely long street that runs west to east, which we consider as a number line. There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5. Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point. Find the distance each of the Q people will walk.
[{"input": "4 6\n 1 3 2\n 7 13 10\n 18 20 13\n 3 4 2\n 0\n 1\n 2\n 3\n 5\n 8", "output": "2\n 2\n 10\n -1\n 13\n -1\n \n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate\n2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at\ntime 3. The first roadwork has ended, but the fourth roadwork has begun, so\nthis person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they\nwalk forever. The output for these cases is -1."}]
Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever. * * *
s604420685
Runtime Error
p03033
Input is given from Standard Input in the following format: N Q S_1 T_1 X_1 : S_N T_N X_N D_1 : D_Q
import random N, Q = list(map(int, input().split())) STX = [list(map(int, input().split())) for _ in range(N)] STX.sort(key=lambda x: x[2]) D = [int(input()) for i in range(Q)] D_binary = [(d, i) for i, d in enumerate(D)] # binary tree class Node(object): """Tree node: left and right child + data which can be any object""" def __init__(self, data): """Node constructor @param data node data object """ self.left = None self.right = None self.data = data def insert(self, data): """Insert new node with data @param data node data object to insert """ if self.data is not None: if data < self.data: if self.left is None: self.left = Node(data) else: self.left.insert(data) elif data > self.data: if self.right is None: self.right = Node(data) else: self.right.insert(data) else: self.data = data def lookup(self, data, parent=None): """Lookup node containing data @param data node data object to look up @param parent node's parent @returns node and node's parent if found or None, None """ if data < self.data: if self.left is None: return None, None return self.left.lookup(data, self) elif data > self.data: if self.right is None: return None, None return self.right.lookup(data, self) else: return self, parent def lookup_near(self, data, parent=None, route=None): """Lookup node containing data""" # def f(): # return min(r for r in route if r> data) if not route: route = [] route.append(self.data) if data < self.data: if self.left is None: # print(route,self.right) return min(r for r in route if r > data) return self.left.lookup_near(data, self, route) elif data > self.data: if self.right is None: # print(route,self.left) return min(r for r in route if r > data) return self.right.lookup_near(data, self, route) else: return self.data def delete(self, data): """Delete node containing data @param data node's content to delete """ # get node containing data node, parent = self.lookup(data) if node is not None: children_count = node.children_count() if children_count == 0: # if node has no children, just remove it if parent: if parent.left is node: parent.left = None else: parent.right = None else: self.data = None elif children_count == 1: # if node has 1 child # replace node by its child if node.left: n = node.left else: n = node.right if parent: if parent.left is node: parent.left = n else: parent.right = n else: self.left = n.left self.right = n.right self.data = n.data else: # if node has 2 children # find its successor parent = node successor = node.right while successor.left: parent = successor successor = successor.left # replace node data by its successor data node.data = successor.data # fix successor's parent node child if parent.left == successor: parent.left = successor.right else: parent.right = successor.right def compare_trees(self, node): """Compare 2 trees @param node tree to compare @returns True if the tree passed is identical to this tree """ if node is None: return False if self.data != node.data: return False res = True if self.left is None: if node.left: return False else: res = self.left.compare_trees(node.left) if res is False: return False if self.right is None: if node.right: return False else: res = self.right.compare_trees(node.right) return res def print_tree(self): """Print tree content inorder""" if self.left: self.left.print_tree() print(self.data, end=" ") if self.right: self.right.print_tree() def tree_data(self): """Generator to get the tree nodes data""" # we use a stack to traverse the tree in a non-recursive way stack = [] node = self while stack or node: if node: stack.append(node) node = node.left else: # we are returning so we pop the node and we yield it node = stack.pop() yield node.data node = node.right def children_count(self): """Return the number of children @returns number of children: 0, 1, 2 """ cnt = 0 if self.left: cnt += 1 if self.right: cnt += 1 return cnt D_shuffle = list(D) random.shuffle(D_shuffle) bt = Node(None) for d in D_shuffle: bt.insert(d) # print(D_shuffle) from collections import defaultdict ans = defaultdict(lambda: -1) for s, t, x in STX: sx = s - x tx = t - x while True: v = bt.lookup_near(sx) if v < tx: bt.delete(v) ans[v] = x else: break for d in D: print(ans[d])
Statement There is an infinitely long street that runs west to east, which we consider as a number line. There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5. Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point. Find the distance each of the Q people will walk.
[{"input": "4 6\n 1 3 2\n 7 13 10\n 18 20 13\n 3 4 2\n 0\n 1\n 2\n 3\n 5\n 8", "output": "2\n 2\n 10\n -1\n 13\n -1\n \n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate\n2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at\ntime 3. The first roadwork has ended, but the fourth roadwork has begun, so\nthis person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they\nwalk forever. The output for these cases is -1."}]
Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever. * * *
s449902061
Wrong Answer
p03033
Input is given from Standard Input in the following format: N Q S_1 T_1 X_1 : S_N T_N X_N D_1 : D_Q
read = input rn = lambda: list(map(int, read().split())) n, q = rn() STX = [rn() for i in range(n)] D = [rn()[0] for i in range(q)] D = list( map( lambda tp: ( -tp[1], tp[0], ), enumerate(D), ) ) # ็›ธๅฝ“ไบŽ-dๅค„0ๆ—ถๅ‡บๅ‘ (-d, index) D.sort() STX.sort(key=lambda tp: tp[0]) # sort by -d # O(n) zhuqufa ans = [-1 for i in range(len(D))] level = 0 while (1 << level) < len(D): # leaves cnt >= len(D) level += 1 tree = [(0, 0) for i in range((1 << (level + 1)) - 1)] Dstart = (1 << level) - 1 Dend = (1 << level) - 1 + len(D) # print(Dstart, Dend, len(tree), level) for i in range(Dstart, Dend): ii = i i -= Dstart tree[ii] = [D[i][0], D[i][0], -1, D[i][1]] for i in range(Dend, len(tree)): tree[i] = [D[-1][0], D[-1][0], 0] # [3] = 0,่‡ชๅŠจๅฟฝ็•ฅ for i in range(Dstart - 1, 0 - 1, -1): l = i * 2 + 1 r = i * 2 + 2 tree[i] = [tree[l][0], tree[r][1], min(tree[l][2], tree[r][2])] def search(l, r, d, i): # [l,r] terminate at d if tree[i][2] >= 0: return # done if r < tree[i][0]: return if l > tree[i][1]: return if i >= Dend: return if i >= Dstart: tree[i][2] = d return lc = i * 2 + 1 rc = i * 2 + 2 search(l, r, d, lc) search(l, r, d, rc) tree[i][2] = min(tree[lc][2], tree[rc][2]) # print(tree[:Dstart]) # print(tree[Dstart:Dend]) # print(tree[Dend:]) for s, t, x in STX: t -= 1 l = x - t r = x - s search(l, r, x, 0) # print('\n',l,r,x, [s,t,x]) # print(tree[:Dstart]) # print(tree[Dstart:Dend]) # print(tree[Dend:]) for a, b, d, i in tree[Dstart:Dend]: ans[i] = d for x in ans: print(x)
Statement There is an infinitely long street that runs west to east, which we consider as a number line. There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5. Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point. Find the distance each of the Q people will walk.
[{"input": "4 6\n 1 3 2\n 7 13 10\n 18 20 13\n 3 4 2\n 0\n 1\n 2\n 3\n 5\n 8", "output": "2\n 2\n 10\n -1\n 13\n -1\n \n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate\n2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at\ntime 3. The first roadwork has ended, but the fourth roadwork has begun, so\nthis person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they\nwalk forever. The output for these cases is -1."}]
Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever. * * *
s956437393
Runtime Error
p03033
Input is given from Standard Input in the following format: N Q S_1 T_1 X_1 : S_N T_N X_N D_1 : D_Q
# coding: utf-8 class Construction: def __init__(self, start, end, pos): self.start = start - 0.5 self.end = end - 0.5 self.pos = pos self.working = False class Constructions: def __init__(self): self.list = [] self.start_max = 0 def append(self, construction): self.list.append(construction) if self.start_max < construction.start: self.start_max = construction.start def sort(self): self.list = sorted(self.list, key=lambda x: x.start) def __iter__(self): for c in self.list: yield c def isEncounter(self, pos): for c in self.list: if c.working and pos == c.pos: return True return False def __str__(self): return str([(c.start, c.end, c.pos, c.working) for c in self.list]) def step(self, elapsed_time): for c in self.list: if c.start <= elapsed_time and c.end >= elapsed_time: c.working = True else: c.working = False class Person: def __init__(self, departure): self.departure = departure self.pos = 0 self.walking = True def walk(self): if self.walking: self.pos += 1 def stop(self): self.walking = False class Persons: def __init__(self): self.list = [] self.departure_max = 0 def append(self, person): self.list.append(person) if self.departure_max < person.departure: self.departure_max = person.departure def __iter__(self): for p in self.list: yield p def __str__(self): return str([(p.departure, p.pos) for p in self.list]) input_line = input() construction_num, person_num = map(int, input_line.split()) constructions = Constructions() for i in range(construction_num): input_line = input() start, end, pos = map(int, input_line.split()) c = Construction(start, end, pos) constructions.append(c) persons = Persons() for i in range(construction_num): input_line = input() departure = int(input_line) p = Person(departure) persons.append(p) constructions.sort() elapsed_time = 0 while True: for index, p in enumerate(persons): constructions.step(elapsed_time) if constructions.isEncounter(p.pos): p.stop() if p.pos > constructions.start_max: p.stop() p.pos = -1 if p.departure <= elapsed_time: p.walk() elapsed_time += 1 if any([p.walking for p in persons]) == False: break for p in persons: print(p.pos)
Statement There is an infinitely long street that runs west to east, which we consider as a number line. There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5. Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point. Find the distance each of the Q people will walk.
[{"input": "4 6\n 1 3 2\n 7 13 10\n 18 20 13\n 3 4 2\n 0\n 1\n 2\n 3\n 5\n 8", "output": "2\n 2\n 10\n -1\n 13\n -1\n \n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate\n2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at\ntime 3. The first roadwork has ended, but the fourth roadwork has begun, so\nthis person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they\nwalk forever. The output for these cases is -1."}]
Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever. * * *
s026899006
Wrong Answer
p03033
Input is given from Standard Input in the following format: N Q S_1 T_1 X_1 : S_N T_N X_N D_1 : D_Q
import bisect class LazyPropSegmentTree: def __init__(self, a): self.padding = float("inf") self.n = len(a) self.N = 1 << (self.n - 1).bit_length() self.seg_data = ( [self.padding] * (self.N - 1) + a + [self.padding] * (self.N - self.n) ) self.lazy = [None] * (2 * self.N - 1) for i in range(2 * self.N - 2, 0, -2): self.seg_data[(i - 1) >> 1] = min(self.seg_data[i], self.seg_data[i - 1]) def __len__(self): return self.n def enum_idx(self, idx1, idx2): # idx1ใจidx2ใ‚’้ƒจๅˆ†็š„ใซๅซใ‚€ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น(=red)ใ€ๅฎŒๅ…จใซๅซใ‚€ใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น(=blue)ใ‚’ # ้™้ †ใซๅ‡บๅŠ› red = [] red_set = set() blue = [] while idx1 < idx2: if idx2 & 1 == 1: # idx2ใŒๅฅ‡ๆ•ฐ blue.append(idx2) idx2 >>= 1 red.append(idx2) red_set.add(idx2) idx2 -= 1 else: idx2 = (idx2 - 1) >> 1 if idx1 & 1 == 0: # idx1ใŒๅถๆ•ฐ blue.append(idx1) idx1 >>= 1 red.append(idx1 - 1) red_set.add(idx1 - 1) else: idx1 >>= 1 if idx1 not in red_set: blue.append(idx1) while idx1: idx1 = (idx1 - 1) >> 1 red.append(idx1) return red, blue def propagate(self, indices): # ้…ๅปถใ•ใ›ใฆใ„ใŸๅ€คใ‚’ไผๆฌใ•ใ›ใ‚‹ # indicesใฏๆ˜‡้ † for idx in indices: v = self.lazy[idx] if v is not None: idx1, idx2 = 2 * idx + 1, 2 * idx + 2 self.lazy[idx1] = self.lazy[idx2] = v self.seg_data[idx1] = self.seg_data[idx2] = v self.lazy[idx] = None def update(self, i, j, x): # [i, j)ใฎๅŒบ้–“ใฎๅ€คใ‚’xใซๅค‰ๆ›ดใ™ใ‚‹ red, blue = self.enum_idx(self.N - 1 + i, self.N - 2 + j) self.propagate(red[::-1]) for idx in blue: self.lazy[idx] = self.seg_data[idx] = x for idx in red: idx1, idx2 = 2 * idx + 1, 2 * idx + 2 self.seg_data[idx] = min(self.seg_data[idx1], self.seg_data[idx2]) def query(self, i, j): # [i, j) red, blue = self.enum_idx(self.N - 1 + i, self.N - 2 + j) self.propagate(red[::-1]) result = self.padding for idx in blue: result = min(result, self.seg_data[idx]) return result @property def data(self): return self.seg_data[self.N - 1 : self.N - 1 + self.n] N, Q = map(int, input().split()) STX = [list(map(int, input().split())) for i in range(N)] STX.sort(key=lambda x: x[2], reverse=True) st = LazyPropSegmentTree([float("inf")] * Q) d = [int(input()) for i in range(Q)] for s, t, x in STX: il = bisect.bisect_left(d, s - x) ir = bisect.bisect_right(d, t - x - 1) if il == ir: continue st.update(il, ir, x) for i in range(Q): x = st.query(i, i + 1) if x < float("inf"): print(x) else: print(-1)
Statement There is an infinitely long street that runs west to east, which we consider as a number line. There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5. Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point. Find the distance each of the Q people will walk.
[{"input": "4 6\n 1 3 2\n 7 13 10\n 18 20 13\n 3 4 2\n 0\n 1\n 2\n 3\n 5\n 8", "output": "2\n 2\n 10\n -1\n 13\n -1\n \n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate\n2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at\ntime 3. The first roadwork has ended, but the fourth roadwork has begun, so\nthis person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they\nwalk forever. The output for these cases is -1."}]
Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever. * * *
s293008872
Accepted
p03033
Input is given from Standard Input in the following format: N Q S_1 T_1 X_1 : S_N T_N X_N D_1 : D_Q
import sys input = sys.stdin.readline INF = 1 << 31 from bisect import bisect_left class LazySegmentTree: def __init__(self, Q): self.N = Q self.tree = [INF] * (2 * self.N) self.lazy = [INF] * (2 * self.N) def _evaluate(self, K): # KใฎไธŠใฎ้…ๅปถ้…ๅˆ—ใ‚’่ฉ•ไพกใ™ใ‚‹ H = K.bit_length() - 1 for i in range(H, 0, -1): h = K >> i if self.lazy[h] == INF: continue self.tree[h] = min(self.tree[h], self.lazy[h]) self.lazy[h << 1] = min(self.lazy[h << 1], self.lazy[h]) self.lazy[h << 1 | 1] = min(self.lazy[h << 1 | 1], self.lazy[h]) self.lazy[h] = INF def _caluculate(self, K): # Kใ‚ˆใ‚ŠไธŠใ‚’่จˆ็ฎ—ใ™ใ‚‹ while K > 1: K >>= 1 self.tree[K] = min( self.tree[K], self.tree[K << 1], self.lazy[K << 1], self.tree[K << 1 | 1], self.lazy[K << 1 | 1], ) def range_update(self, L, R, M): # [L,R)ใซMใ‚’ไฝœ็”จ L += self.N R += self.N L0 = L // (L & -L) R0 = R // (R & -R) - 1 # self._evaluate(L0) # self._evaluate(R0) while L < R: if L & 1: self.lazy[L] = min(self.lazy[L], M) L += 1 if R & 1: R -= 1 self.lazy[R] = min(self.lazy[R], M) L >>= 1 R >>= 1 # print("L0 R0 {} {}\n".format(L0,R0)) self._caluculate(L0) self._caluculate(R0) def range_query(self, L, R): # [L,R)ใ‚’่จˆ็ฎ—ใ™ใ‚‹ L += self.N R += self.N L0 = L // (L & -L) R0 = R // (R & -R) - 1 self._evaluate(L0) self._evaluate(R0) v = INF while L < R: if L & 1: v = min(v, self.tree[L], self.lazy[L]) L += 1 if R & 1: R -= 1 v = min(self.tree[R], self.lazy[R], v) L >>= 1 R >>= 1 return v """ def __str__(self): return '\n'.join(' '.join(str(v) for v in self.tree[1<<i:1<<(i + 1)]) for i in range((2*self.N).bit_length())) """ def debug(self): print(self.lazy) print(self.tree) def __str__(self): for i in range(self.N): self.tree[i] = min(self.tree[i], self.lazy[i]) self.lazy[i << 1] = min(self.lazy[i << 1], self.lazy[i]) self.lazy[i << 1 | 1] = min(self.lazy[i << 1 | 1], self.lazy[i]) self.lazy[i] = INF for i in range(self.N, self.N * 2): self.tree[i] = min(self.tree[i], self.lazy[i]) return "\n".join(map(str, [k if k < INF else -1 for k in self.tree[self.N :]])) N, Q = map(int, input().split()) roadwork = [tuple(map(int, input().split())) for _ in range(N)] D = [int(input()) for _ in range(Q)] st = LazySegmentTree(Q) for s, t, x in roadwork: l = bisect_left(D, s - x) r = bisect_left(D, t - x) st.range_update(l, r, x) print(str(st))
Statement There is an infinitely long street that runs west to east, which we consider as a number line. There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5. Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point. Find the distance each of the Q people will walk.
[{"input": "4 6\n 1 3 2\n 7 13 10\n 18 20 13\n 3 4 2\n 0\n 1\n 2\n 3\n 5\n 8", "output": "2\n 2\n 10\n -1\n 13\n -1\n \n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate\n2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at\ntime 3. The first roadwork has ended, but the fourth roadwork has begun, so\nthis person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they\nwalk forever. The output for these cases is -1."}]
Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever. * * *
s877531838
Accepted
p03033
Input is given from Standard Input in the following format: N Q S_1 T_1 X_1 : S_N T_N X_N D_1 : D_Q
class BIT: def __init__(self, N): self.tree = [0] * (N + 1) # 1-indexed self.N = N def add(self, i, x): """tree[i]ใจ้–ข้€ฃๅ€‹ๆ‰€ใซxใ‚’ๅŠ ใˆใ‚‹""" tree = self.tree N = self.N while i <= N: tree[i] += x i += i & (-i) def sum(self, i): tree = self.tree s = 0 while i: s += tree[i] i -= i & (-i) return s def binary_search(self, x): """ๅŒบ้–“ๅ’Œ >=x ใจใชใ‚‹ๆœ€ๅฐใฎindex""" tree = self.tree N = self.N i = 0 step = 1 << (N.bit_length() - 1) while step: if i + step <= N and tree[i + step] < x: i += step x -= tree[i] step >>= 1 return i + 1 def main(): from collections import deque, namedtuple from operator import attrgetter import sys input = sys.stdin.readline Event = namedtuple("Event", "time position") N, Q = map(int, input().split()) go = [] stop = [] xs = set() for _ in range(N): s, t, x = map(int, input().split()) stop.append(Event(time=s - x, position=x)) go.append(Event(time=t - x, position=x)) xs.add(x) xs = sorted(xs) stop.sort(key=attrgetter("time")) go.sort(key=attrgetter("time")) stop = deque(stop) go = deque(go) compress = {x: i for i, x in enumerate(xs, 1)} decompress = {i: x for i, x in enumerate(xs, 1)} ans = [] b = BIT(N) for _ in range(Q): d = int(input()) while go and go[0].time <= d: e = go.popleft() p = compress[e.position] b.add(p, -1) while stop and stop[0].time <= d: e = stop.popleft() p = compress[e.position] b.add(p, 1) compressed_ind = b.binary_search(1) ind = decompress.get(compressed_ind, -1) ans.append(ind) print(*ans, sep="\n") if __name__ == "__main__": main()
Statement There is an infinitely long street that runs west to east, which we consider as a number line. There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5. Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point. Find the distance each of the Q people will walk.
[{"input": "4 6\n 1 3 2\n 7 13 10\n 18 20 13\n 3 4 2\n 0\n 1\n 2\n 3\n 5\n 8", "output": "2\n 2\n 10\n -1\n 13\n -1\n \n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate\n2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at\ntime 3. The first roadwork has ended, but the fourth roadwork has begun, so\nthis person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they\nwalk forever. The output for these cases is -1."}]
Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever. * * *
s962919795
Wrong Answer
p03033
Input is given from Standard Input in the following format: N Q S_1 T_1 X_1 : S_N T_N X_N D_1 : D_Q
import sys s2nn = lambda s: [int(c) for c in s.split(" ")] ss2nn = lambda ss: [int(s) for s in ss] ss2nnn = lambda ss: [s2nn(s) for s in ss] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)] ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)] ii2nn = lambda n: ss2nn(ii2ss(n)) ii2nnn = lambda n: ss2nnn(ii2ss(n)) # random_denseใŒTLE, ไป–ใฏAC """ from bisect import bisect_left, bisect_right # ไบŒๅˆ†ๆŽข็ดข def main(): N, Q = i2nn() STX = ii2nnn(N) # ๅบงๆจ™ X ใงๆ™‚ๅˆป [S, T) ใŒๅทฅไบ‹ D = ii2nn(Q) # ๆ˜‡้ †ใ‚ฝใƒผใƒˆๆธˆใฟ E = [-1] * Q STX.sort(key=lambda v: v[2]) for s, t, x in STX: a = bisect_left(D, s-x) b = bisect_left(D, t-x) for i in range(a, b): if E[i] == -1: E[i] = x for e in E: print(e) """ def main(): N, Q = i2nn() STX = ii2nnn(N) # ๅบงๆจ™ X ใงๆ™‚ๅˆป [S, T) ใŒๅทฅไบ‹ D = ii2nn(Q) # ๆ˜‡้ †ใ‚ฝใƒผใƒˆๆธˆใฟ events = [] for s, t, x in STX: events.append(("S", s - x - 0.25, x)) events.append(("T", t - x - 0.75, x)) # 0.5 ๅŒๅฃซใ ใจ [1, 2), [0, 1) ใงๅนใ้ฃ›ใถ for i, d in enumerate(D): events.append(("D", d, i)) ans = [-1] * Q events.sort(key=lambda v: v[1]) xset = set() xmin = None # xmin = 1e+10 # xb = False for event, time, xi in events: if event == "S": xset.add(xi) if xmin is None: xmin = xi elif xmin > xi: xmin = xi # xb = True elif event == "T": xset.remove(xi) if xmin == xi: xmin = None # xb = False elif event == "D" and xset: # if not xb: if xmin is None: xmin = min(xset) # xb = True ans[xi] = xmin for n in ans: print(n) main()
Statement There is an infinitely long street that runs west to east, which we consider as a number line. There are N roadworks scheduled on this street. The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5. Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point. Find the distance each of the Q people will walk.
[{"input": "4 6\n 1 3 2\n 7 13 10\n 18 20 13\n 3 4 2\n 0\n 1\n 2\n 3\n 5\n 8", "output": "2\n 2\n 10\n -1\n 13\n -1\n \n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate\n2 when reaching a point blocked by the first roadwork at time 2.\n\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at\ntime 3. The first roadwork has ended, but the fourth roadwork has begun, so\nthis person also stops walking at coordinate 2.\n\nThe fourth and sixth persons encounter no roadworks while walking, so they\nwalk forever. The output for these cases is -1."}]
Print the minimum number of bombs needed to win. * * *
s803050042
Accepted
p02788
Input is given from Standard Input in the following format: N D A X_1 H_1 : X_N H_N
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) """ ๅทฆใ‹ใ‚‰่ฆ‹ใ‚‹๏ผŒใƒขใƒณใ‚นใ‚ฟใƒผใŒ็”Ÿใใฆใ„ใ‚‹ใชใ‚‰ใใ„ใคใŒๅทฆ็ซฏใ‚ฎใƒชใ‚ฎใƒชใซใชใ‚‹ไฝ็ฝฎใซ็ˆ†ๅผพๆŠ•ไธ‹ ๅŒบ้–“ๆธ›็ฎ—๏ผŒๅบงๅœง """ def main(): #################### import sys class Lazysegtree: # ๅฟ…ใšๅ˜ไฝๅ…ƒใซๆณจๆ„ใ™ใ‚‹ใ“ใจ๏ผqueryใง1็‚นใฎๅ€คใฎใฟใ‚’ๆŠฝๅ‡บใ™ใ‚‹ใ‚ˆใ†ใชๅ ดๅˆใงใ‚‚๏ผŒๅ˜ไฝๅ…ƒใจsegfuncใŒใ‚ใฃใฆใชใ„ใจใƒ€ใƒก๏ผ๏ผ """RAQ ๅค–ใ‹ใ‚‰ไฝฟใ†ใฎใฏ๏ผŒquery๏ผŒadd,updateใใ‚‰ใ„ใ‹ """ def __init__(self, A, intv, initialize=True, segf=min): """ AใŒๅˆๆœŸ้…ๅˆ—๏ผŒintvใŒๅ˜ไฝๅ…ƒ,segfใŒ่ฉ•ไพก้–ขๆ•ฐ """ # ๅŒบ้–“ใฏ 1-indexed ใง็ฎก็† self.N = len(A) self.N0 = 2 ** (self.N - 1).bit_length() self.intv = intv self.segf = segf self.lazy = [0] * (2 * self.N0) if initialize: self.data = [intv] * self.N0 + A + [intv] * (self.N0 - self.N) for i in range(self.N0 - 1, 0, -1): self.data[i] = self.segf(self.data[2 * i], self.data[2 * i + 1]) else: self.data = [intv] * (2 * self.N0) def _ascend(self, k): k = k >> 1 c = k.bit_length() for j in range(c): idx = k >> j self.data[idx] = ( self.segf(self.data[2 * idx], self.data[2 * idx + 1]) + self.lazy[idx] ) def _descend(self, k): k = k >> 1 idx = 1 c = k.bit_length() for j in range(1, c + 1): idx = k >> (c - j) ax = self.lazy[idx] if not ax: continue self.lazy[idx] = 0 self.data[2 * idx] += ax self.data[2 * idx + 1] += ax self.lazy[2 * idx] += ax self.lazy[2 * idx + 1] += ax def update(self, k, x): # 1็‚นใฎใƒ‡ใƒผใ‚ฟใฎๅค‰ๆ›ด k = k + self.N0 self.data[k] = x self._ascend(k) def query(self, l, r): # ใ‚ฏใ‚จใƒช๏ผŒ[l,r)ใ‹ใช L = l + self.N0 R = r + self.N0 Li = L // (L & -L) Ri = R // (R & -R) self._descend(Li) self._descend(Ri - 1) s = self.intv t = self.intv while L < R: if R & 1: R -= 1 t = self.segf(self.data[R], t) if L & 1: s = self.segf(s, self.data[L]) L += 1 L >>= 1 R >>= 1 return self.segf(s, t) def add(self, l, r, x): # ๅŒบ้–“ๅŠ ็ฎ—๏ผŒ[l,r)ใ‹ใช L = l + self.N0 R = r + self.N0 Li = L // (L & -L) Ri = R // (R & -R) while L < R: if R & 1: R -= 1 self.data[R] += x self.lazy[R] += x if L & 1: self.data[L] += x self.lazy[L] += x L += 1 L >>= 1 R >>= 1 self._ascend(Li) self._ascend(Ri - 1) # ๅฟ…ใšๅ˜ไฝๅ…ƒใซๆณจๆ„ใ™ใ‚‹ใ“ใจ๏ผqueryใง1็‚นใฎๅ€คใฎใฟใ‚’ๆŠฝๅ‡บใ™ใ‚‹ใ‚ˆใ†ใชๅ ดๅˆใงใ‚‚๏ผŒๅ˜ไฝๅ…ƒใจsegfuncใŒใ‚ใฃใฆใชใ„ใจใƒ€ใƒก๏ผ๏ผ ########## import bisect N, D, A = MI() X = [0] * N H = [0] * N for i in range(N): X[i], H[i] = MI() X, H = zip(*sorted(zip(X, H))) from collections import defaultdict dd = defaultdict(int) for i in range(N): dd[X[i]] = i ans = 0 inf = 10**10 seg = Lazysegtree(list(H), inf, segf=min) for i in range(N): h = seg.query(i, i + 1) if h > 0: cnt = (h + A - 1) // A ans += cnt l = i t = X[l] + 2 * D r = bisect.bisect_right(X, t) seg.add(l, r, -1 * cnt * A) print(ans) main()
Statement Silver Fox is fighting with N monsters. The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the _health_ of H_i. Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health. Silver Fox wins when all the monsters' healths become 0 or below. Find the minimum number of bombs needed to win.
[{"input": "3 3 2\n 1 2\n 5 4\n 9 2", "output": "2\n \n\nFirst, let us use a bomb at the coordinate 4 to decrease the first and second\nmonsters' health by 2.\n\nThen, use a bomb at the coordinate 6 to decrease the second and third\nmonsters' health by 2.\n\nNow, all the monsters' healths are 0. We cannot make all the monsters' health\ndrop to 0 or below with just one bomb.\n\n* * *"}, {"input": "9 4 1\n 1 5\n 2 4\n 3 3\n 4 2\n 5 1\n 6 2\n 7 3\n 8 4\n 9 5", "output": "5\n \n\nWe should use five bombs at the coordinate 5.\n\n* * *"}, {"input": "3 0 1\n 300000000 1000000000\n 100000000 1000000000\n 200000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}]
Print the minimum number of bombs needed to win. * * *
s194903476
Accepted
p02788
Input is given from Standard Input in the following format: N D A X_1 H_1 : X_N H_N
import operator import os import sys 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 class LazySegmentTree: # http://tsutaj.hatenablog.com/entry/2017/03/29/204841 def __init__(self, size, fn=operator.add, default=None, initial_values=None): """ :param int size: :param callable fn: ๅŒบ้–“ใซ้ฉ็”จใ™ใ‚‹้–ขๆ•ฐใ€‚ๅผ•ๆ•ฐใ‚’ 2 ใคๅ–ใ‚‹ใ€‚min, max, operator.xor ใชใฉ :param default: :param list initial_values: """ default = default or 0 # size ไปฅไธŠใงใ‚ใ‚‹ๆœ€ๅฐใฎ 2 ๅ†ชใ‚’ size ใจใ™ใ‚‹ self._size = 1 << (size - 1).bit_length() self._fn = fn self._lazy = [0] * (self._size * 2 - 1) self._tree = [default] * (self._size * 2 - 1) if initial_values: i = self._size - 1 for v in initial_values: self._tree[i] = v i += 1 i = self._size - 2 while i >= 0: self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2]) i -= 1 def add(self, from_i, to_i, value, k=0, L=None, r=None): """ [from_i, to_i) ใ‚’ใ€ใใ‚Œใžใ‚Œใฎๅ€คใจ value ใซ fn ใ‚’้ฉ็”จใ—ใŸๅ€คใงๆ›ดๆ–ฐใ™ใ‚‹ :param int from_i: :param int to_i: :param int value: :param int k: self._tree ใฎใ‚คใƒณใƒ‡ใƒƒใ‚ฏใ‚น :param int L: :param int r: :return: """ L = 0 if L is None else L r = self._size if r is None else r self._eval(k, L, r) # ็ฏ„ๅ›ฒๅค– if to_i <= L or r <= from_i: return if from_i <= L and r <= to_i: # ๅฎŒๅ…จใซ่ขซ่ฆ†ใ—ใฆใ‚‹ self._lazy[k] += (r - L) * value self._eval(k, L, r) else: # ไธญ้€”ๅŠ็ซฏ self.add(from_i, to_i, value, k * 2 + 1, L, (L + r) // 2) self.add(from_i, to_i, value, k * 2 + 2, (L + r) // 2, r) self._tree[k] = self._fn(self._tree[k * 2 + 1], self._tree[k * 2 + 2]) def _eval(self, k, L, r): """ ้…ๅปถ้…ๅˆ—ใฎๅ€คใ‚’่ฉ•ไพกใ™ใ‚‹ :param k: :param L: :param r: """ if self._lazy[k] != 0: # ๆœฌไฝ“ใ‚’ๆ›ดๆ–ฐ self._tree[k] += self._lazy[k] # ไธ€็•ชไธ‹ใ˜ใ‚ƒใชใ‘ใ‚Œใฐไผๆ’ญใ•ใ›ใ‚‹ if r - L > 1: self._lazy[k * 2 + 1] += self._lazy[k] >> 1 self._lazy[k * 2 + 2] += self._lazy[k] >> 1 self._lazy[k] = 0 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 self._eval(k, L, 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, D, A = list(map(int, sys.stdin.buffer.readline().split())) XH = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)] XH.sort() X = [] H = [] for x, h in XH: X.append(x) H.append(h) lr = [] r = 0 for l in range(N): while r < N and X[r] <= X[l] + D * 2: r += 1 lr.append((l, r)) imos = [0] * (N + 1) cum = 0 ans = 0 for l, r in lr: cum += imos[l] h = H[l] - cum if h > 0: cnt = (h + A - 1) // A cum += cnt * A imos[r] -= cnt * A ans += cnt print(ans)
Statement Silver Fox is fighting with N monsters. The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the _health_ of H_i. Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health. Silver Fox wins when all the monsters' healths become 0 or below. Find the minimum number of bombs needed to win.
[{"input": "3 3 2\n 1 2\n 5 4\n 9 2", "output": "2\n \n\nFirst, let us use a bomb at the coordinate 4 to decrease the first and second\nmonsters' health by 2.\n\nThen, use a bomb at the coordinate 6 to decrease the second and third\nmonsters' health by 2.\n\nNow, all the monsters' healths are 0. We cannot make all the monsters' health\ndrop to 0 or below with just one bomb.\n\n* * *"}, {"input": "9 4 1\n 1 5\n 2 4\n 3 3\n 4 2\n 5 1\n 6 2\n 7 3\n 8 4\n 9 5", "output": "5\n \n\nWe should use five bombs at the coordinate 5.\n\n* * *"}, {"input": "3 0 1\n 300000000 1000000000\n 100000000 1000000000\n 200000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}]
Print the minimum number of bombs needed to win. * * *
s782575304
Wrong Answer
p02788
Input is given from Standard Input in the following format: N D A X_1 H_1 : X_N H_N
def examA(): H, A = LI() ans = (H - 1) // A + 1 print(ans) return def examB(): H, N = LI() A = LI() if H > sum(A): print("No") else: print("Yes") return def examC(): N, K = LI() H = LI() H.sort() ans = sum(H[: max(0, N - K)]) print(ans) return def examD(): H = I() ans = 2 ** (H.bit_length()) - 1 print(ans) return def examE(): H, N = LI() A = [0] * N B = [0] * N V = [[] for _ in range(N)] for i in range(N): A[i], B[i] = LI() V[i] = [A[i], B[i], A[i] / B[i]] V.sort(key=lambda x: x[2], reverse=True) dp = [[inf] * (H + 1) for _ in range(N + 1)] dp[0][0] = 0 for i in range(N): for j in range(H): dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]) if j <= H - V[i][0]: dp[i + 1][j + V[i][0]] = min(dp[i + 1][j + V[i][0]], dp[i][j] + V[i][1]) else: dp[i + 1][H] = min(dp[i + 1][H], dp[i][j] + V[i][1]) loop = (H - 1) // V[0][0] + 1 ans = [0] * loop for i in range(loop): curH = H - V[0][0] * i ans[i] = i * V[0][1] + min(dp[N][curH:]) print(ans) # print(dp) print(min(ans)) return def examF(): class SegmentTree: def __init__(self, n, ele, segfun): #####ๅ˜ไฝๅ…ƒ######่ฆ่จญๅฎš0or1orinf self.ide_ele = ele self.segfun = segfun #################### self.n = n self.N0 = 1 << n.bit_length() self.data = [self.ide_ele] * (self.N0 * 2) def update_add(self, l, r, val): l += self.N0 r += self.N0 while l < r: if l & 1: self.data[l] += val l += 1 if r & 1: self.data[r - 1] += val r -= 1 l //= 2 r //= 2 def update(self, l, r, val): l += self.N0 r += self.N0 while l < r: if l & 1: self.data[l] = self.segfun(self.data[l], val) l += 1 if r & 1: self.data[r - 1] = self.segfun(self.data[r - 1], val) r -= 1 l //= 2 r //= 2 def query(self, i): i += len(self.data) // 2 ret = self.data[i] while i > 0: i //= 2 ret = self.segfun(ret, self.data[i]) return ret N, D, A = LI() XH = [LI() for _ in range(N)] XH.sort(key=lambda x: x[0]) X = [0] * N for i in range(N): X[i] = XH[i][0] S = SegmentTree(N, 0, lambda a, b: a + b) ans = 0 for i in range(N): cur = (XH[i][1] - 1) // A + 1 cur -= S.query(i) now = bisect.bisect_right(X, X[i] + D * 2) # print(now) S.update_add(i, now, cur) ans += cur print(ans) return import sys, copy, bisect, itertools, heapq, math from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 alphabet = [chr(ord("a") + i) for i in range(26)] if __name__ == "__main__": examF() """ """
Statement Silver Fox is fighting with N monsters. The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the _health_ of H_i. Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health. Silver Fox wins when all the monsters' healths become 0 or below. Find the minimum number of bombs needed to win.
[{"input": "3 3 2\n 1 2\n 5 4\n 9 2", "output": "2\n \n\nFirst, let us use a bomb at the coordinate 4 to decrease the first and second\nmonsters' health by 2.\n\nThen, use a bomb at the coordinate 6 to decrease the second and third\nmonsters' health by 2.\n\nNow, all the monsters' healths are 0. We cannot make all the monsters' health\ndrop to 0 or below with just one bomb.\n\n* * *"}, {"input": "9 4 1\n 1 5\n 2 4\n 3 3\n 4 2\n 5 1\n 6 2\n 7 3\n 8 4\n 9 5", "output": "5\n \n\nWe should use five bombs at the coordinate 5.\n\n* * *"}, {"input": "3 0 1\n 300000000 1000000000\n 100000000 1000000000\n 200000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}]
Print the minimum number of bombs needed to win. * * *
s771864902
Accepted
p02788
Input is given from Standard Input in the following format: N D A X_1 H_1 : X_N H_N
from bisect import * n, d, a, *t = map(int, open(0).read().split()) c = [0] * -~n z = sorted(zip(*[iter(t)] * 2)) s = 0 for i, (x, h) in enumerate(z): c[i] += c[i - 1] h -= c[i] t = 0 - -max(0, h) // a c[i] += t * a c[bisect(z, (x + d + d, 10e9))] -= t * a s += t print(s)
Statement Silver Fox is fighting with N monsters. The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the _health_ of H_i. Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health. Silver Fox wins when all the monsters' healths become 0 or below. Find the minimum number of bombs needed to win.
[{"input": "3 3 2\n 1 2\n 5 4\n 9 2", "output": "2\n \n\nFirst, let us use a bomb at the coordinate 4 to decrease the first and second\nmonsters' health by 2.\n\nThen, use a bomb at the coordinate 6 to decrease the second and third\nmonsters' health by 2.\n\nNow, all the monsters' healths are 0. We cannot make all the monsters' health\ndrop to 0 or below with just one bomb.\n\n* * *"}, {"input": "9 4 1\n 1 5\n 2 4\n 3 3\n 4 2\n 5 1\n 6 2\n 7 3\n 8 4\n 9 5", "output": "5\n \n\nWe should use five bombs at the coordinate 5.\n\n* * *"}, {"input": "3 0 1\n 300000000 1000000000\n 100000000 1000000000\n 200000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}]
Print the minimum number of bombs needed to win. * * *
s674017668
Runtime Error
p02788
Input is given from Standard Input in the following format: N D A X_1 H_1 : X_N H_N
H, N = map(int, input().split()) AB = [] for i in range(N): a, b = map(int, input().split()) AB.append([a, b]) INF = 10**15 dp = [[INF] * (2 * 10**4 + 1) for i in range(N + 1)] for i in range(N + 1): dp[i][0] = 0 for i in range(N): for j in range(1, 2 * 10**4 + 1): dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - AB[i][0]] + AB[i][1]) ans = float("inf") for i in range(H, 2 * 10**4 + 1): ans = min(ans, dp[N][i]) print(ans)
Statement Silver Fox is fighting with N monsters. The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the _health_ of H_i. Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health. Silver Fox wins when all the monsters' healths become 0 or below. Find the minimum number of bombs needed to win.
[{"input": "3 3 2\n 1 2\n 5 4\n 9 2", "output": "2\n \n\nFirst, let us use a bomb at the coordinate 4 to decrease the first and second\nmonsters' health by 2.\n\nThen, use a bomb at the coordinate 6 to decrease the second and third\nmonsters' health by 2.\n\nNow, all the monsters' healths are 0. We cannot make all the monsters' health\ndrop to 0 or below with just one bomb.\n\n* * *"}, {"input": "9 4 1\n 1 5\n 2 4\n 3 3\n 4 2\n 5 1\n 6 2\n 7 3\n 8 4\n 9 5", "output": "5\n \n\nWe should use five bombs at the coordinate 5.\n\n* * *"}, {"input": "3 0 1\n 300000000 1000000000\n 100000000 1000000000\n 200000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}]
Print the minimum number of bombs needed to win. * * *
s601633968
Accepted
p02788
Input is given from Standard Input in the following format: N D A X_1 H_1 : X_N H_N
import bisect import math n, d, a = map(int, input().split()) xh = [] for _ in range(n): x, h = map(int, input().split()) xh.append((x, h)) xh.sort(key=lambda x: x[0]) xs = [x[0] for x in xh] ranges = [] for x in xs: ranges.append(bisect.bisect_right(xs, x + 2 * d)) # N: ๅ‡ฆ็†ใ™ใ‚‹ๅŒบ้–“ใฎ้•ทใ• N = n INF = 2**31 - 1 LV = (N - 1).bit_length() N0 = 2**LV data = [0] * (2 * N0) lazy = [0] * (2 * N0) def gindex(l, r): L = (l + N0) >> 1 R = (r + N0) >> 1 lc = 0 if l & 1 else (L & -L).bit_length() rc = 0 if r & 1 else (R & -R).bit_length() for i in range(LV): if rc <= i: yield R if L < R and lc <= i: yield L L >>= 1 R >>= 1 # ้…ๅปถไผๆฌๅ‡ฆ็† def propagates(*ids): for i in reversed(ids): v = lazy[i - 1] if not v: continue lazy[2 * i - 1] += v lazy[2 * i] += v data[2 * i - 1] += v data[2 * i] += v lazy[i - 1] = 0 # ๅŒบ้–“[l, r)ใซxใ‚’ๅŠ ็ฎ— def update(l, r, x): (*ids,) = gindex(l, r) propagates(*ids) L = N0 + l R = N0 + r while L < R: if R & 1: R -= 1 lazy[R - 1] += x data[R - 1] += x if L & 1: lazy[L - 1] += x data[L - 1] += x L += 1 L >>= 1 R >>= 1 for i in ids: data[i - 1] = min(data[2 * i - 1], data[2 * i]) # ๅŒบ้–“[l, r)ๅ†…ใฎๆœ€ๅฐๅ€คใ‚’ๆฑ‚ใ‚ใ‚‹ def query(l, r): propagates(*gindex(l, r)) L = N0 + l R = N0 + r s = INF while L < R: if R & 1: R -= 1 s = min(s, data[R - 1]) if L & 1: s = min(s, data[L - 1]) L += 1 L >>= 1 R >>= 1 return s for i, (x, h) in enumerate(xh): update(i, i + 1, h) ans = 0 for i in range(n): v = query(i, i + 1) if v > 0: t = math.ceil(v / a) ans += t update(i, ranges[i], -t * a) print(ans)
Statement Silver Fox is fighting with N monsters. The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the _health_ of H_i. Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health. Silver Fox wins when all the monsters' healths become 0 or below. Find the minimum number of bombs needed to win.
[{"input": "3 3 2\n 1 2\n 5 4\n 9 2", "output": "2\n \n\nFirst, let us use a bomb at the coordinate 4 to decrease the first and second\nmonsters' health by 2.\n\nThen, use a bomb at the coordinate 6 to decrease the second and third\nmonsters' health by 2.\n\nNow, all the monsters' healths are 0. We cannot make all the monsters' health\ndrop to 0 or below with just one bomb.\n\n* * *"}, {"input": "9 4 1\n 1 5\n 2 4\n 3 3\n 4 2\n 5 1\n 6 2\n 7 3\n 8 4\n 9 5", "output": "5\n \n\nWe should use five bombs at the coordinate 5.\n\n* * *"}, {"input": "3 0 1\n 300000000 1000000000\n 100000000 1000000000\n 200000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}]
Print the minimum number of bombs needed to win. * * *
s303302917
Accepted
p02788
Input is given from Standard Input in the following format: N D A X_1 H_1 : X_N H_N
from bisect import bisect_right, bisect_left # instead of AVLTree class BITbisect: def __init__(self, InputProbNumbers): # ๅบงๅœง self.ind_to_co = [-(10**18)] self.co_to_ind = {} for ind, num in enumerate(sorted(list(set(InputProbNumbers)))): self.ind_to_co.append(num) self.co_to_ind[num] = ind + 1 self.max = len(self.co_to_ind) self.data = [0] * (self.max + 1) def __str__(self): retList = [] for i in range(1, self.max + 1): x = self.ind_to_co[i] if self.count(x): c = self.count(x) for _ in range(c): retList.append(x) return "[" + ", ".join([str(a) for a in retList]) + "]" def __getitem__(self, key): key += 1 s = 0 ind = 0 l = self.max.bit_length() for i in reversed(range(l)): if ind + (1 << i) <= self.max: if s + self.data[ind + (1 << i)] < key: s += self.data[ind + (1 << i)] ind += 1 << i if ind == self.max or key < 0: raise IndexError("BIT index out of range") return self.ind_to_co[ind + 1] def __len__(self): return self._query_sum(self.max) def __contains__(self, num): if not num in self.co_to_ind: return False return self.count(num) > 0 # 0ใ‹ใ‚‰iใพใงใฎๅŒบ้–“ๅ’Œ # ๅทฆใซ้€ฒใ‚“ใงใ„ใ def _query_sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s # i็•ช็›ฎใฎ่ฆ็ด ใซxใ‚’่ถณใ™ # ไธŠใซ็™ปใฃใฆใ„ใ def _add(self, i, x): while i <= self.max: self.data[i] += x i += i & -i def add(self, co, x): i = self.co_to_ind[co] while i > 0: self.data[i] += x i -= i & -i def now(self, x): i = self.co_to_ind[x] ret = 0 while i <= self.max: ret += self.data[i] i += i & -i return ret # ๅ€คxใ‚’ๆŒฟๅ…ฅ def push(self, x): if not x in self.co_to_ind: raise KeyError("The pushing number didnt initialized") self._add(self.co_to_ind[x], 1) # ๅ€คxใ‚’ๅ‰Š้™ค def delete(self, x): if not x in self.co_to_ind: raise KeyError("The deleting number didnt initialized") if self.count(x) <= 0: raise ValueError("The deleting number doesnt exist") self._add(self.co_to_ind[x], -1) # ่ฆ็ด xใฎๅ€‹ๆ•ฐ def count(self, x): return self._query_sum(self.co_to_ind[x]) - self._query_sum( self.co_to_ind[x] - 1 ) # ๅ€คxใ‚’่ถ…ใˆใ‚‹ๆœ€ไฝŽind def bisect_right(self, x): if x in self.co_to_ind: i = self.co_to_ind[x] else: i = bisect_right(self.ind_to_co, x) - 1 return self._query_sum(i) # ๅ€คxใ‚’ไธ‹ๅ›žใ‚‹ๆœ€ไฝŽind def bisect_left(self, x): if x in self.co_to_ind: i = self.co_to_ind[x] else: i = bisect_left(self.ind_to_co, x) if i == 1: return 0 return self._query_sum(i - 1) import sys input = sys.stdin.readline N, D, A = map(int, input().split()) XH = [list(map(int, input().split())) for _ in range(N)] if D == 0: ans = 0 for x, h in XH: ans += (h + A - 1) // A else: XH.sort() Input = [] for x, h in XH: Input.append(x) Input.sort() bit = BITbisect(Input) ans = 0 for x, h in XH: now = bit.now(x) if now >= h: continue count = (h - now + A - 1) // A ans += count nx = Input[bisect_right(Input, x + 2 * D) - 1] bit.add(nx, A * count) print(ans)
Statement Silver Fox is fighting with N monsters. The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the _health_ of H_i. Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health. Silver Fox wins when all the monsters' healths become 0 or below. Find the minimum number of bombs needed to win.
[{"input": "3 3 2\n 1 2\n 5 4\n 9 2", "output": "2\n \n\nFirst, let us use a bomb at the coordinate 4 to decrease the first and second\nmonsters' health by 2.\n\nThen, use a bomb at the coordinate 6 to decrease the second and third\nmonsters' health by 2.\n\nNow, all the monsters' healths are 0. We cannot make all the monsters' health\ndrop to 0 or below with just one bomb.\n\n* * *"}, {"input": "9 4 1\n 1 5\n 2 4\n 3 3\n 4 2\n 5 1\n 6 2\n 7 3\n 8 4\n 9 5", "output": "5\n \n\nWe should use five bombs at the coordinate 5.\n\n* * *"}, {"input": "3 0 1\n 300000000 1000000000\n 100000000 1000000000\n 200000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}]
Print the minimum number of bombs needed to win. * * *
s613091133
Accepted
p02788
Input is given from Standard Input in the following format: N D A X_1 H_1 : X_N H_N
import sys input = sys.stdin.readline N, D, A = map(int, input().split()) M = [list(map(int, input().split())) for i in range(N)] M.sort() PLACE = [M[i][0] for i in range(N)] HP = [M[i][1] for i in range(N)] seg_el = 1 << (N.bit_length()) # Segment treeใฎๅฐใฎ่ฆ็ด ๆ•ฐ SEG = [0] * (2 * seg_el) # 1-indexedใชใฎใงใ€่ฆ็ด ๆ•ฐ2*seg_el.Segment treeใฎๅˆๆœŸๅ€คใงๅˆๆœŸๅŒ– LAZY = [0] * ( 2 * seg_el ) # 1-indexedใชใฎใงใ€่ฆ็ด ๆ•ฐ2*seg_el.Segment treeใฎๅˆๆœŸๅ€คใงๅˆๆœŸๅŒ– for i in range(N): SEG[i + seg_el] = HP[i] def indexes( L, R ): # ้…ๅปถไผๆฌใ™ในใใƒŽใƒผใƒ‰ใฎใƒชใ‚นใƒˆใ‚’ไธ‹ใ‹ใ‚‰ไธŠใฎ้ †ใซ่ฟ”ใ™. ๏ผˆใคใพใ‚Š, updateใ‚„getvaluesใง่ฆ‹ใ‚‹ใƒŽใƒผใƒ‰ใ‚ˆใ‚ŠไธŠใซใ‚ใ‚‹ใƒŽใƒผใƒ‰ใŸใก๏ผ‰ INDLIST = [] R -= 1 L >>= 1 R >>= 1 while L != R: if L > R: INDLIST.append(L) L >>= 1 else: INDLIST.append(R) R >>= 1 while L != 0: INDLIST.append(L) L >>= 1 return INDLIST def adds(l, r, x): # ๅŒบ้–“[l,r)ใ‚’ +x ๆ›ดๆ–ฐ L = l + seg_el R = r + seg_el L //= L & (-L) R //= R & (-R) UPIND = indexes(L, R) for ind in UPIND[ ::-1 ]: # ้…ๅปถไผๆฌ. ไธŠใ‹ใ‚‰ๆ›ดๆ–ฐใ—ใฆใ„ใ. ๏ผˆใŸใ ใ—, ไปŠๅ›žใฏใ†ใพใใ‚„ใ‚‹ใจใ“ใฎ้ƒจๅˆ†ใ‚’็œใ‘ใ‚‹. addใฏใ‚ฏใ‚จใƒชใฎ้ †็•ชใซใ‚ˆใ‚‰ใชใ„ใฎใง. addใงใฏใชใ, updateใฎๅ ดๅˆๅฟ…่ฆ๏ผ‰ if LAZY[ind] != 0: plus_lazy = LAZY[ind] SEG[ind << 1] += plus_lazy SEG[1 + (ind << 1)] += plus_lazy LAZY[ind << 1] += plus_lazy LAZY[1 + (ind << 1)] += plus_lazy LAZY[ind] = 0 while L != R: if L > R: SEG[L] += x LAZY[L] += x L += 1 L //= L & (-L) else: R -= 1 SEG[R] += x LAZY[R] += x R //= R & (-R) for ind in UPIND: SEG[ind] = min( SEG[ind << 1], SEG[1 + (ind << 1)] ) # ๆœ€ๅˆใฎ้…ๅปถไผๆฌใ‚’็œใ„ใŸๅ ดๅˆ, ใ“ใ“ใ‚’ๅค‰ใˆใ‚‹ def getvalues(l, r): # ๅŒบ้–“[l,r)ใซ้–ขใ™ใ‚‹minใ‚’่ชฟในใ‚‹ L = l + seg_el R = r + seg_el L //= L & (-L) R //= R & (-R) UPIND = indexes(L, R) for ind in UPIND[::-1]: # ้…ๅปถไผๆฌ if LAZY[ind] != 0: plus_lazy = LAZY[ind] SEG[ind << 1] += plus_lazy SEG[1 + (ind << 1)] += plus_lazy LAZY[ind << 1] += plus_lazy LAZY[1 + (ind << 1)] += plus_lazy LAZY[ind] = 0 ANS = 1 << 31 while L != R: if L > R: ANS = min(ANS, SEG[L]) L += 1 L //= L & (-L) else: R -= 1 ANS = min(ANS, SEG[R]) R //= R & (-R) return ANS plind = 0 ANS = 0 import bisect while plind < N: RHP = getvalues(plind, plind + 1) if RHP > 0: MAX = PLACE[plind] + 2 * D x = bisect.bisect_right(PLACE, MAX) adds(0, x, (-RHP // A) * A) ANS += -(-RHP // A) else: plind += 1 print(ANS)
Statement Silver Fox is fighting with N monsters. The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the _health_ of H_i. Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health. Silver Fox wins when all the monsters' healths become 0 or below. Find the minimum number of bombs needed to win.
[{"input": "3 3 2\n 1 2\n 5 4\n 9 2", "output": "2\n \n\nFirst, let us use a bomb at the coordinate 4 to decrease the first and second\nmonsters' health by 2.\n\nThen, use a bomb at the coordinate 6 to decrease the second and third\nmonsters' health by 2.\n\nNow, all the monsters' healths are 0. We cannot make all the monsters' health\ndrop to 0 or below with just one bomb.\n\n* * *"}, {"input": "9 4 1\n 1 5\n 2 4\n 3 3\n 4 2\n 5 1\n 6 2\n 7 3\n 8 4\n 9 5", "output": "5\n \n\nWe should use five bombs at the coordinate 5.\n\n* * *"}, {"input": "3 0 1\n 300000000 1000000000\n 100000000 1000000000\n 200000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}]
Print the minimum number of bombs needed to win. * * *
s501513370
Wrong Answer
p02788
Input is given from Standard Input in the following format: N D A X_1 H_1 : X_N H_N
def main(): N, D, A = (int(i) for i in input().split()) P = [[int(i) for i in input().split()] for j in range(N)] P.sort() X = [x[0] for x in P] H = [h[1] for h in P] diff = [H[0]] + [H[i + 1] - H[i] for i in range(N - 1)] BIT = [0] * (N + 1) def BIT_query(idx): """A1 ~ Aiใพใงใฎๅ’Œ(1-index)""" res_sum = 0 while idx > 0: res_sum += BIT[idx] idx -= idx & -idx return res_sum def BIT_update(idx, x): """Aiใซxใ‚’ๅŠ ็ฎ—(1-index)""" while idx <= N: BIT[idx] += x idx += idx & -idx return def BIT_init(A): for i, e in enumerate(A): BIT_update(i + 1, e) BIT_init(diff) from bisect import bisect_right ans = 0 for left in range(N): x = P[left][0] h = BIT_query(left + 1) cur = (h + A - 1) // A damage = cur * A BIT_update(left + 1, -damage) right = bisect_right(X, x + 2 * D) BIT_update(right + 1, damage) ans += cur print(ans) if __name__ == "__main__": main()
Statement Silver Fox is fighting with N monsters. The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the _health_ of H_i. Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health. Silver Fox wins when all the monsters' healths become 0 or below. Find the minimum number of bombs needed to win.
[{"input": "3 3 2\n 1 2\n 5 4\n 9 2", "output": "2\n \n\nFirst, let us use a bomb at the coordinate 4 to decrease the first and second\nmonsters' health by 2.\n\nThen, use a bomb at the coordinate 6 to decrease the second and third\nmonsters' health by 2.\n\nNow, all the monsters' healths are 0. We cannot make all the monsters' health\ndrop to 0 or below with just one bomb.\n\n* * *"}, {"input": "9 4 1\n 1 5\n 2 4\n 3 3\n 4 2\n 5 1\n 6 2\n 7 3\n 8 4\n 9 5", "output": "5\n \n\nWe should use five bombs at the coordinate 5.\n\n* * *"}, {"input": "3 0 1\n 300000000 1000000000\n 100000000 1000000000\n 200000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}]
Print the minimum number of bombs needed to win. * * *
s989463933
Wrong Answer
p02788
Input is given from Standard Input in the following format: N D A X_1 H_1 : X_N H_N
import sys input = sys.stdin.readline N, D, A = [int(_) for _ in input().split()] XH = sorted([[int(_) for _ in input().split()] + [0] for _ in range(N)]) XH2 = [[xh[0] + 2 * D + 1, i, 1] for i, xh in enumerate(XH)] XH3 = sorted(XH + XH2) bombs = [-1] * N for i, xh in enumerate(XH3): if xh[2]: bombs[xh[1]] = i - xh[1] class LazySegmentTree: def __init__(self, array, f, g, h, ti, ei): """ Parameters ---------- array : list to construct segment tree from f : func binary operation of the monoid T x T -> T T is dat g : func binary operation of the monoid T x E -> T T is dat, E is laz h : func binary operation of the monoid E x E -> T E is laz ti : T identity element of T ei : E identity element of E """ self.f = f self.g = g self.h = h self.ti = ti self.ei = ei self.height = height = len(array).bit_length() self.n = n = 2**height self.dat = dat = [ti] * n + array + [ti] * (n - len(array)) self.laz = [ei] * (2 * n) for i in range(n - 1, 0, -1): # build dat[i] = f(dat[i << 1], dat[i << 1 | 1]) def reflect(self, k): dat = self.dat ei = self.ei laz = self.laz g = self.g return self.dat[k] if laz[k] is ei else g(dat[k], laz[k]) def evaluate(self, k): laz = self.laz ei = self.ei reflect = self.reflect dat = self.dat h = self.h if laz[k] is ei: return laz[(k << 1) | 0] = h(laz[(k << 1) | 0], laz[k]) laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]) dat[k] = reflect(k) laz[k] = ei def thrust(self, k): height = self.height evaluate = self.evaluate for i in range(height, 0, -1): evaluate(k >> i) def recalc(self, k): dat = self.dat reflect = self.reflect f = self.f while k: k >>= 1 dat[k] = f(reflect((k << 1) | 0), reflect((k << 1) | 1)) def update(self, a, b, x): # set value at position [a, b) (0-indexed) thrust = self.thrust n = self.n h = self.h laz = self.laz recalc = self.recalc a += n b += n - 1 l = a r = b + 1 thrust(a) thrust(b) while l < r: if l & 1: laz[l] = h(laz[l], x) l += 1 if r & 1: r -= 1 laz[r] = h(laz[r], x) l >>= 1 r >>= 1 recalc(a) recalc(b) def set_val(self, a, x): n = self.n thrust = self.thrust dat = self.dat laz = self.laz recalc = self.recalc ei = self.ei a += n thrust(a) dat[a] = x laz[a] = ei recalc(a) def get_val(self, a): a += self.n res = self.dat[a] while a: if self.laz[a] != self.ei: res = self.g(res, self.laz[a]) a //= 2 return res def query(self, a, b): # result on interval [a, b) (0-indexed) f = self.f ti = self.ti n = self.n thrust = self.thrust reflect = self.reflect a += n b += n - 1 thrust(a) thrust(b) l = a r = b + 1 vl = vr = ti while l < r: if l & 1: vl = f(vl, reflect(l)) l += 1 if r & 1: r -= 1 vr = f(reflect(r), vr) l >>= 1 r >>= 1 return f(vl, vr) # RMQ and RAQ array = [(xh[1], 1) for xh in XH] f = max g = lambda a, b: (a[0] + a[1] * b, a[1]) h = lambda a, b: a + b ti = (-float("inf"), 0) ei = 0 LST = LazySegmentTree(array=array, ti=ti, ei=ei, f=f, g=g, h=h) ans = 0 for i in range(N): this = LST.query(i, i + 1)[0] if this > 0: c = (this - 1) // A + 1 ans += c LST.update(i, bombs[i], -A * c) print(ans)
Statement Silver Fox is fighting with N monsters. The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the _health_ of H_i. Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health. Silver Fox wins when all the monsters' healths become 0 or below. Find the minimum number of bombs needed to win.
[{"input": "3 3 2\n 1 2\n 5 4\n 9 2", "output": "2\n \n\nFirst, let us use a bomb at the coordinate 4 to decrease the first and second\nmonsters' health by 2.\n\nThen, use a bomb at the coordinate 6 to decrease the second and third\nmonsters' health by 2.\n\nNow, all the monsters' healths are 0. We cannot make all the monsters' health\ndrop to 0 or below with just one bomb.\n\n* * *"}, {"input": "9 4 1\n 1 5\n 2 4\n 3 3\n 4 2\n 5 1\n 6 2\n 7 3\n 8 4\n 9 5", "output": "5\n \n\nWe should use five bombs at the coordinate 5.\n\n* * *"}, {"input": "3 0 1\n 300000000 1000000000\n 100000000 1000000000\n 200000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}]
Print the minimum number of bombs needed to win. * * *
s044334551
Wrong Answer
p02788
Input is given from Standard Input in the following format: N D A X_1 H_1 : X_N H_N
n, d, a = map(int, input().split()) ab = [] for _ in range(n): x, h = (int(x) for x in input().split()) ab.append([x, h]) ab.sort() hp_memo = [] for i in range(n): hp_memo.append(ab[i][1]) attack_count = 0 # print(hp_memo) for i in range(n): if hp_memo[i] > 0: if hp_memo[i] % a == 0: attack_count += hp_memo[i] // a damage = hp_memo[i] else: attack_count += 1 + (hp_memo[i] // a) damage = (1 + a) * (hp_memo[i] // a) right = ab[i][0] + (2 * d) while i < n and ab[i][0] <= right: hp_memo[i] -= damage i += 1 # print(hp_memo,damage) print(attack_count)
Statement Silver Fox is fighting with N monsters. The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the _health_ of H_i. Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health. Silver Fox wins when all the monsters' healths become 0 or below. Find the minimum number of bombs needed to win.
[{"input": "3 3 2\n 1 2\n 5 4\n 9 2", "output": "2\n \n\nFirst, let us use a bomb at the coordinate 4 to decrease the first and second\nmonsters' health by 2.\n\nThen, use a bomb at the coordinate 6 to decrease the second and third\nmonsters' health by 2.\n\nNow, all the monsters' healths are 0. We cannot make all the monsters' health\ndrop to 0 or below with just one bomb.\n\n* * *"}, {"input": "9 4 1\n 1 5\n 2 4\n 3 3\n 4 2\n 5 1\n 6 2\n 7 3\n 8 4\n 9 5", "output": "5\n \n\nWe should use five bombs at the coordinate 5.\n\n* * *"}, {"input": "3 0 1\n 300000000 1000000000\n 100000000 1000000000\n 200000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}]
In the first line, print the sequence S. Two consequtive elements should be separated by a space character. In the second line, print the number of comparisons.
s176035452
Runtime Error
p02272
In the first line _n_ is given. In the second line, _n_ integers are given.
h, w = [int(n) for n in input().split()] for i in range(0, h): for j in range(0, w): print("#", end="") print()
Merge Sort Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. Merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; create array L[0...n1], R[0...n2] for i = 0 to n1-1 do L[i] = A[left + i] for i = 0 to n2-1 do R[i] = A[mid + i] L[n1] = SENTINEL R[n2] = SENTINEL i = 0; j = 0; for k = left to right-1 if L[i] <= R[j] then A[k] = L[i] i = i + 1 else A[k] = R[j] j = j + 1 Merge-Sort(A, left, right){ if left+1 < right then mid = (left + right)/2; call Merge-Sort(A, left, mid) call Merge-Sort(A, mid, right) call Merge(A, left, mid, right)
[{"input": "10\n 8 5 9 2 6 3 7 1 10 4", "output": "1 2 3 4 5 6 7 8 9 10\n 34"}]
In the first line, print the sequence S. Two consequtive elements should be separated by a space character. In the second line, print the number of comparisons.
s235486288
Accepted
p02272
In the first line _n_ is given. In the second line, _n_ integers are given.
# def merge(arr, l, mid, r): # L = [arr[i] for i in range(l, mid)] # R = [arr[i] for i in range(mid, r)] # L.append(int(1e9 + 10)) # R.append(int(1e9 + 10)) # i, j = 0, 0 # cnt = 0 # for k in range(l, r): # if L[i] <= R[j]: # arr[k] = L[i] # i += 1 # else: # arr[k] = R[j] # j += 1 # cnt += 1 # return cnt # def mergeSort(arr, l, r): # cnt = 0 # if l + 1 < r: # mid = (l + r) >> 1 # cnt += mergeSort(arr, l, mid) # cnt += mergeSort(arr, mid, r) # cnt += merge(arr, l, mid, r) # return cnt # triky def count(l, r): cnt = 0 if l + 1 < r: mid = (l + r) >> 1 cnt += count(l, mid) cnt += count(mid, r) cnt += r - l return cnt cnt = count(0, int(input())) arr = list(map(int, input().split())) arr.sort() print(*arr) print(cnt)
Merge Sort Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. Merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; create array L[0...n1], R[0...n2] for i = 0 to n1-1 do L[i] = A[left + i] for i = 0 to n2-1 do R[i] = A[mid + i] L[n1] = SENTINEL R[n2] = SENTINEL i = 0; j = 0; for k = left to right-1 if L[i] <= R[j] then A[k] = L[i] i = i + 1 else A[k] = R[j] j = j + 1 Merge-Sort(A, left, right){ if left+1 < right then mid = (left + right)/2; call Merge-Sort(A, left, mid) call Merge-Sort(A, mid, right) call Merge(A, left, mid, right)
[{"input": "10\n 8 5 9 2 6 3 7 1 10 4", "output": "1 2 3 4 5 6 7 8 9 10\n 34"}]
In the first line, print the sequence S. Two consequtive elements should be separated by a space character. In the second line, print the number of comparisons.
s435000939
Accepted
p02272
In the first line _n_ is given. In the second line, _n_ integers are given.
def merge(targ, first, mid, last): left = targ[first:mid] + [10**9 + 1] right = targ[mid:last] + [10**9 + 1] leftcnt = rightcnt = 0 global ans for i in range(first, last): ans += 1 # print(left,right,left[leftcnt],right[rightcnt],targ,ans) if left[leftcnt] <= right[rightcnt]: targ[i] = left[leftcnt] leftcnt += 1 else: targ[i] = right[rightcnt] rightcnt += 1 def mergesort(targ, first, last): if first + 1 >= last: pass else: mid = (first + last) // 2 mergesort(targ, first, mid) mergesort(targ, mid, last) merge(targ, first, mid, last) ans = 0 num = int(input()) targ = [int(n) for n in input().split(" ")] mergesort(targ, 0, num) print(" ".join([str(n) for n in targ])) print(ans)
Merge Sort Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. Merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; create array L[0...n1], R[0...n2] for i = 0 to n1-1 do L[i] = A[left + i] for i = 0 to n2-1 do R[i] = A[mid + i] L[n1] = SENTINEL R[n2] = SENTINEL i = 0; j = 0; for k = left to right-1 if L[i] <= R[j] then A[k] = L[i] i = i + 1 else A[k] = R[j] j = j + 1 Merge-Sort(A, left, right){ if left+1 < right then mid = (left + right)/2; call Merge-Sort(A, left, mid) call Merge-Sort(A, mid, right) call Merge(A, left, mid, right)
[{"input": "10\n 8 5 9 2 6 3 7 1 10 4", "output": "1 2 3 4 5 6 7 8 9 10\n 34"}]
Print the answer. * * *
s083670135
Runtime Error
p02622
Input is given from Standard Input in the following format: S T
S,T = list(input().split()) count=0 for i in range(len(S)): if S[i]!=T[i]: count+=1 print(count)
Statement Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character.
[{"input": "cupofcoffee\n cupofhottea", "output": "4\n \n\nWe can achieve the objective in four operations, such as the following:\n\n * First, replace the sixth character `c` with `h`.\n * Second, replace the eighth character `f` with `t`.\n * Third, replace the ninth character `f` with `t`.\n * Fourth, replace the eleventh character `e` with `a`.\n\n* * *"}, {"input": "abcde\n bcdea", "output": "5\n \n\n* * *"}, {"input": "apple\n apple", "output": "0\n \n\nNo operations may be needed to achieve the objective."}]
Print the answer. * * *
s598828482
Accepted
p02622
Input is given from Standard Input in the following format: S T
print(sum([s != t for s, t in zip(input(), input())]))
Statement Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character.
[{"input": "cupofcoffee\n cupofhottea", "output": "4\n \n\nWe can achieve the objective in four operations, such as the following:\n\n * First, replace the sixth character `c` with `h`.\n * Second, replace the eighth character `f` with `t`.\n * Third, replace the ninth character `f` with `t`.\n * Fourth, replace the eleventh character `e` with `a`.\n\n* * *"}, {"input": "abcde\n bcdea", "output": "5\n \n\n* * *"}, {"input": "apple\n apple", "output": "0\n \n\nNo operations may be needed to achieve the objective."}]
Print the answer. * * *
s217769482
Runtime Error
p02622
Input is given from Standard Input in the following format: S T
a = int(input()) print(a + a**2 + a**3)
Statement Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character.
[{"input": "cupofcoffee\n cupofhottea", "output": "4\n \n\nWe can achieve the objective in four operations, such as the following:\n\n * First, replace the sixth character `c` with `h`.\n * Second, replace the eighth character `f` with `t`.\n * Third, replace the ninth character `f` with `t`.\n * Fourth, replace the eleventh character `e` with `a`.\n\n* * *"}, {"input": "abcde\n bcdea", "output": "5\n \n\n* * *"}, {"input": "apple\n apple", "output": "0\n \n\nNo operations may be needed to achieve the objective."}]
Print the answer. * * *
s055069411
Accepted
p02622
Input is given from Standard Input in the following format: S T
print(sum([1 for s, t in zip(list(input()), list(input())) if s != t]))
Statement Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character.
[{"input": "cupofcoffee\n cupofhottea", "output": "4\n \n\nWe can achieve the objective in four operations, such as the following:\n\n * First, replace the sixth character `c` with `h`.\n * Second, replace the eighth character `f` with `t`.\n * Third, replace the ninth character `f` with `t`.\n * Fourth, replace the eleventh character `e` with `a`.\n\n* * *"}, {"input": "abcde\n bcdea", "output": "5\n \n\n* * *"}, {"input": "apple\n apple", "output": "0\n \n\nNo operations may be needed to achieve the objective."}]
Print the answer. * * *
s327727090
Runtime Error
p02622
Input is given from Standard Input in the following format: S T
k = list(input()) m = list(input()) ams = 0 for i in len(k): if k[i] != m[i]: ams += 1 print(ams)
Statement Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character.
[{"input": "cupofcoffee\n cupofhottea", "output": "4\n \n\nWe can achieve the objective in four operations, such as the following:\n\n * First, replace the sixth character `c` with `h`.\n * Second, replace the eighth character `f` with `t`.\n * Third, replace the ninth character `f` with `t`.\n * Fourth, replace the eleventh character `e` with `a`.\n\n* * *"}, {"input": "abcde\n bcdea", "output": "5\n \n\n* * *"}, {"input": "apple\n apple", "output": "0\n \n\nNo operations may be needed to achieve the objective."}]
Print the answer. * * *
s243802994
Accepted
p02622
Input is given from Standard Input in the following format: S T
import sys sys.setrecursionlimit(10**9) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(input()) def MI(): return map(int, input().split()) def MI1(): return map(int1, input().split()) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def MS(): return input().split() def LS(): return list(input()) def LLS(rows_number): return [LS() for _ in range(rows_number)] def printlist(lst, k=" "): print(k.join(list(map(str, lst)))) INF = float("inf") # from math import ceil, floor, log2 # from collections import deque # from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations # from heapq import heapify, heappop, heappush # import numpy as np # cumsum # from bisect import bisect_left, bisect_right def solve(): S = LS() T = LS() ans = 0 for s, t in zip(S, T): if s != t: ans += 1 print(ans) if __name__ == "__main__": solve()
Statement Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character.
[{"input": "cupofcoffee\n cupofhottea", "output": "4\n \n\nWe can achieve the objective in four operations, such as the following:\n\n * First, replace the sixth character `c` with `h`.\n * Second, replace the eighth character `f` with `t`.\n * Third, replace the ninth character `f` with `t`.\n * Fourth, replace the eleventh character `e` with `a`.\n\n* * *"}, {"input": "abcde\n bcdea", "output": "5\n \n\n* * *"}, {"input": "apple\n apple", "output": "0\n \n\nNo operations may be needed to achieve the objective."}]
Print the answer. * * *
s402398233
Accepted
p02622
Input is given from Standard Input in the following format: S T
def B(): s = input() t = input() count=0 for i in range(len(s)): if s[i]!=t[i]: count = count+1 print(count) B()
Statement Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character.
[{"input": "cupofcoffee\n cupofhottea", "output": "4\n \n\nWe can achieve the objective in four operations, such as the following:\n\n * First, replace the sixth character `c` with `h`.\n * Second, replace the eighth character `f` with `t`.\n * Third, replace the ninth character `f` with `t`.\n * Fourth, replace the eleventh character `e` with `a`.\n\n* * *"}, {"input": "abcde\n bcdea", "output": "5\n \n\n* * *"}, {"input": "apple\n apple", "output": "0\n \n\nNo operations may be needed to achieve the objective."}]
Print the answer. * * *
s294200747
Wrong Answer
p02622
Input is given from Standard Input in the following format: S T
S=input() T=input() S=list(S) T=list(T) for i in range(len(S)): if(S[i]!=T[i]): S[i]=T[i] print(i+1)
Statement Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character.
[{"input": "cupofcoffee\n cupofhottea", "output": "4\n \n\nWe can achieve the objective in four operations, such as the following:\n\n * First, replace the sixth character `c` with `h`.\n * Second, replace the eighth character `f` with `t`.\n * Third, replace the ninth character `f` with `t`.\n * Fourth, replace the eleventh character `e` with `a`.\n\n* * *"}, {"input": "abcde\n bcdea", "output": "5\n \n\n* * *"}, {"input": "apple\n apple", "output": "0\n \n\nNo operations may be needed to achieve the objective."}]
Print the answer. * * *
s050809734
Accepted
p02622
Input is given from Standard Input in the following format: S T
a = input() b = input() list_a = [] list_b = [] score = 0 for n in a: list_a.append(n) for m in b: list_b.append(m) for i in range(0, len(list_a)): if list_a[i] != list_b[i]: score += 1 print(score)
Statement Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character.
[{"input": "cupofcoffee\n cupofhottea", "output": "4\n \n\nWe can achieve the objective in four operations, such as the following:\n\n * First, replace the sixth character `c` with `h`.\n * Second, replace the eighth character `f` with `t`.\n * Third, replace the ninth character `f` with `t`.\n * Fourth, replace the eleventh character `e` with `a`.\n\n* * *"}, {"input": "abcde\n bcdea", "output": "5\n \n\n* * *"}, {"input": "apple\n apple", "output": "0\n \n\nNo operations may be needed to achieve the objective."}]
Print the answer. * * *
s099157401
Wrong Answer
p02622
Input is given from Standard Input in the following format: S T
def levenshtein(s1, s2): """ >>> levenshtein('kitten', 'sitting') 3 >>> levenshtein('ใ‚ใ„ใ†ใˆใŠ', 'ใ‚ใ„ใ†ใˆใŠ') 0 >>> levenshtein('ใ‚ใ„ใ†ใˆใŠ', 'ใ‹ใใใ‘ใ“') 5 """ n, m = len(s1), len(s2) dp = [[0] * (m + 1) for _ in range(n + 1)] for i in range(n + 1): dp[i][0] = i for j in range(m + 1): dp[0][j] = j for i in range(1, n + 1): for j in range(1, m + 1): cost = 0 if s1[i - 1] == s2[j - 1] else 1 dp[i][j] = min( dp[i - 1][j] + 1, # insertion dp[i][j - 1] + 1, # deletion dp[i - 1][j - 1] + cost, ) # replacement return dp[n][m] s1 = input() s2 = input() print(levenshtein(s1, s2))
Statement Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character.
[{"input": "cupofcoffee\n cupofhottea", "output": "4\n \n\nWe can achieve the objective in four operations, such as the following:\n\n * First, replace the sixth character `c` with `h`.\n * Second, replace the eighth character `f` with `t`.\n * Third, replace the ninth character `f` with `t`.\n * Fourth, replace the eleventh character `e` with `a`.\n\n* * *"}, {"input": "abcde\n bcdea", "output": "5\n \n\n* * *"}, {"input": "apple\n apple", "output": "0\n \n\nNo operations may be needed to achieve the objective."}]
Print the answer. * * *
s461921352
Accepted
p02622
Input is given from Standard Input in the following format: S T
print(len(list(filter(lambda x: x[0] != x[1], zip(input(), input())))))
Statement Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character.
[{"input": "cupofcoffee\n cupofhottea", "output": "4\n \n\nWe can achieve the objective in four operations, such as the following:\n\n * First, replace the sixth character `c` with `h`.\n * Second, replace the eighth character `f` with `t`.\n * Third, replace the ninth character `f` with `t`.\n * Fourth, replace the eleventh character `e` with `a`.\n\n* * *"}, {"input": "abcde\n bcdea", "output": "5\n \n\n* * *"}, {"input": "apple\n apple", "output": "0\n \n\nNo operations may be needed to achieve the objective."}]
For each dataset, print 2, -2, 1, or 0 in a line.
s822044398
Runtime Error
p00023
The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$
# your code goes here a, b = input().split(" ") print("%d %d %.5f" % (int(a) / int(b), int(a) % int(b), float(a) / int(b)))
Circles Intersection You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical.
[{"input": "0.0 0.0 5.0 0.0 0.0 4.0\n 0.0 0.0 2.0 4.1 0.0 2.0", "output": "0"}]
For each dataset, print 2, -2, 1, or 0 in a line.
s302002874
Accepted
p00023
The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers: $x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$
for i in range(int(input())): xa, ya, ra, xb, yb, rb = map(float, input().split(" ")) ab_length = ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5 if ra > rb: max_r, min_r, min_c = ra, rb, 2 else: max_r, min_r, min_c = rb, ra, -2 if ab_length > ra + rb: ans = 0 elif ab_length <= ra + rb: if ab_length + min_r < max_r: ans = min_c else: ans = 1 print(ans)
Circles Intersection You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circumference of $A$ and $B$ intersect, and * "0" if $A$ and $B$ do not overlap. You may assume that $A$ and $B$ are not identical.
[{"input": "0.0 0.0 5.0 0.0 0.0 4.0\n 0.0 0.0 2.0 4.1 0.0 2.0", "output": "0"}]
If S is a strong palindrome, print `Yes`; otherwise, print `No`. * * *
s369652859
Wrong Answer
p02730
Input is given from Standard Input in the following format: S
S = input() a = "" b = "" c = "" d = "" # for i in range(0,int((len(S)-1)/2)): # a+=S[i] # for i in range(int((len(S)-1)/2)-1,-1,-1): # b+=S[i] # for j in range(int((len(S)+3)/2)-1,len(S)): # c+=S[j] # for j in range(len(S)-1,int((len(S)+3)/2)-2,-1): # d+=S[j] # # print(a) # # print(b) # # print(c) # # print(d) # if a == b and c==d: # print('Yes') # else: # print('No') mae = "" usiro = "" N = len(S) mae = S[0 : int((N - 1) / 2)] eam = S[-int((N - 1) / 2) :] usiro = S[int((N + 3) / 2) - 1 :] orisu = S[-int(((N + 3) / 2)) + 2 :] # print(mae) # print(eam) # print(usiro) # print(orisu) for i in range(len(mae) - 1, -1, -1): a += mae[i] # print(a) for i in range(len(usiro) - 1, -1, -1): b += usiro[i] # print(b) if mae == a and usiro == b: print("Yes") else: print("No")
Statement A string S of an odd length is said to be a _strong palindrome_ if and only if all of the following conditions are satisfied: * S is a palindrome. * Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome. * The string consisting of the (N+3)/2-st through N-th characters of S is a palindrome. Determine whether S is a strong palindrome.
[{"input": "akasaka", "output": "Yes\n \n\n * S is `akasaka`.\n * The string formed by the 1-st through the 3-rd characters is `aka`.\n * The string formed by the 5-th through the 7-th characters is `aka`. All of these are palindromes, so S is a strong palindrome.\n\n* * *"}, {"input": "level", "output": "No\n \n\n* * *"}, {"input": "atcoder", "output": "No"}]
If S is a strong palindrome, print `Yes`; otherwise, print `No`. * * *
s128866282
Wrong Answer
p02730
Input is given from Standard Input in the following format: S
S = input() N = len(S) s1 = S[0 : (N - 1) // 2] s2 = S[(N + 1) // 2 : N] t = list(s2) t.reverse() s3 = "".join(t) if s1 != s3: print("No") exit() N = len(s1) s4 = s1[0 : (N - 1) // 2] s5 = s1[(N + 1) // 2 : N] t = list(s5) t.reverse() s6 = "".join(t) if s4 != s6: print("No") exit() N = len(s2) s7 = s2[0 : (N - 1) // 2] s8 = s2[(N + 1) // 2 : N] t = list(s8) t.reverse() s9 = "".join(t) if s7 != s9: print("No") exit() print("Yes")
Statement A string S of an odd length is said to be a _strong palindrome_ if and only if all of the following conditions are satisfied: * S is a palindrome. * Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome. * The string consisting of the (N+3)/2-st through N-th characters of S is a palindrome. Determine whether S is a strong palindrome.
[{"input": "akasaka", "output": "Yes\n \n\n * S is `akasaka`.\n * The string formed by the 1-st through the 3-rd characters is `aka`.\n * The string formed by the 5-th through the 7-th characters is `aka`. All of these are palindromes, so S is a strong palindrome.\n\n* * *"}, {"input": "level", "output": "No\n \n\n* * *"}, {"input": "atcoder", "output": "No"}]
If S is a strong palindrome, print `Yes`; otherwise, print `No`. * * *
s008398953
Wrong Answer
p02730
Input is given from Standard Input in the following format: S
X = input() L = X[::-1] if L == X: N = len(X) if N % 2 == 1: a = int((N - 1) / 2) b = int((N + 3) / 2) Ya = X[0:a] LYa = Ya[::-1] Yb = X[b - 1 : N] LYb = Yb[::-1] if LYa == Ya: if LYb == Yb: print("Yes") else: print("No")
Statement A string S of an odd length is said to be a _strong palindrome_ if and only if all of the following conditions are satisfied: * S is a palindrome. * Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome. * The string consisting of the (N+3)/2-st through N-th characters of S is a palindrome. Determine whether S is a strong palindrome.
[{"input": "akasaka", "output": "Yes\n \n\n * S is `akasaka`.\n * The string formed by the 1-st through the 3-rd characters is `aka`.\n * The string formed by the 5-th through the 7-th characters is `aka`. All of these are palindromes, so S is a strong palindrome.\n\n* * *"}, {"input": "level", "output": "No\n \n\n* * *"}, {"input": "atcoder", "output": "No"}]
If S is a strong palindrome, print `Yes`; otherwise, print `No`. * * *
s581855571
Wrong Answer
p02730
Input is given from Standard Input in the following format: S
S = input() N = len(S) str_num = -1 reverse_S = "" # ๆกไปถ1๏ผˆSใŒๅ›žๆ–‡ใงใ‚ใ‚‹ใ‹๏ผ‰ for i in range(-1, -(N + 1), -1): reverse_S = reverse_S + S[i] if S == reverse_S: condition1 = "YES" else: condition1 = "NO" # ๆกไปถ2 S2 = "" N2 = int((N - 1) / 2) for i in range(N2): S2 = S2 + S[i] reverse_S2 = "" for i in range(-1, -(N2 + 1), -1): reverse_S2 = reverse_S2 + S2[i] if S2 == reverse_S2: condition2 = "YES" else: condition2 = "NO" # ๆกไปถ3 S3 = "" N3 = int((N + 3) / 2) for i in range(N3 - 1, N): S3 = S3 + S[i] reverse_S3 = "" for i in range(-1, -(N3 - 1), -1): reverse_S3 = reverse_S3 + S3[i] if S3 == reverse_S3: condition3 = "YES" else: condition3 = "NO" if condition1 == condition2 == condition3: print("Yes") else: print("No")
Statement A string S of an odd length is said to be a _strong palindrome_ if and only if all of the following conditions are satisfied: * S is a palindrome. * Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome. * The string consisting of the (N+3)/2-st through N-th characters of S is a palindrome. Determine whether S is a strong palindrome.
[{"input": "akasaka", "output": "Yes\n \n\n * S is `akasaka`.\n * The string formed by the 1-st through the 3-rd characters is `aka`.\n * The string formed by the 5-th through the 7-th characters is `aka`. All of these are palindromes, so S is a strong palindrome.\n\n* * *"}, {"input": "level", "output": "No\n \n\n* * *"}, {"input": "atcoder", "output": "No"}]
If S is a strong palindrome, print `Yes`; otherwise, print `No`. * * *
s361113013
Runtime Error
p02730
Input is given from Standard Input in the following format: S
x = int(input()) a = x // 500 b = (x - 500 * a) // 5 print(int(1000 * a + 5 * b))
Statement A string S of an odd length is said to be a _strong palindrome_ if and only if all of the following conditions are satisfied: * S is a palindrome. * Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome. * The string consisting of the (N+3)/2-st through N-th characters of S is a palindrome. Determine whether S is a strong palindrome.
[{"input": "akasaka", "output": "Yes\n \n\n * S is `akasaka`.\n * The string formed by the 1-st through the 3-rd characters is `aka`.\n * The string formed by the 5-th through the 7-th characters is `aka`. All of these are palindromes, so S is a strong palindrome.\n\n* * *"}, {"input": "level", "output": "No\n \n\n* * *"}, {"input": "atcoder", "output": "No"}]