output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the minimum possible total cost incurred. * * *
s360107306
Runtime Error
p03160
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N
import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log from collections import defaultdict as dd, deque, Counter as C, OrderedDict as od from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect from time import perf_counter from fractions import Fraction # sys.setrecursionlimit(pow(10, 6)) # sys.stdin = open("input.txt", "r") # sys.stdout = open("output.txt", "w") mod = pow(10, 9) + 7 mod2 = 998244353 def data(): return sys.stdin.readline().strip() def out(*var, end="\n"): sys.stdout.write(" ".join(map(str, var)) + end) def l(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int, data().split()) def ssp(): return map(str, data().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)] n = int(data()) arr = l() dp = dd(lambda: inf) dp[n - 1] = 0 for i in range(n - 2, -1, -1): dp[i] = min(dp[i], dp[i + 1] + abs(arr[i + 1] - arr[i])) if i != n - 2: dp[i] = min(dp[i], dp[i + 2] + abs(arr[i + 2] - arr[i])) out(dp[0])
Statement There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
[{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}]
Print the minimum possible total cost incurred. * * *
s430476457
Runtime Error
p03160
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N
from sys import stdin, gettrace import sys if not gettrace(): def input(): return next(stdin)[:-1] # def input(): # return stdin.buffer.readline() def main(): def mincost(n,h): dp=[-1 for i in range(n)] dp[n-1]=0 dp[n-2]=abs(h[n-2]-h[n-1]) for i in range(n-3,-1,-1): mn=min(i+k+1,n) mnm=sys.maxsize for j in range(i+1,mn): mnm=min(dp[j]+abs(h[j]-h[i]),mnm) dp[i]=mnm return dp[0] n,k=map(int,input().split()) h=[int(x) for x in input().split()] print(mincost(n,h)) if __name__ == "__main__": main()
Statement There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
[{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}]
Print the minimum possible total cost incurred. * * *
s194339704
Runtime Error
p03160
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N
## necessary imports import sys input = sys.stdin.readline from math import log2, log, ceil # swap_array function def swaparr(arr, a, b): temp = arr[a] arr[a] = arr[b] arr[b] = temp ## gcd function def gcd(a, b): if a == 0: return b return gcd(b % a, a) ## nCr function efficient using Binomial Cofficient def nCr(n, k): if k > n - k: k = n - k res = 1 for i in range(k): res = res * (n - i) res = res / (i + 1) return res ## upper bound function code -- such that e in a[:i] e < x; def upper_bound(a, x, lo=0): hi = len(a) while lo < hi: mid = (lo + hi) // 2 if a[mid] < x: lo = mid + 1 else: hi = mid return lo ## prime factorization def primefs(n): ## if n == 1 ## calculating primes primes = {} while n % 2 == 0: primes[2] = primes.get(2, 0) + 1 n = n // 2 for i in range(3, int(n**0.5) + 2, 2): while n % i == 0: primes[i] = primes.get(i, 0) + 1 n = n // i if n > 2: primes[n] = primes.get(n, 0) + 1 ## prime factoriazation of n is stored in dictionary ## primes and can be accesed. O(sqrt n) return primes ## MODULAR EXPONENTIATION FUNCTION def power(x, y, p): res = 1 x = x % p if x == 0: return 0 while y > 0: if (y & 1) == 1: res = (res * x) % p y = y >> 1 x = (x * x) % p return res ## DISJOINT SET UNINON FUNCTIONS def swap(a, b): temp = a a = b b = temp return a, b # find function with path compression included (recursive) # def find(x, link): # if link[x] == x: # return x # link[x] = find(link[x], link); # return link[x]; # find function with path compression (ITERATIVE) def find(x, link): p = x while p != link[p]: p = link[p] while x != p: nex = link[x] link[x] = p x = nex return p # the union function which makes union(x,y) # of two nodes x and y def union(x, y, link, size): x = find(x, link) y = find(y, link) if size[x] < size[y]: x, y = swap(x, y) if x != y: size[x] += size[y] link[y] = x ## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES def sieve(n): prime = [True for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 return prime #### PRIME FACTORIZATION IN O(log n) using Sieve #### MAXN = int(1e6 + 5) def spf_sieve(): spf[1] = 1 for i in range(2, MAXN): spf[i] = i for i in range(4, MAXN, 2): spf[i] = 2 for i in range(3, ceil(MAXN**0.5), 2): if spf[i] == i: for j in range(i * i, MAXN, i): if spf[j] == j: spf[j] = i ## function for storing smallest prime factors (spf) in the array ################## un-comment below 2 lines when using factorization ################# # spf = [0 for i in range(MAXN)] # spf_sieve() def factoriazation(x): ret = {} while x != 1: ret[spf[x]] = ret.get(spf[x], 0) + 1 x = x // spf[x] return ret ## this function is useful for multiple queries only, o/w use ## primefs function above. complexity O(log n) ## taking integer array input def int_array(): return list(map(int, input().strip().split())) ## taking string array input def str_array(): return input().strip().split() # defining a couple constants MOD = int(1e9) + 7 CMOD = 998244353 INF = float("inf") NINF = -float("inf") ################### ---------------- TEMPLATE ENDS HERE ---------------- ################### ## Top-Down Approach -- Memoization.. n = int(input()) a = int_array() dp = [-1] * n def function(x): if x == 0: return 0 if x == 1: return abs(a[1] - a[0]) if dp[x] != -1: return dp[x] y = abs(a[x] - a[x - 1]) + function(x - 1) z = abs(a[x] - a[x - 2]) + function(x - 2) dp[x] = min(y, z) return dp[x] ans = function(n - 1) print(ans)
Statement There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
[{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}]
Print the minimum possible total cost incurred. * * *
s678016178
Runtime Error
p03160
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N
N, W = map(int, input().split()) Wlist = [] Vlist = [] for i in range(N): w, v = map(int, input().split()) Wlist += [w] Vlist += [v] dp = [[0 for p in range(W + 1)] for i in range(N)] for i in range(W + 1): if i >= Wlist[0]: dp[0][i] = Vlist[0] for i in range(1, N): wi = Wlist[i] for j in range(W + 1): if j - wi >= 0: dp[i][j] = max(dp[i - 1][j - wi] + Vlist[i], dp[i - 1][j]) else: dp[i][j] = max(dp[i - 1][j], dp[i][j]) print(max(dp[N - 1]))
Statement There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
[{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}]
Print the minimum possible total cost incurred. * * *
s184024484
Runtime Error
p03160
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N
N, W = map(int, input().split()) w = [] v = [] for i in range(N): w_, v_ = map(int, input().split()) w.append(w_) v.append(v_) dp = [[0] * (W + 1) for _ in range(N + 1)] def memo(i, j): if dp[i][j]: return dp[i][j] if i == N: dp[i][j] = 0 elif w[i] > j: dp[i][j] = memo(i + 1, j) else: dp[i][j] = max(memo(i + 1, j), memo(i + 1, j - w[i]) + v[i]) return dp[i][j] print(memo(0, W))
Statement There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
[{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}]
Print the minimum possible total cost incurred. * * *
s610339787
Runtime Error
p03160
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N
n,x=map(int,input().split()) a=list(map(int,input().split())) dp=[-1]*n dp[0]=0 if n=<x: x=n-1 for i in range(1,x+1): dp[i]=abs(a[i]-a[0]) for i in range(x+1,n): min1=10**9 for j in range(i-(x),i): if min1>dp[j]+abs(a[j]-a[i]): min1=dp[j]+abs(a[j]-a[i]) dp[i]=min1 print(dp[-1])
Statement There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
[{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}]
Print the minimum possible total cost incurred. * * *
s569549318
Accepted
p03160
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N
N = int(input()) H = list(map(int, input().split())) D = [0 for i in range(N + 1)] # D[i]をiまでで、最短コストとなるやりかたとする。 if N == 1: D[N] = 0 if N == 2: D[N] = abs(H[1] - H[0]) if N > 2: for i in range(N + 1): if i == 0: D[i] = 0 if i == 1: D[i] = 0 if i == 2: D[i] = abs(H[1] - H[0]) if i > 2: D[i] = min( (D[i - 2] + abs(H[i - 1] - H[i - 3])), (D[i - 1] + abs(H[i - 1] - H[i - 2])), ) print(D[N])
Statement There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
[{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}]
Print the minimum possible total cost incurred. * * *
s652303303
Accepted
p03160
Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N
def delta(a, b): return abs(a - b) n, *hs = [int(x) for x in open(0).read().split()] l = len(hs) delta = lambda a, b: abs(hs[a] - hs[b]) dp = [0, delta(1, 0)] for i in range(2, l): dp.append(min(dp[i - 1] + delta(i, i - 1), dp[i - 2] + delta(i, i - 2))) print(dp[-1])
Statement There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
[{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}]
If Takahashi will win, print `First`. If Aoki will win, print `Second`. * * *
s580695920
Runtime Error
p03863
The input is given from Standard Input in the following format: s
s=input() l=len(s) if s[0]==s[-1]: if l%2=1: print("First") else: print("Second") else: if l%2=0: print("First") else: print("Second")
Statement There is a string s of length 3 or greater. No two neighboring characters in s are equal. Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first: * Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s. The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.
[{"input": "aba", "output": "Second\n \n\nTakahashi, who goes first, cannot perform the operation, since removal of the\n`b`, which is the only character not at either ends of s, would result in s\nbecoming `aa`, with two `a`s neighboring.\n\n* * *"}, {"input": "abc", "output": "First\n \n\nWhen Takahashi removes `b` from s, it becomes `ac`. Then, Aoki cannot perform\nthe operation, since there is no character in s, excluding both ends.\n\n* * *"}, {"input": "abcab", "output": "First"}]
If Takahashi will win, print `First`. If Aoki will win, print `Second`. * * *
s417406200
Accepted
p03863
The input is given from Standard Input in the following format: s
s = input() def result(limit): if limit % 2 == 1: return "First" if limit % 2 == 0: return "Second" first = s[0] last = s[-1] if first != last: first_idx = [] last_idx = [] for x in range(s.count(first)): first_idx.append(s.index(first, x)) for y in range(s.count(last)): last_idx.append(s.index(last, y)) judge = 0 data = [] data.append(last_idx.pop()) while judge < 2: if judge == 0: while judge == 0: if len(first_idx) == 0: judge = 2 else: k = first_idx.pop() if k < data[-1]: judge = 1 data.append(k) elif judge == 1: while judge == 1: if len(last_idx) == 0: judge = 2 else: k = last_idx.pop() if k < data[-1]: judge = 0 data.append(k) print(result(len(s) - len(data))) elif first == last: first_idx = [] for x in range(s.count(first)): first_idx.append(s.index(first, x)) alpha = "abcdefghijklmnopqrstuvwxyz" counter = [0 for _ in range(len(alpha))] for i in range(1, len(first_idx)): string = s[first_idx[i - 1] + 1 : first_idx[i]] for j in range(len(alpha)): if alpha[j] in string: counter[j] += 1 k = max(counter) print(result(len(s) - 2 * k - 1))
Statement There is a string s of length 3 or greater. No two neighboring characters in s are equal. Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first: * Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s. The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.
[{"input": "aba", "output": "Second\n \n\nTakahashi, who goes first, cannot perform the operation, since removal of the\n`b`, which is the only character not at either ends of s, would result in s\nbecoming `aa`, with two `a`s neighboring.\n\n* * *"}, {"input": "abc", "output": "First\n \n\nWhen Takahashi removes `b` from s, it becomes `ac`. Then, Aoki cannot perform\nthe operation, since there is no character in s, excluding both ends.\n\n* * *"}, {"input": "abcab", "output": "First"}]
If Takahashi will win, print `First`. If Aoki will win, print `Second`. * * *
s551125315
Runtime Error
p03863
The input is given from Standard Input in the following format: s
#pragma GCC optimize ("O3") #pragma GCC target ("tune=native") #pragma GCC target ("avx") #include <bits/stdc++.h> // 汎用マクロ #define ALL_OF(x) (x).begin(), (x).end() #define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++) #define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++) #define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--) #define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; } template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; } #define INF 0x7FFFFFFF #define LINF 0x7FFFFFFFFFFFFFFFLL #define Yes(q) ((q) ? "Yes" : "No") #define YES(q) ((q) ? "YES" : "NO") #define Possible(q) ((q) ? "Possible" : "Impossible") #define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE") #define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl #define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; } template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; } // gcc拡張マクロ #define popcount __builtin_popcount #define popcountll __builtin_popcountll // エイリアス #define DANCE_ long #define ROBOT_ unsigned #define HUMAN_ signed #define CHOKUDAI_ const using ll = DANCE_ HUMAN_ DANCE_; using ull = DANCE_ ROBOT_ DANCE_; using cll = DANCE_ DANCE_ CHOKUDAI_; using ld = long double; using namespace std; // モジュール // 処理内容 int main() { string s; cin >> s; ll n = s.size(); cout << ((s.front() == s.back()) != !!(n % 2) ? "First" : "Second") << endl; }
Statement There is a string s of length 3 or greater. No two neighboring characters in s are equal. Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first: * Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s. The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.
[{"input": "aba", "output": "Second\n \n\nTakahashi, who goes first, cannot perform the operation, since removal of the\n`b`, which is the only character not at either ends of s, would result in s\nbecoming `aa`, with two `a`s neighboring.\n\n* * *"}, {"input": "abc", "output": "First\n \n\nWhen Takahashi removes `b` from s, it becomes `ac`. Then, Aoki cannot perform\nthe operation, since there is no character in s, excluding both ends.\n\n* * *"}, {"input": "abcab", "output": "First"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s309924753
Accepted
p02771
Input is given from Standard Input in the following format: A B C
ABC = list(map(str, input().split())) abc = set(ABC) print("Yes" if len(abc) == 2 else "No")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s051609212
Accepted
p02771
Input is given from Standard Input in the following format: A B C
print(len({*input()}) % 2 * "Yes" or "No")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s927058277
Accepted
p02771
Input is given from Standard Input in the following format: A B C
S = len(set(input().split())) print("Yes" if S == 2 else "No")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s121030385
Accepted
p02771
Input is given from Standard Input in the following format: A B C
print("Yes" if len(set(map(int, input().split()))) == 2 else "No")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s869111187
Accepted
p02771
Input is given from Standard Input in the following format: A B C
print("YNeos"[len(set(input()[::2])) & 1 :: 2])
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s137897786
Runtime Error
p02771
Input is given from Standard Input in the following format: A B C
a = 1 << 1000000000 b = 1 << a print(b)
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s125218597
Runtime Error
p02771
Input is given from Standard Input in the following format: A B C
num = list(map(int, input().split())) print("Yes" if len(num) == len(set(num) + 1) else "No")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s546530346
Runtime Error
p02771
Input is given from Standard Input in the following format: A B C
s = str(input()) n = len(s) dp = [[0] * 2 for _ in range(n + 1)] dp[0][1] = 1 for i in range(n): p = int(s[i]) dp[i + 1][0] = min(dp[i][1] + 10 - p, dp[i][0] + p) dp[i + 1][1] = min(dp[i][1] + 10 - p - 1, dp[i][0] + p + 1) print(dp[-1][0])
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s581337200
Runtime Error
p02771
Input is given from Standard Input in the following format: A B C
import collections from collections import OrderedDict # 入力 N = int(input()) S = [input() for i in range(N)] # 出現回数のカウント c = OrderedDict(collections.Counter(S)) ln = len(c.values()) # 多い順に並べ替えた辞書をつくる d = OrderedDict(sorted(c.items(), key=lambda x: x[1], reverse=True)) dval = list(d.values()) dkey = list(d.keys()) # 回数が多い単語を抜き出したリストの制作 word = list() word.append(dkey[0]) i = 1 if ln > 1: while dval[i - 1] == dval[i]: word.append(dkey[i]) i += 1 if i == ln: break # 辞書順に並べ替える dic = sorted(word) # 表示 for i in range(len(dic)): print(dic[i])
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s013099261
Runtime Error
p02771
Input is given from Standard Input in the following format: A B C
def main(): import sys input = sys.stdin.readline import bisect N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] A_m = [abs(int(x)) for x in A if x < 0] A_m.sort() N_m = len(A_m) A_p = [int(x) for x in A if x > 0] A_p.sort() N_p = len(A_p) M = N_m * N_p P = (1 / 2) * (N_m) * (N_m - 1) + (1 / 2) * (N_p) * (N_p - 1) Z = (1 / 2) * N * (N - 1) - (M + P) if M < K <= M + Z: print(0) sys.exit() def cnt_M(x): cnt = 0 for i in A_m: cnt += bisect.bisect_right(A_p, x // i) return cnt >= (M - K + 1) if K <= M: left = -1 - 10**18 right = 1 + 10**18 while right - left > 1: mid = (left + right) // 2 if cnt_M(mid): right = mid else: left = mid print(-right) sys.exit() K -= M + Z def cnt_P(x): cnt = 0 ng = 0 for i in A_m: cnt += bisect.bisect_right(A_m, x // i) if i**2 <= x: ng += 1 for j in A_p: cnt += bisect.bisect_right(A_p, x // j) if j**2 <= x: ng += 1 return (cnt - ng) // 2 >= K left = -1 - 10**18 right = 1 + 10**18 while right - left > 1: mid = (left + right) // 2 if cnt_P(mid): right = mid else: left = mid print(right) main()
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s244421756
Runtime Error
p02771
Input is given from Standard Input in the following format: A B C
import numpy as np N, K = map(int, input().split()) a = np.array(input().split(), np.int64) a = np.sort(a) zero = a[a == 0] pos = a[a > 0] neg = a[a < 0] def f(x): count = 0 c = x // pos count += np.searchsorted(a, c, side="right").sum() count += N * len(zero) if x >= 0 else 0 c = -(-x // neg) count += (N - np.searchsorted(a, c, side="left")).sum() count -= a[a * a <= x].size count //= 2 return count right = 10**18 left = -(10**18) while right - left > 1: mid = (right + left) // 2 if f(mid) < K: left = mid else: right = mid print(int(right))
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s759481043
Runtime Error
p02771
Input is given from Standard Input in the following format: A B C
N, K = map(int, input().split()) A_s = list(map(int, input().split())) minus = [-x for x in A_s if x < 0] plus = [x for x in A_s if x >= 0] minus.sort() plus.sort() def cnt(x): ans = 0 if x < 0: r = 0 x = -x for num in minus[::-1]: while r < len(plus) and plus[r] * num < x: r += 1 ans += len(plus) - r return ans r = 0 for num in minus[::-1]: if num * num <= x: ans -= 1 while r < len(minus) and minus[r] * num <= x: r += 1 ans += r r = 0 for num in plus[::-1]: if num * num <= x: ans -= 1 while r < len(plus) and plus[r] * num <= x: r += 1 ans += r ans //= 2 ans += len(minus) * len(plus) return ans top = 2 * (10**18) + 2 bottom = 0 while top - bottom > 1: mid = (top + bottom) // 2 if cnt(mid - 10**18 - 1) < K: bottom = mid else: top = mid print(int(top - 10**18 - 1))
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s857395790
Accepted
p02771
Input is given from Standard Input in the following format: A B C
i = list(map(int, input().split())) i.sort() j = i[0] k = i[1] l = i[2] a = "No" if j == k: if k != l: a = "Yes" else: a = "No" elif k == l: a = "Yes" print(a)
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s539386668
Accepted
p02771
Input is given from Standard Input in the following format: A B C
s = set([int(i) for i in input().split()]) print(["No", "Yes"][len(s) == 2])
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s907675600
Accepted
p02771
Input is given from Standard Input in the following format: A B C
L = set(map(int, input().split())) print("Yes" if len(L) == 2 else "No")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s214948139
Runtime Error
p02771
Input is given from Standard Input in the following format: A B C
print("YES" if set(map(int, input().split())).len() == 2 else "NO")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s700774597
Wrong Answer
p02771
Input is given from Standard Input in the following format: A B C
a = input().split() count = 0 if a[0] == a[1]: count = count + 1 if a[1] == a[2]: count = count + 1 if a[0] == a[2]: count = count + 1 print("Yes" if count == 2 else "No")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s714641917
Accepted
p02771
Input is given from Standard Input in the following format: A B C
v = set(map(lambda x: int(x), input().split(" "))) print("Yes" if len(v) == 2 else "No")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s955373656
Accepted
p02771
Input is given from Standard Input in the following format: A B C
nums = [i for i in input().split()] nums = list(set(nums)) print("Yes" if len(nums) == 2 else "No")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s554578837
Accepted
p02771
Input is given from Standard Input in the following format: A B C
print(("No", "Yes")[len(set(list(map(int, input().split())))) == 2])
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s725935491
Accepted
p02771
Input is given from Standard Input in the following format: A B C
print("Yes" if 2 == len(set(input().split())) else "No")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s110606430
Accepted
p02771
Input is given from Standard Input in the following format: A B C
print("Yes") if len(set(input().split())) == 2 else print("No")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s736429882
Wrong Answer
p02771
Input is given from Standard Input in the following format: A B C
s = list(map(int, input().split())) print("yes" if len(s) == 2 else "no")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s226973347
Wrong Answer
p02771
Input is given from Standard Input in the following format: A B C
print("Yes")
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
If the given triple is poor, print `Yes`; otherwise, print `No`. * * *
s838496371
Runtime Error
p02771
Input is given from Standard Input in the following format: A B C
n, k = (int(x) for x in input().split()) list1 = list(map(int, input().split())) list1.sort() list2 = [n - 1] * n list3 = [] for j in range(n): list3.append(list1[j] * list1[list2[j]]) for j in range(k): max1 = list3.index(max(list3)) list2[max1] -= 1 list3[max1] = list1[max1] * list2[max1] print(list3[max1])
Statement A triple of numbers is said to be _poor_ when two of those numbers are equal but the other number is different from those two numbers. You will be given three integers A, B, and C. If this triple is poor, print `Yes`; otherwise, print `No`.
[{"input": "5 7 5", "output": "Yes\n \n\nA and C are equal, but B is different from those two numbers, so this triple\nis poor.\n\n* * *"}, {"input": "4 4 4", "output": "No\n \n\nA, B, and C are all equal, so this triple is not poor.\n\n* * *"}, {"input": "4 9 6", "output": "No\n \n\n* * *"}, {"input": "3 3 4", "output": "Yes"}]
Print the maximum total values of the items in a line.
s585606228
Wrong Answer
p02321
N W v1 w1 v2 w2 : vN wN The first line consists of the integers N and W. In the following N lines, the value and weight of the i-th item are given.
import bisect n, knapsack = map(int, input().split()) items = [tuple(map(int, input().split())) for _ in range(n)] def make_half_knapsack(hn, items): hk = {} for i in range(1, 1 << hn): vs, ws = 0, 0 j, k = i, 0 while j: if j & 1: v, w = items[k] vs += v ws += w j >>= 1 k += 1 if ws not in hk or hk[ws] < vs: hk[ws] = vs return hk hn = n // 2 hk = make_half_knapsack(hn, items[:hn]) hk1w = sorted(hk.keys()) hk1v = [hk[w] for w in hk1w] hk = make_half_knapsack(n - hn, items[hn:]) ans = 0 for w2, v2 in hk.items(): i = bisect.bisect(hk1w, knapsack - w2) ans = max(ans, max(hk1v[:i], default=0) + v2) print(ans)
Huge Knapsack Problem You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that is capacity of the knapsack. Find the maximum total value of items in the knapsack.
[{"input": "4 5\n 4 2\n 5 2\n 2 1\n 8 3", "output": "13"}, {"input": "2 20\n 5 9\n 4 10", "output": "9"}]
Print the maximum total values of the items in a line.
s512097458
Wrong Answer
p02321
N W v1 w1 v2 w2 : vN wN The first line consists of the integers N and W. In the following N lines, the value and weight of the i-th item are given.
n, W = map(int, input().split()) value = [] weight = [] for _ in range(n): v, w = map(int, input().split()) value.append(v) weight.append(w) def search(i, k, acc, vlst, wlst, vwlst): if i == k: vsum = sum(vlst[i] for i in range(k) if acc[i]) wsum = sum(wlst[i] for i in range(k) if acc[i]) vwlst.append([wsum, vsum]) else: search(i + 1, k, acc + [0], vlst, wlst, vwlst) search(i + 1, k, acc + [1], vlst, wlst, vwlst) vw1 = [] vw2 = [] search(0, n // 2, [], value[: n // 2], weight[: n // 2], vw1) search(0, n - n // 2, [], value[n // 2 :], weight[n // 2 :], vw2) vw1.sort() vw2.sort() maxv = 0 for i in range(n // 2): w, v = vw1[i] if maxv < v: maxv = v else: vw1[i][1] = maxv maxv = 0 for i in range(n - n // 2): w, v = vw2[i] if maxv < v: maxv = v else: vw2[i][1] = maxv ind1 = 0 ind2 = 2 ** (n - n // 2) - 1 ans = 0 while ind1 < 2 ** (n // 2) and ind2 >= 0: w1, v1 = vw1[ind1] w2, v2 = vw2[ind2] while ind2 > 0 and w1 + w2 > W: ind2 -= 1 w2, v2 = vw2[ind2] if w1 + w2 <= W: ans = max(ans, v1 + v2) ind1 += 1 print(ans)
Huge Knapsack Problem You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that is capacity of the knapsack. Find the maximum total value of items in the knapsack.
[{"input": "4 5\n 4 2\n 5 2\n 2 1\n 8 3", "output": "13"}, {"input": "2 20\n 5 9\n 4 10", "output": "9"}]
Print the number of ways in which the squares can be painted in the end, modulo 998244353. * * *
s053778957
Accepted
p02634
Input is given from Standard Input in the following format: A B C D
a, b, c, d = map(int, input().split()) dp = [[1 for i in range(d + 1)] for j in range(c + 1)] mod = 998244353 for y in range(c + 1): if y < a: continue for x in range(d + 1): if x < b: continue if y == a and x == b: continue py = 0 px = 0 m = 0 if y > a: py = dp[y - 1][x] * x if x > b: px = dp[y][x - 1] * y if y > a and x > b: m = dp[y - 1][x - 1] * (y - 1) * (x - 1) dp[y][x] = py + px - m dp[y][x] %= mod print(dp[c][d])
Statement We have a grid with A horizontal rows and B vertical columns, with the squares painted white. On this grid, we will repeatedly apply the following operation: * Assume that the grid currently has a horizontal rows and b vertical columns. Choose "vertical" or "horizontal". * If we choose "vertical", insert one row at the top of the grid, resulting in an (a+1) \times b grid. * If we choose "horizontal", insert one column at the right end of the grid, resulting in an a \times (b+1) grid. * Then, paint one of the added squares black, and the other squares white. Assume the grid eventually has C horizontal rows and D vertical columns. Find the number of ways in which the squares can be painted in the end, modulo 998244353.
[{"input": "1 1 2 2", "output": "3\n \n\nAny two of the three squares other than the bottom-left square can be painted\nblack.\n\n* * *"}, {"input": "2 1 3 4", "output": "65\n \n\n* * *"}, {"input": "31 41 59 265", "output": "387222020"}]
Print the number of ways in which the squares can be painted in the end, modulo 998244353. * * *
s166591680
Accepted
p02634
Input is given from Standard Input in the following format: A B C D
# AGC046-B Extension """ https://maspypy.com/atcoder-%E5%8F%82%E5%8A%A0%E6%84%9F%E6%83%B3-2020-06-20agc046 「操作列の結果、完成図としてありうるものを数えよ」 という問題は、複数の操作後の完成図が同じ結果を取りうることを考慮し、 ・完成図としてあり得るパターンの同値な言い換えを探す ・操作に制約を加えても同じ完成図を作成できることが一意になる のどちらかを目指して、考察していく。 以下、問題の「縦を選んだ場合のマスの変化」は上ではなく下として考える。 ケース2の 2 1 3 4 について考える。 これは縦に1回と横に3回の追加を行うが、 実は縦の制御について、最も左端に存在する黒タイルについて場合分けをして良い。 w??? w??? b??? の盤面について考えた時、これは初手に縦の操作を選ぶことで達成できるが、 そうでないような操作で上図と同じような盤面になったとして、実は左下の位置が 黒になるような場合、?の位置もまた同じように決定されるので、そのような 操作は考慮しなくて良いことが分かる。 そのような操作とは、つまり、"縦方向の拡張を最速で行わなかった"ような操作である。 考察すべき2つめの条件、操作に制約を加えても同じ完成図を作成できることが一意になる を達成することができた。 この時の?の組み合わせは、横拡張3回のうち、すべての拡張で3つを選べるので、 3*3通り である。 次は、一番下の行で、初めて黒が出る位置を1つずつずらして考えていく。 w??? w??? wb?? この場合、右に1回横拡張を挟んで、すぐさま縦拡張,そのあと横拡張を2回行うので、 2*3*3 w??? w??? wwb? 2*2*3 w??? w??? wwwb 2*2*2 よって合計65通りとなる。 この操作をdpによって拡張する。 具体的には、 dp[i][j]:横幅iの時点で残りの縦幅がjの時、縦幅を利用する際の通し数 """ import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n % 2 == 0 else 0 A, B, C, D = map(int, readline().split()) mod = 998244353 dp0 = [[0] * (D + 1) for _ in range(C + 1)] dp1 = [[0] * (D + 1) for _ in range(C + 1)] dp0[A][B] = 1 for x in range(A, C + 1): for y in range(B, D + 1): if x == A and y == B: continue dp0[x][y] = (dp0[x][y - 1] * x + dp1[x][y - 1] * 1) % mod dp1[x][y] = (dp0[x - 1][y] * y + dp1[x - 1][y] * y) % mod ans = (dp0[C][D] + dp1[C][D]) % mod print(ans)
Statement We have a grid with A horizontal rows and B vertical columns, with the squares painted white. On this grid, we will repeatedly apply the following operation: * Assume that the grid currently has a horizontal rows and b vertical columns. Choose "vertical" or "horizontal". * If we choose "vertical", insert one row at the top of the grid, resulting in an (a+1) \times b grid. * If we choose "horizontal", insert one column at the right end of the grid, resulting in an a \times (b+1) grid. * Then, paint one of the added squares black, and the other squares white. Assume the grid eventually has C horizontal rows and D vertical columns. Find the number of ways in which the squares can be painted in the end, modulo 998244353.
[{"input": "1 1 2 2", "output": "3\n \n\nAny two of the three squares other than the bottom-left square can be painted\nblack.\n\n* * *"}, {"input": "2 1 3 4", "output": "65\n \n\n* * *"}, {"input": "31 41 59 265", "output": "387222020"}]
Print the number of ways in which the squares can be painted in the end, modulo 998244353. * * *
s198884514
Wrong Answer
p02634
Input is given from Standard Input in the following format: A B C D
print(1)
Statement We have a grid with A horizontal rows and B vertical columns, with the squares painted white. On this grid, we will repeatedly apply the following operation: * Assume that the grid currently has a horizontal rows and b vertical columns. Choose "vertical" or "horizontal". * If we choose "vertical", insert one row at the top of the grid, resulting in an (a+1) \times b grid. * If we choose "horizontal", insert one column at the right end of the grid, resulting in an a \times (b+1) grid. * Then, paint one of the added squares black, and the other squares white. Assume the grid eventually has C horizontal rows and D vertical columns. Find the number of ways in which the squares can be painted in the end, modulo 998244353.
[{"input": "1 1 2 2", "output": "3\n \n\nAny two of the three squares other than the bottom-left square can be painted\nblack.\n\n* * *"}, {"input": "2 1 3 4", "output": "65\n \n\n* * *"}, {"input": "31 41 59 265", "output": "387222020"}]
Print the number of ways in which the squares can be painted in the end, modulo 998244353. * * *
s591390809
Wrong Answer
p02634
Input is given from Standard Input in the following format: A B C D
def LI():return [int(i) for i in input().split()] mo=998244353 a,b,c,d=LI() h=c-a+1 w=d-b+1 dp=[[0]*(d+1) for i in range(c+1)] dp[a][b]=1 for i in range(a,c): dp[i+1][b]=dp[i][b]*b for i in range(b,d): dp[a][i+1]=dp[a][i]*a for i in range(a,c): for j in range(b,d): #dp[i+1][j+1]=dp[i][j+1]*(j+1)+dp[i+1][j]*(i+1)-dp[i][j] dp[i+1][j+1]=dp[i][j+1]+dp[i+1][j] +dp[i][j+1]*(j) +dp[i+1][j]*(i) -dp[i][j]*i*j dp[i+1][j+1]%=mo ans=dp[c][d] print(ans)
Statement We have a grid with A horizontal rows and B vertical columns, with the squares painted white. On this grid, we will repeatedly apply the following operation: * Assume that the grid currently has a horizontal rows and b vertical columns. Choose "vertical" or "horizontal". * If we choose "vertical", insert one row at the top of the grid, resulting in an (a+1) \times b grid. * If we choose "horizontal", insert one column at the right end of the grid, resulting in an a \times (b+1) grid. * Then, paint one of the added squares black, and the other squares white. Assume the grid eventually has C horizontal rows and D vertical columns. Find the number of ways in which the squares can be painted in the end, modulo 998244353.
[{"input": "1 1 2 2", "output": "3\n \n\nAny two of the three squares other than the bottom-left square can be painted\nblack.\n\n* * *"}, {"input": "2 1 3 4", "output": "65\n \n\n* * *"}, {"input": "31 41 59 265", "output": "387222020"}]
For each process, prints its name and the time the process finished in order.
s734663780
Accepted
p02264
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
class Process: def __init__(self, process_name, process_time): self.name = process_name self.time = process_time self.remaing_time = process_time self.complete_flg = False def get_name(self): return self.name def get_time(self): return self.time def get_remaining_time(self): return self.remaing_time def exec_process(self, quantum): if self.remaing_time <= quantum: self.complete_flg = True use_time = self.remaing_time self.remaing_time = 0 return use_time else: self.remaing_time -= quantum return quantum def get_complete_flg(self): return self.complete_flg if __name__ == "__main__": n, q = [int(x) for x in input().split()] all_time = 0 procesies = [] for _ in range(n): name, time = input().split() temp_process = Process(name, int(time)) procesies.append(temp_process) while len(procesies) != 0: target_process = procesies.pop(0) all_time += target_process.exec_process(q) if target_process.get_complete_flg(): print(target_process.get_name() + " " + str(all_time)) else: procesies.append(target_process)
Input _n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
[{"input": "5 100\n p1 150\n p2 80\n p3 200\n p4 350\n p5 20", "output": "p2 180\n p5 400\n p1 450\n p3 550\n p4 800"}]
For each process, prints its name and the time the process finished in order.
s647271526
Accepted
p02264
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
# ----------------for input------------------------ numberAndQuontum = input().split() number = int(numberAndQuontum[0]) Quontum = int(numberAndQuontum[1]) allProcessList = [] index = 0 while index < number: nameAndTime = input().split() nameTimeList = [] nameTimeList.append(nameAndTime[0]) nameTimeList.append(int(nameAndTime[1])) allProcessList.append(nameTimeList) index += 1 # ----------------for input------------------------ def schedule(Quontum, allProcessList): time = 0 listForReturn = [] while True: index = 0 if allProcessList == []: break length = len(allProcessList) while index < length: if allProcessList[index][1] <= Quontum: time += allProcessList[index][1] listForReturn.append(allProcessList[index][0] + " " + str(time)) allProcessList[index] = [] index += 1 else: time += Quontum listForAppend = [ allProcessList[index][0], allProcessList[index][1] - Quontum, ] allProcessList.append(listForAppend) allProcessList[index] = [] index += 1 while [] in allProcessList: allProcessList.remove([]) for printPair in listForReturn: print(printPair) # -------------------for main--------------------------- schedule(Quontum, allProcessList)
Input _n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
[{"input": "5 100\n p1 150\n p2 80\n p3 200\n p4 350\n p5 20", "output": "p2 180\n p5 400\n p1 450\n p3 550\n p4 800"}]
For each process, prints its name and the time the process finished in order.
s829709098
Accepted
p02264
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
a = input().split() a = [int(i) for i in a] b = [] cnt = 0 time = 0 for i in range(a[0]): b.append(input().split()) cnt += int(b[i][1]) i = 0 while cnt != time: if int(b[i][1]) <= a[1]: time += int(b[i][1]) print(b[i][0], time) b.pop(0) else: b[i][1] = int(b[i][1]) - a[1] time += a[1] b.append(b.pop(i))
Input _n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
[{"input": "5 100\n p1 150\n p2 80\n p3 200\n p4 350\n p5 20", "output": "p2 180\n p5 400\n p1 450\n p3 550\n p4 800"}]
For each process, prints its name and the time the process finished in order.
s959045953
Wrong Answer
p02264
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
n, q = map(int, input().split()) p = [] for _ in [0] * n: s, k = input().split() p += [[s, int(k)]] b = list(range(n)) t = 0 while sum(b): for i in b: a = p[i] if a[1] > q: a[1] -= q t += q else: b.remove(i) t += a[1] print(a[0], t)
Input _n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
[{"input": "5 100\n p1 150\n p2 80\n p3 200\n p4 350\n p5 20", "output": "p2 180\n p5 400\n p1 450\n p3 550\n p4 800"}]
For each process, prints its name and the time the process finished in order.
s671237031
Wrong Answer
p02264
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
# operand.py using polish way of expressing data = input() operators = "+-*/" command = data.split() operand = [] # used to store operand"s" for com in command: if ( com in operators ): # do some calculation on the last one and the second last one XD second = operand.pop() first = operand.pop() if com == "+": out = first + second elif com == "-": out = first - second elif com == "*": out = first * second elif com == "/": out = first / second operand.append(out) out = int() # clear out else: # store operand into to buffer operand.append(int(com)) print(operand[0])
Input _n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
[{"input": "5 100\n p1 150\n p2 80\n p3 200\n p4 350\n p5 20", "output": "p2 180\n p5 400\n p1 450\n p3 550\n p4 800"}]
For each process, prints its name and the time the process finished in order.
s685394660
Accepted
p02264
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
# encoding: utf-8 import sys from collections import deque class Solution: @staticmethod def message_queue(): # write your code here # tasks = deque(map(lambda x: x.split(), sys.stdin.readlines())) task_num, task_time = map(int, input().split()) _input = sys.stdin.readlines() task_deque = deque( map(lambda x: dict(name=x.split()[0], time=int(x.split()[-1])), _input) ) total_time = 0 while task_deque: item = task_deque.popleft() if item["time"] <= task_time: total_time += item["time"] print(item["name"], total_time) else: item["time"] -= task_time total_time += task_time task_deque.append(item) if __name__ == "__main__": solution = Solution() solution.message_queue()
Input _n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
[{"input": "5 100\n p1 150\n p2 80\n p3 200\n p4 350\n p5 20", "output": "p2 180\n p5 400\n p1 450\n p3 550\n p4 800"}]
For each process, prints its name and the time the process finished in order.
s887869061
Accepted
p02264
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
args = list(map(int, input().split())) processes = [] for i in range(args[0]): processes.append(input().split()) processes[i][1] = int(processes[i][1]) timer, p = 0, 0 while args[0]: p %= args[0] if processes[p][1] > args[1]: processes[p][1] -= args[1] timer += args[1] else: timer += processes[p][1] print(processes[p][0], timer) args[0] -= 1 del processes[p] p -= 1 p += 1
Input _n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
[{"input": "5 100\n p1 150\n p2 80\n p3 200\n p4 350\n p5 20", "output": "p2 180\n p5 400\n p1 450\n p3 550\n p4 800"}]
For each process, prints its name and the time the process finished in order.
s539529935
Accepted
p02264
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
class ArrayDeque: def __init__(self): self.a_size = 1 self.a = [None] self.n = 0 self.head = 0 self.tail = 0 def __bool__(self): return self.n != 0 def _resize(self): new_a = [None] * ((self.n + 1) << 1) for i in range(self.n): new_a[i] = self.a[(self.head + i) & (self.a_size - 1)] self.a = new_a self.a_size = (self.n + 1) << 1 self.head = 0 self.tail = self.n def append(self, val): if self.n == self.a_size - 1: self._resize() self.a[self.tail] = val self.tail = (self.tail + 1) & (self.a_size - 1) self.n += 1 def appendleft(self, val): if self.n == self.a_size - 1: self._resize() self.head = (self.head - 1) & (self.a_size - 1) self.a[self.head] = val self.n += 1 def popleft(self): if self.n == 0: raise IndexError() val = self.a[self.head] self.head = (self.head + 1) & (self.a_size - 1) self.n -= 1 if self.a_size >= 4 * self.n + 2: self._resize() return val def pop(self): if self.n == 0: raise IndexError() self.tail = (self.tail - 1) & (self.a_size - 1) val = self.a[self.tail] self.n -= 1 if self.a_size >= 4 * self.n + 2: self._resize() return val n, q = map(int, input().split()) info = [input().split() for i in range(n)] que = ArrayDeque() for name, time in info: que.append((name, int(time))) ans_time = 0 ans = [] while que: name, time = que.popleft() if time > q: que.append((name, time - q)) ans_time += q else: ans_time += time ans.append((name, ans_time)) for name, time in ans: print(name, time)
Input _n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
[{"input": "5 100\n p1 150\n p2 80\n p3 200\n p4 350\n p5 20", "output": "p2 180\n p5 400\n p1 450\n p3 550\n p4 800"}]
For each process, prints its name and the time the process finished in order.
s625475240
Accepted
p02264
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
import sys data = [] for line in sys.stdin: data.append(line.split()) quontum = int(data[0][1]) targetData = data[1:] answerData = [] totalQuontum = 0 while targetData: target = targetData.pop(0) target[1] = int(target[1]) - quontum if target[1] <= 0: totalQuontum += quontum + int(target[1]) target[1] = totalQuontum answerData.append(target) else: targetData.append(target) totalQuontum += quontum for answer in answerData: print(str(answer[0]) + " " + str(answer[1]))
Input _n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
[{"input": "5 100\n p1 150\n p2 80\n p3 200\n p4 350\n p5 20", "output": "p2 180\n p5 400\n p1 450\n p3 550\n p4 800"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s015638201
Accepted
p03025
Input is given from Standard Input in the following format: N A B C
class Combinatorics: def __init__(self, N, mod): """ Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N) over the finite field Z/(mod)Z. Input: N (int): maximum n mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated. """ self.mod = mod self.fact = {i: None for i in range(N + 1)} # n! self.inverse = { i: None for i in range(1, N + 1) } # inverse of n in the field Z/(MOD)Z self.fact_inverse = { i: None for i in range(N + 1) } # inverse of n! in the field Z/(MOD)Z # preprocess self.fact[0] = self.fact[1] = 1 self.fact_inverse[0] = self.fact_inverse[1] = 1 self.inverse[1] = 1 for i in range(2, N + 1): self.fact[i] = i * self.fact[i - 1] % self.mod q, r = divmod(self.mod, i) self.inverse[i] = (-(q % self.mod) * self.inverse[r]) % self.mod self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i - 1] % self.mod def perm(self, n, r): """ Calculate nPr = n! / (n-r)! % mod """ if n < r or n < 0 or r < 0: return 0 else: return (self.fact[n] * self.fact_inverse[n - r]) % self.mod def binom(self, n, r): """ Calculate nCr = n! /(r! (n-r)!) % mod """ if n < r or n < 0 or r < 0: return 0 else: return ( self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n - r] % self.mod) % self.mod ) def hom(self, n, r): """ Calculate nHr = {n+r-1}Cr % mod. Assign r objects to one of n classes. Arrangement of r circles and n-1 partitions: o o o | o o | | | o | | | o o | | o """ if n == 0 and r > 0: return 0 if n >= 0 and r == 0: return 1 return self.binom(n + r - 1, r) def extended_euclid(a, b): x1, y1, m = 1, 0, a x2, y2, n = 0, 1, b while m % n != 0: q, r = divmod(m, n) x1, y1, m, x2, y2, n = x2, y2, n, x1 - q * x2, y1 - q * y2, r return (x2, y2, n) def modular_inverse(a, mod): x, _, g = extended_euclid(a, mod) if g != 1: return None # Modular inverse of a does not exist else: return x % mod N, A, B, C = map(int, input().split()) MOD = 10**9 + 7 com = Combinatorics(2 * N, MOD) pa = A * modular_inverse(A + B, MOD) pb = B * modular_inverse(A + B, MOD) n_first_AB = (100 * modular_inverse(100 - C, MOD)) % MOD ans = 0 for m in range(N, 2 * N): # E[X] = E_M[ E[X | M] ] Exp_X_given_M = (m * n_first_AB) % MOD prob_m = ( com.binom(m - 1, N - 1) * ( (pow(pa, N, MOD) * pow(pb, m - N, MOD)) % MOD + (pow(pa, m - N, MOD) * pow(pb, N, MOD)) % MOD ) % MOD ) ans = (ans + Exp_X_given_M * prob_m) % MOD print(ans)
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s094719223
Accepted
p03025
Input is given from Standard Input in the following format: N A B C
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 def init_fact_inv(MAX: int, MOD: int) -> list: """ 階乗たくさん使う時用のテーブル準備 MAX:階乗に使う数値の最大以上まで作る """ # 階乗テーブル factorial = [1] * MAX factorial[0] = factorial[1] = 1 for i in range(2, MAX): factorial[i] = factorial[i - 1] * i % MOD # 階乗の逆元テーブル inverse = [1] * MAX # powに第三引数入れると冪乗のmod付計算を高速にやってくれる inverse[MAX - 1] = pow(factorial[MAX - 1], MOD - 2, MOD) for i in range(MAX - 2, 0, -1): # 最後から戻っていくこのループならMAX回powするより処理が速い inverse[i] = inverse[i + 1] * (i + 1) % MOD return factorial, inverse # 組み合わせの数(必要な階乗と逆元のテーブルを事前に作っておく) def nCr(n, r, factorial, inverse): if n < r: return 0 # 10C7 = 10C3 r = min(r, n - r) # 分子の計算 numerator = factorial[n] # 分母の計算 denominator = inverse[r] * inverse[n - r] % MOD return numerator * denominator % MOD def fermat(x, y, MOD): return x * pow(y, MOD - 2, MOD) % MOD N, A, B, C = MAP() fact, inv = init_fact_inv(N * 2 + 1, MOD) # MODの割り算 AAB = fermat(A, A + B, MOD) BAB = fermat(B, A + B, MOD) ans = 0 for m in range(N, N * 2): # (引き分けを考えずに)m回で終わる確率 x = ( pow(AAB, N, MOD) * pow(BAB, m - N, MOD) + pow(BAB, N, MOD) * pow(AAB, m - N, MOD) ) * nCr(m - 1, N - 1, fact, inv) # 引き分け以外の試合がm回行われるまでの試合数の期待値 y = fermat(m * 100, A + B, MOD) ans = (ans + x * y) % MOD print(ans)
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s313775291
Runtime Error
p03025
Input is given from Standard Input in the following format: N A B C
from fractions import Fraction as F I = lambda: map(int, input().split()) mod = 1000000007 N, A, B, C = I() a = F(A, 100) b = F(B, 100) c = F(C, 100) f = N * (a**N) / ((1 - c) ** N) / (1 - c) * ((b**N) / (c**N) - 1) / ((b / c) - 1) g = N * (b**N) / ((1 - c) ** N) / (1 - c) * ((a**N) / (c**N) - 1) / ((a / c) - 1) print(f + g)
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s441144988
Wrong Answer
p03025
Input is given from Standard Input in the following format: N A B C
n, a, b, c = (int(i) for i in input().split()) a = a / 100 b = b / 100 def bitsu(n): r = 1 for i in range(n): r = r * (i + 1) return r def comb(n, k): return bitsu(n) / (bitsu(k) * bitsu(n - k)) def pos(a, b, k): # k回目で終わる確率 return (a**n) * (b ** (k - n)) * comb(n, k) + (a ** (k - n)) * (b**n) * comb(n, k) r = 0 for i in (n, 2 * n - 1): r = r + i * pos(a, b, i) print(r)
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s598479710
Accepted
p03025
Input is given from Standard Input in the following format: N A B C
#!/usr/bin/env python3 import sys MOD = 1000000007 # type: int def gcd(a, b): if b == 0: return a return gcd(b, a % b) def reduce(y, x): tmp = gcd(x, y) return (y // tmp, x // tmp) def get_z(y, x): # y/x (mod 1000000007) inv_x = pow(x, MOD - 2, MOD) return y * inv_x % MOD def make_combs(n, k): fact = [1] * (n + 1) for i in range(2, n + 1): fact[i] = (fact[i - 1] * i) % MOD ret = [0] * (n + 1) for i in range(k, n + 1): a = fact[i] b = (fact[k] * fact[i - k]) % MOD ret[i] = get_z(a, b) return ret def make_pow(y, x, n): ret = [0] * (n + 1) yy = [1] * (n + 1) xx = [1] * (n + 1) for i in range(1, n + 1): yy[i] = (yy[i - 1] * y) % MOD xx[i] = (xx[i - 1] * x) % MOD for i in range(n + 1): # print(yy[i], xx[i]) ret[i] = get_z(yy[i], xx[i]) return ret def solve(n: int, A: int, B: int, C: int): y = 0 x = 0 AB = 100 - C combs = make_combs(2 * n, n - 1) a, a_ab = reduce(A, AB) b, b_ab = reduce(B, AB) a_pow = make_pow(a, a_ab, n) b_pow = make_pow(b, b_ab, n) # print(combs) # print(a_pow) # print(b_pow) for i in range(n, n * 2): com = combs[i - 1] # tmp = (A / ab) ** (n) + (B / ab) ** (i - n) # tmp += (B / ab) ** (n) + (A / ab) ** (i - n) tmp = a_pow[n] * b_pow[i - n] tmp += b_pow[n] * a_pow[i - n] # print(a_pow[n], b_pow[i - n], b_pow[n], a_pow[i - n]) x = (x + tmp * com) % MOD y = (y + tmp * com * i) % MOD x = (x * (100 - C)) % MOD y = (y * 100) % MOD ret = get_z(y, x) print(ret) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int C = int(next(tokens)) # type: int solve(N, A, B, C) if __name__ == "__main__": main()
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s804738771
Accepted
p03025
Input is given from Standard Input in the following format: N A B C
class Combination: """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う""" def __init__(self, n, MOD): self.fact = [1] for i in range(1, n + 1): self.fact.append(self.fact[-1] * i % MOD) self.inv_fact = [0] * (n + 1) self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD) for i in reversed(range(n)): self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD self.MOD = MOD def factorial(self, k): """k!を求める O(1)""" return self.fact[k] def inverse_factorial(self, k): """k!の逆元を求める O(1)""" return self.inv_fact[k] def permutation(self, k, r): """kPrを求める O(1)""" if k < r: return 0 return (self.fact[k] * self.inv_fact[k - r]) % self.MOD def combination(self, k, r): """kCrを求める O(1)""" if k < r: return 0 return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD n, a, b, c = map(int, input().split()) MOD = 10**9 + 7 comb = Combination(10**6, MOD) pa = a * pow(a + b, MOD - 2, MOD) % MOD pb = b * pow(a + b, MOD - 2, MOD) % MOD ec = 100 * pow(100 - c, MOD - 2, MOD) % MOD ans1 = 0 tmp = pow(pa, n, MOD) for i in range(n): ans1 += tmp * pow(pb, i, MOD) * comb.combination(n - 1 + i, i) * (n + i) * ec ans1 %= MOD ans2 = 0 tmp = pow(pb, n, MOD) for i in range(n): ans2 += tmp * pow(pa, i, MOD) * comb.combination(n - 1 + i, i) * (n + i) * ec ans2 %= MOD print((ans1 + ans2) % MOD)
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s696747862
Accepted
p03025
Input is given from Standard Input in the following format: N A B C
# 入力 N, A, B, C = map(int, input().split()) MOD = 10**9 + 7 class ModInt: def __init__(self, x): self.x = x % MOD def __str__(self): return str(self.x) __repr__ = __str__ def __add__(self, other): return ( ModInt(self.x + other.x) if isinstance(other, ModInt) else ModInt(self.x + other) ) def __sub__(self, other): return ( ModInt(self.x - other.x) if isinstance(other, ModInt) else ModInt(self.x - other) ) def __mul__(self, other): return ( ModInt(self.x * other.x) if isinstance(other, ModInt) else ModInt(self.x * other) ) def __truediv__(self, other): return ( ModInt(self.x * pow(other.x, MOD - 2, MOD)) if isinstance(other, ModInt) else ModInt(self.x * pow(other, MOD - 2, MOD)) ) def __pow__(self, other): return ( ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else ModInt(pow(self.x, other, MOD)) ) def __radd__(self, other): return ModInt(other + self.x) def __rsub__(self, other): return ModInt(other - self.x) def __rmul__(self, other): return ModInt(other * self.x) def __rtruediv__(self, other): return ModInt(other * pow(self.x, MOD - 2, MOD)) def __rpow__(self, other): return ModInt(pow(other, self.x, MOD)) # f[n] = n! % (10**9 + 7) f = [0 for _ in range(2 * N)] f[0] = ModInt(1) for i in range(1, 2 * N): f[i] = i * f[i - 1] # 引き分けなしの分母 D = ModInt(100 - C) # 1回のゲームにつき、高橋君が勝つ確率 p = A / D # 1回のゲームにつき、青木君が勝つ確率 q = B / D # 高橋君がN回、青木君がi回勝つケースの重み付き期待値の和、および # 高橋君がi回、青木君がN回勝つケースの重み付き期待値の和 # を求めそれらの和を解とする ans = (100 / D) * sum( (N + i) * (f[N + i - 1] / (f[i] * f[N - 1])) * (p**N * q**i + p**i * q**N) for i in range(N) ) # 出力 print(ans)
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s495585216
Accepted
p03025
Input is given from Standard Input in the following format: N A B C
import sys def main(): input = sys.stdin.readline MOD = 10**9 + 7 N, A, B, C = map(int, input().split()) factrial = [1] * (2 * N) # pa[i] / pab[i] is the probobility that A wins i times when there is no draw. pa = [1] * (2 * N) pb = [1] * (2 * N) pab = [1] * (2 * N) for k in range(1, 2 * N): factrial[k] = (factrial[k - 1] * k) % MOD pa[k] = (pa[k - 1] * A) % MOD pb[k] = (pb[k - 1] * B) % MOD pab[k] = (pab[k - 1] * (A + B)) % MOD fact_inv = [1] * (2 * N) fact_inv[2 * N - 1] = pow(factrial[2 * N - 1], MOD - 2, MOD) pab_inv = [1] * (2 * N) pab_inv[2 * N - 1] = pow(pab[2 * N - 1], MOD - 2, MOD) for k in range(2 * N - 2, -1, -1): fact_inv[k] = (fact_inv[k + 1] * (k + 1)) % MOD pab_inv[k] = (pab_inv[k + 1] * (A + B)) % MOD def comb_mod(n, r, MOD=10**9 + 7): return (factrial[n] * fact_inv[r] * fact_inv[n - r]) % MOD ans = 0 for m in range(N): E = ( comb_mod(N + m - 1, N - 1) * (pa[N] * pb[m] + pa[m] * pb[N]) * pab_inv[N + m] * (N + m) * 100 * pow(100 - C, MOD - 2, MOD) ) % MOD ans = (ans + E) % MOD return ans if __name__ == "__main__": print(main())
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s673328772
Accepted
p03025
Input is given from Standard Input in the following format: N A B C
import sys sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 def POW(x, y): return pow(x, y, MOD) def INV(x, m=MOD): return pow(x, m - 2, m) def DIV(x, y, m=MOD): return (x * INV(y, m)) % m def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return input() # factorials _nfact = 2 * (10**5) + 10 facts = [0] * _nfact facts[0] = 1 for i in range(1, _nfact): facts[i] = (facts[i - 1] * i) % MOD ifacts = [0] * _nfact ifacts[-1] = INV(facts[-1]) for i in range(_nfact - 1, 0, -1): ifacts[i - 1] = (ifacts[i] * i) % MOD def binomial(m, n): return facts[m] * ifacts[n] * ifacts[m - n] def main(): N, A, B, C = LI() D = DIV(100, 100 - C) ans = 0 ap, bp, abp = [1], [1], [POW(A + B, N)] for _ in range(0, N + 1): ap.append(ap[-1] * A % MOD) bp.append(bp[-1] * B % MOD) abp.append(abp[-1] * (A + B) % MOD) for m in range(N, 2 * N): x = ( binomial(m - 1, N - 1) * DIV(ap[N] * bp[m - N] + ap[m - N] * bp[N], abp[m - N]) % MOD ) y = (m * D) % MOD ans = (ans + (x * y) % MOD) % MOD return ans print(main())
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s054890798
Wrong Answer
p03025
Input is given from Standard Input in the following format: N A B C
N, A, B, C = [int(i) for i in input().split()] P = 0.01 * max(A, B) X = N * (1 - P) / P print(int((N + X) * (1 - 0.01 * C)))
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s217063263
Runtime Error
p03025
Input is given from Standard Input in the following format: N A B C
N, A, B, C = map(int, input().split()) X = (100 * N) / A * B
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s767301278
Accepted
p03025
Input is given from Standard Input in the following format: N A B C
#!/usr/bin/env python import sys MOD = 10**9 + 7 def Add(n, m): return (n + m) % MOD def Sub(n, m): return (n - m) % MOD def Mul(n, m): return (n * m) % MOD def Pow(n, p): if p < 0: return Pow(n, (p % (MOD - 1))) elif p == 0: return 1 elif p == 1: return n elif p % 2 == 0: tmp = Pow(n, (p // 2)) % MOD return tmp**2 % MOD else: tmp = Pow(n, (p // 2)) % MOD return (n * tmp**2) % MOD # raise ValueError def Div(n, m): return (n * Pow(m, MOD - 2)) % MOD # #:::::::::::::::::::::::::::::::::::::::::::::::::: n, a, b, c = [int(x) for x in sys.stdin.readline().split()] # h = Div(1, 100) pa = Mul(a, h) pb = Mul(b, h) cc = Div(1, Mul(100 - c, h)) # power of n cn = Pow(cc, n + 1) t = Mul(cn, n) an = Mul(Pow(pa, n), t) bn = Mul(Pow(pb, n), t) # for A pam = bn pac = Mul(pa, cc) # for B pbm = an pbc = Mul(pb, cc) # permutation mbar = n perm = [1] * n for m in range(1, n): mbar -= 1 perm[m] = Mul(perm[m - 1], mbar) perm.reverse() nfact = perm[0] # ret = 0 ncm = 1 for m in range(n): if m > 0: ncm = Mul(ncm, n + m) pam = Mul(pam, pac) pbm = Mul(pbm, pbc) # ret = (ret + Mul(Mul(ncm, pbm + pam), perm[m])) % MOD # print(Div(ret, nfact))
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print the expected number of games that will be played, in the manner specified in the statement. * * *
s058907373
Runtime Error
p03025
Input is given from Standard Input in the following format: N A B C
import sys sys.setrecursionlimit(110000) def inpl(): return list(map(int, input().split())) class UnionFind: def __init__(self, N): # par = parent self.par = [i for i in range(N)] self.N = N self.hop = {i: -1 for i in range(N)} self.adj = [[] for i in range(N)] return def root(self, x): if self.par[x] == x: return x else: self.par[x] = self.root(self.par[x]) return self.par[x] def same(self, x, y): return self.root(x) == self.root(y) def union(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False self.par[x] = min(x, y) self.par[y] = min(x, y) return True def find_root(self): for i in range(self.N): if i == self.root(i): return i return def dfs(self, i): for nh in self.adj[i]: if self.hop[nh] != -1: continue else: self.hop[nh] = self.hop[i] + 1 self.dfs(nh) return N = int(input()) uf = UnionFind(N) AB = [[0, 0] for i in range(N - 1)] for i in range(N - 1): a, b = inpl() a -= 1 b -= 1 AB[i][0] = a AB[i][1] = b uf.adj[a].append(b) uf.adj[b].append(a) C = inpl() for a, b in AB: uf.union(a, b) root_num = uf.find_root() uf.hop[root_num] = 0 uf.dfs(root_num) dic2 = sorted(uf.hop.items(), key=lambda x: x[1], reverse=True) ans = [0 for i in range(N)] for i, k in enumerate(dic2): ans[k[0]] = i C.sort() print(sum(C[:-1])) for i in range(N): if i != 0: print(" ", end="") print(C[ans[i]], end="") print("")
Statement Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
[{"input": "1 25 25 50", "output": "2\n \n\nSince N=1, they will repeat the game until one of them wins. The expected\nnumber of games played is 2.\n\n* * *"}, {"input": "4 50 50 0", "output": "312500008\n \n\nC may be 0.\n\n* * *"}, {"input": "1 100 0 0", "output": "1\n \n\nB may also be 0.\n\n* * *"}, {"input": "100000 31 41 28", "output": "104136146"}]
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x. * * *
s182766325
Accepted
p03475
Input is given from Standard Input in the following format: N C_1 S_1 F_1 : C_{N-1} S_{N-1} F_{N-1}
def examA(): C1 = SI() C2 = SI() ans = "YES" if C1[0] != C2[2] or C1[1] != C2[1] or C1[2] != C2[0]: ans = "NO" print(ans) return def examB(): A, B, C, X, Y = LI() loop = max(X, Y) ans = inf for i in range(loop + 1): cost = i * 2 * C if X > i: cost += A * (X - i) if Y > i: cost += B * (Y - i) ans = min(ans, cost) print(ans) return def examC(): def gcd(x, y): if y == 0: return x while y != 0: x, y = y, x % y return x N, x = LI() X = LI() if N == 1: print(abs(X[0] - x)) return for i in range(N): X[i] = abs(X[i] - x) now = gcd(X[0], X[1]) for i in range(2, N): now = gcd(now, X[i]) ans = now print(ans) return def examD(): N = I() C = [LI() for _ in range(N - 1)] ans = [inf] * N for i in range(N): cur = 0 for j in range(i, N - 1): c, s, f = C[j] next = 0 if cur <= s: cur = s + c else: cur = (1 + (cur - 1) // f) * f + c ans[i] = cur for v in ans: print(v) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return from decimal import Decimal as dec import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(input()) def LI(): return list(map(int, sys.stdin.readline().split())) def DI(): return dec(input()) def LDI(): return list(map(dec, 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, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10 ** (-12) alphabet = [chr(ord("a") + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == "__main__": examD() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
Statement A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
[{"input": "3\n 6 5 1\n 1 10 1", "output": "12\n 11\n 0\n \n\nWe will travel from Station 1 as follows:\n\n * 5 seconds after the beginning: take the train to Station 2.\n * 11 seconds: arrive at Station 2.\n * 11 seconds: take the train to Station 3.\n * 12 seconds: arrive at Station 3.\n\nWe will travel from Station 2 as follows:\n\n * 10 seconds: take the train to Station 3.\n * 11 seconds: arrive at Station 3.\n\nNote that we should print 0 for Station 3.\n\n* * *"}, {"input": "4\n 12 24 6\n 52 16 4\n 99 2 2", "output": "187\n 167\n 101\n 0\n \n\n* * *"}, {"input": "4\n 12 13 1\n 44 17 17\n 66 4096 64", "output": "4162\n 4162\n 4162\n 0"}]
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x. * * *
s340795431
Accepted
p03475
Input is given from Standard Input in the following format: N C_1 S_1 F_1 : C_{N-1} S_{N-1} F_{N-1}
n = int(input()) y = [list(map(int, input().split())) for i in range(n - 1)] for s in range(n): x = 0 for k, g in enumerate(y[s:]): a, b, c = g[0], g[1], g[2] if k == 0: x = b + a elif x > b: if (x - b) % c == 0: x = x + a else: x = (x // c + 1) * c + a elif x < b: x = b + a print(x)
Statement A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
[{"input": "3\n 6 5 1\n 1 10 1", "output": "12\n 11\n 0\n \n\nWe will travel from Station 1 as follows:\n\n * 5 seconds after the beginning: take the train to Station 2.\n * 11 seconds: arrive at Station 2.\n * 11 seconds: take the train to Station 3.\n * 12 seconds: arrive at Station 3.\n\nWe will travel from Station 2 as follows:\n\n * 10 seconds: take the train to Station 3.\n * 11 seconds: arrive at Station 3.\n\nNote that we should print 0 for Station 3.\n\n* * *"}, {"input": "4\n 12 24 6\n 52 16 4\n 99 2 2", "output": "187\n 167\n 101\n 0\n \n\n* * *"}, {"input": "4\n 12 13 1\n 44 17 17\n 66 4096 64", "output": "4162\n 4162\n 4162\n 0"}]
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x. * * *
s891486700
Runtime Error
p03475
Input is given from Standard Input in the following format: N C_1 S_1 F_1 : C_{N-1} S_{N-1} F_{N-1}
N = int(input()) C = [] S = [] F = [] T = [0]*N for i in range(N-1): C[i], S[i], F[i] = map(int, input().split()) for j in len(T): T[j] = C[j] + S[j] for i in range(N-1): if T[j] > S[i+1]: T[j] = T[j] + C[i+1] else: T[j] = S[i+1] T[N-1] = 0 for i in len(T): print(T[i])
Statement A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
[{"input": "3\n 6 5 1\n 1 10 1", "output": "12\n 11\n 0\n \n\nWe will travel from Station 1 as follows:\n\n * 5 seconds after the beginning: take the train to Station 2.\n * 11 seconds: arrive at Station 2.\n * 11 seconds: take the train to Station 3.\n * 12 seconds: arrive at Station 3.\n\nWe will travel from Station 2 as follows:\n\n * 10 seconds: take the train to Station 3.\n * 11 seconds: arrive at Station 3.\n\nNote that we should print 0 for Station 3.\n\n* * *"}, {"input": "4\n 12 24 6\n 52 16 4\n 99 2 2", "output": "187\n 167\n 101\n 0\n \n\n* * *"}, {"input": "4\n 12 13 1\n 44 17 17\n 66 4096 64", "output": "4162\n 4162\n 4162\n 0"}]
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x. * * *
s455069905
Wrong Answer
p03475
Input is given from Standard Input in the following format: N C_1 S_1 F_1 : C_{N-1} S_{N-1} F_{N-1}
""" 5 3 2 2 4 1 1 2 2 2 1 """ n = int(input()) array = [[int(x) for x in input().split()], [int(x) for x in input().split()]] res = 0 for i in range(n): tmp = sum(array[0][: i + 1]) + sum(array[1][i:]) if tmp > res: res = tmp print(res)
Statement A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
[{"input": "3\n 6 5 1\n 1 10 1", "output": "12\n 11\n 0\n \n\nWe will travel from Station 1 as follows:\n\n * 5 seconds after the beginning: take the train to Station 2.\n * 11 seconds: arrive at Station 2.\n * 11 seconds: take the train to Station 3.\n * 12 seconds: arrive at Station 3.\n\nWe will travel from Station 2 as follows:\n\n * 10 seconds: take the train to Station 3.\n * 11 seconds: arrive at Station 3.\n\nNote that we should print 0 for Station 3.\n\n* * *"}, {"input": "4\n 12 24 6\n 52 16 4\n 99 2 2", "output": "187\n 167\n 101\n 0\n \n\n* * *"}, {"input": "4\n 12 13 1\n 44 17 17\n 66 4096 64", "output": "4162\n 4162\n 4162\n 0"}]
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x. * * *
s028749537
Wrong Answer
p03475
Input is given from Standard Input in the following format: N C_1 S_1 F_1 : C_{N-1} S_{N-1} F_{N-1}
N = int(input()) inputList = [] for count in range(1, N): C, S, F = map(int, input().split()) tempList = [C, S, F] inputList.append(tempList) outputList = [] # 最後の行 outputList.append(0) # 下から2番目 lastC = inputList[N - 2][0] lastS = inputList[N - 2][1] outputList.insert(0, lastC + lastS) for i in range(N - 3, -1, -1): C = inputList[i][0] S = inputList[i][1] F = inputList[i][2] notArrivalFlag = False for j in range(N - 2, i, -1): if C + S < inputList[j][1]: notArrivalFlag = True if notArrivalFlag: outputList.insert(0, outputList[0]) else: sumC = 0 for j in range(N - 2, i, -1): sumC += inputList[j][0] outputList.insert(0, C + S + sumC) for output in outputList: print(output)
Statement A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
[{"input": "3\n 6 5 1\n 1 10 1", "output": "12\n 11\n 0\n \n\nWe will travel from Station 1 as follows:\n\n * 5 seconds after the beginning: take the train to Station 2.\n * 11 seconds: arrive at Station 2.\n * 11 seconds: take the train to Station 3.\n * 12 seconds: arrive at Station 3.\n\nWe will travel from Station 2 as follows:\n\n * 10 seconds: take the train to Station 3.\n * 11 seconds: arrive at Station 3.\n\nNote that we should print 0 for Station 3.\n\n* * *"}, {"input": "4\n 12 24 6\n 52 16 4\n 99 2 2", "output": "187\n 167\n 101\n 0\n \n\n* * *"}, {"input": "4\n 12 13 1\n 44 17 17\n 66 4096 64", "output": "4162\n 4162\n 4162\n 0"}]
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x. * * *
s139211504
Runtime Error
p03475
Input is given from Standard Input in the following format: N C_1 S_1 F_1 : C_{N-1} S_{N-1} F_{N-1}
n = int(input()) data = [] for i in range(n-1): station_data = [int(x) for x in input().split()] data.append(station_data) time_list = [] for i in range(n-1): total_time = data[i][1] + data[i][0] for j in range(i+1, n-1): if total_time <= data[j][1]: total_time = data[j][1] + data[j][0] elif total_time % data[j][2] == 0: total_time += data[j][0] else: total_time += total_time % data[j][2] + data[j][0] time_list.append(total_time) time_list.append(0) answer = map(str, time_list) print("\n".join(answer)
Statement A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
[{"input": "3\n 6 5 1\n 1 10 1", "output": "12\n 11\n 0\n \n\nWe will travel from Station 1 as follows:\n\n * 5 seconds after the beginning: take the train to Station 2.\n * 11 seconds: arrive at Station 2.\n * 11 seconds: take the train to Station 3.\n * 12 seconds: arrive at Station 3.\n\nWe will travel from Station 2 as follows:\n\n * 10 seconds: take the train to Station 3.\n * 11 seconds: arrive at Station 3.\n\nNote that we should print 0 for Station 3.\n\n* * *"}, {"input": "4\n 12 24 6\n 52 16 4\n 99 2 2", "output": "187\n 167\n 101\n 0\n \n\n* * *"}, {"input": "4\n 12 13 1\n 44 17 17\n 66 4096 64", "output": "4162\n 4162\n 4162\n 0"}]
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x. * * *
s265850273
Wrong Answer
p03475
Input is given from Standard Input in the following format: N C_1 S_1 F_1 : C_{N-1} S_{N-1} F_{N-1}
N = int(input()) numbers = [] for a in range(N - 1): list = [] C, S, F = input().split() list.append(int(C)) list.append(int(S)) list.append(int(F)) numbers.append(list) if N == 1: print(0) elif N == 2: print(numbers[0][0] + numbers[0][1]) print(0) else: for a in range(N - 1): b = numbers[a][0] + numbers[a][1] while a < N - 2: if b >= numbers[a + 1][1]: c = b - numbers[a + 1][1] d = c / numbers[a + 1][2] e = numbers[a + 1][1] + numbers[a + 1][2] * d b = e + numbers[a + 1][0] else: b = numbers[a + 1][1] + numbers[a + 1][0] a += 1 print(round(b)) print(0)
Statement A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
[{"input": "3\n 6 5 1\n 1 10 1", "output": "12\n 11\n 0\n \n\nWe will travel from Station 1 as follows:\n\n * 5 seconds after the beginning: take the train to Station 2.\n * 11 seconds: arrive at Station 2.\n * 11 seconds: take the train to Station 3.\n * 12 seconds: arrive at Station 3.\n\nWe will travel from Station 2 as follows:\n\n * 10 seconds: take the train to Station 3.\n * 11 seconds: arrive at Station 3.\n\nNote that we should print 0 for Station 3.\n\n* * *"}, {"input": "4\n 12 24 6\n 52 16 4\n 99 2 2", "output": "187\n 167\n 101\n 0\n \n\n* * *"}, {"input": "4\n 12 13 1\n 44 17 17\n 66 4096 64", "output": "4162\n 4162\n 4162\n 0"}]
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x. * * *
s664358599
Accepted
p03475
Input is given from Standard Input in the following format: N C_1 S_1 F_1 : C_{N-1} S_{N-1} F_{N-1}
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N = I() data = ILL(N - 1) for i in range(N - 1): now = 0 for j in range(i, N - 1): c, s, f = data[j] next_departure = max(s, -(-now // f) * f) now = next_departure + c print(now) print(0)
Statement A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
[{"input": "3\n 6 5 1\n 1 10 1", "output": "12\n 11\n 0\n \n\nWe will travel from Station 1 as follows:\n\n * 5 seconds after the beginning: take the train to Station 2.\n * 11 seconds: arrive at Station 2.\n * 11 seconds: take the train to Station 3.\n * 12 seconds: arrive at Station 3.\n\nWe will travel from Station 2 as follows:\n\n * 10 seconds: take the train to Station 3.\n * 11 seconds: arrive at Station 3.\n\nNote that we should print 0 for Station 3.\n\n* * *"}, {"input": "4\n 12 24 6\n 52 16 4\n 99 2 2", "output": "187\n 167\n 101\n 0\n \n\n* * *"}, {"input": "4\n 12 13 1\n 44 17 17\n 66 4096 64", "output": "4162\n 4162\n 4162\n 0"}]
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x. * * *
s073998833
Wrong Answer
p03475
Input is given from Standard Input in the following format: N C_1 S_1 F_1 : C_{N-1} S_{N-1} F_{N-1}
import sys def 解(): iN = int(sys.stdin.readline()) aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()] def fCeil(a): return int(-1 * (int(-1 * a))) for i in range(iN - 1): Tjb = aData[i][0] + aData[i][1] for j in range(i + 1, iN - 1): Cj = aData[j][0] Sj = aData[j][1] Fj = aData[j][2] Tjb = max(fCeil(Tjb / Fj), Sj // Fj) * Fj + Cj print(Tjb) print(0) 解()
Statement A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
[{"input": "3\n 6 5 1\n 1 10 1", "output": "12\n 11\n 0\n \n\nWe will travel from Station 1 as follows:\n\n * 5 seconds after the beginning: take the train to Station 2.\n * 11 seconds: arrive at Station 2.\n * 11 seconds: take the train to Station 3.\n * 12 seconds: arrive at Station 3.\n\nWe will travel from Station 2 as follows:\n\n * 10 seconds: take the train to Station 3.\n * 11 seconds: arrive at Station 3.\n\nNote that we should print 0 for Station 3.\n\n* * *"}, {"input": "4\n 12 24 6\n 52 16 4\n 99 2 2", "output": "187\n 167\n 101\n 0\n \n\n* * *"}, {"input": "4\n 12 13 1\n 44 17 17\n 66 4096 64", "output": "4162\n 4162\n 4162\n 0"}]
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x. * * *
s696317573
Accepted
p03475
Input is given from Standard Input in the following format: N C_1 S_1 F_1 : C_{N-1} S_{N-1} F_{N-1}
# https://atcoder.jp/contests/abc084/tasks/abc084_c # 制約によりたかだか500行 O(N*N)でも間に合うのでは? # 入力が10**5とかになったときに100ms程度早い import sys read = sys.stdin.readline def read_a_int(): return int(read()) def read_col(H, n_cols): """ H is number of rows n_cols is number of cols A列、B列が与えられるようなとき """ ret = [[] for _ in range(n_cols)] for _ in range(H): tmp = list(map(int, read().split())) for col in range(n_cols): ret[col].append(tmp[col]) return ret N = read_a_int() C, S, F = read_col(N - 1, 3) def f(i): # 駅iからN-1までに向かう最短時間 now = S[i] # はじめは運転開始時刻 for j in range(i, N - 2): # 駅N-1の手前まで now += C[j] # 移動時間 # 駅の待ち時刻まで待機 f, s = F[j + 1], S[j + 1] # だけど割り切れるときは余分に+1されてしまうので-0.5してつじつま合わせ now_tmp = (int((now - 0.5) // f) + 1) * f now = max(now_tmp, s) now += C[N - 2] return now for i in range(N - 1): print(f(i)) print(0)
Statement A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
[{"input": "3\n 6 5 1\n 1 10 1", "output": "12\n 11\n 0\n \n\nWe will travel from Station 1 as follows:\n\n * 5 seconds after the beginning: take the train to Station 2.\n * 11 seconds: arrive at Station 2.\n * 11 seconds: take the train to Station 3.\n * 12 seconds: arrive at Station 3.\n\nWe will travel from Station 2 as follows:\n\n * 10 seconds: take the train to Station 3.\n * 11 seconds: arrive at Station 3.\n\nNote that we should print 0 for Station 3.\n\n* * *"}, {"input": "4\n 12 24 6\n 52 16 4\n 99 2 2", "output": "187\n 167\n 101\n 0\n \n\n* * *"}, {"input": "4\n 12 13 1\n 44 17 17\n 66 4096 64", "output": "4162\n 4162\n 4162\n 0"}]
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x. * * *
s041963253
Accepted
p03475
Input is given from Standard Input in the following format: N C_1 S_1 F_1 : C_{N-1} S_{N-1} F_{N-1}
import sys import math import copy import heapq from functools import cmp_to_key from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(input()) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = float("inf") MOD = 10**9 + 7 divide = lambda x: pow(x, MOD - 2, MOD) def nck(n, k, kaijyo): return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD def npk(n, k, kaijyo): if k == 0 or k == n: return n % MOD return (kaijyo[n] * divide(kaijyo[n - k])) % MOD def fact_and_inv(SIZE): inv = [0] * SIZE # inv[j] = j^{-1} mod MOD fac = [0] * SIZE # fac[j] = j! mod MOD finv = [0] * SIZE # finv[j] = (j!)^{-1} mod MOD inv[1] = 1 fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2, SIZE): inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD fac[i] = fac[i - 1] * i % MOD finv[i] = finv[i - 1] * inv[i] % MOD return fac, finv def renritsu(A, Y): # example 2x + y = 3, x + 3y = 4 # A = [[2,1], [1,3]]) # Y = [[3],[4]] または [3,4] A = np.matrix(A) Y = np.matrix(Y) Y = np.reshape(Y, (-1, 1)) X = np.linalg.solve(A, Y) # [1.0, 1.0] return X.flatten().tolist()[0] class TwoDimGrid: # 2次元座標 -> 1次元 def __init__(self, h, w, wall="#"): self.h = h self.w = w self.size = (h + 2) * (w + 2) self.wall = wall self.get_grid() # self.init_cost() def get_grid(self): grid = [self.wall * (self.w + 2)] for i in range(self.h): grid.append(self.wall + getS() + self.wall) grid.append(self.wall * (self.w + 2)) self.grid = grid def init_cost(self): self.cost = [INF] * self.size def pos(self, x, y): # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed return y * (self.w + 2) + x def getgrid(self, x, y): return self.grid[y][x] def get(self, x, y): return self.cost[self.pos(x, y)] def set(self, x, y, v): self.cost[self.pos(x, y)] = v return def show(self): for i in range(self.h + 2): print(self.cost[(self.w + 2) * i : (self.w + 2) * (i + 1)]) def showsome(self, tgt): for t in tgt: print(t) return def showsomejoin(self, tgt): for t in tgt: print("".join(t)) return def search(self): grid = self.grid move = [(0, 1), (0, -1), (1, 0), (-1, 0)] move_eight = [ (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1), ] # for i in range(1, self.h+1): # for j in range(1, self.w+1): # cx, cy = j, i # for dx, dy in move_eight: # nx, ny = dx + cx, dy + cy def soinsu(n): ret = defaultdict(int) for i in range(2, int(math.sqrt(n) + 2)): if n % i == 0: while True: if n % i == 0: ret[i] += 1 n //= i else: break if not ret: return {n: 1} return ret def solve(): n = getN() den = [] ans = [0 for i in range(n)] for i in range(n - 1): den.append(getList()) den.append([0, 0, 0]) # for i in range(1,n): # tgt = n - i - 1 # tou = den[tgt][1] + den[tgt][0] # if tou <= den[tgt+1][1]: # ans[tgt] = ans[tgt+1] # for i in range(n - 1): cur = 0 for j in range(i, n - 1): if cur <= den[j][1]: cur = den[j][1] cur = int(math.ceil(cur / den[j][2]) * den[j][2]) cur += den[j][0] ans[i] = cur print(*ans, sep="\n") def main(): n = getN() for _ in range(n): solve() return if __name__ == "__main__": # main() solve()
Statement A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
[{"input": "3\n 6 5 1\n 1 10 1", "output": "12\n 11\n 0\n \n\nWe will travel from Station 1 as follows:\n\n * 5 seconds after the beginning: take the train to Station 2.\n * 11 seconds: arrive at Station 2.\n * 11 seconds: take the train to Station 3.\n * 12 seconds: arrive at Station 3.\n\nWe will travel from Station 2 as follows:\n\n * 10 seconds: take the train to Station 3.\n * 11 seconds: arrive at Station 3.\n\nNote that we should print 0 for Station 3.\n\n* * *"}, {"input": "4\n 12 24 6\n 52 16 4\n 99 2 2", "output": "187\n 167\n 101\n 0\n \n\n* * *"}, {"input": "4\n 12 13 1\n 44 17 17\n 66 4096 64", "output": "4162\n 4162\n 4162\n 0"}]
Print the shortest possible distance one needs to cover in order to get from intersection (x_1, y_1) to intersection (x_2, y_2), in meters. Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-11}. * * *
s141093019
Runtime Error
p03619
Input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 N X_1 Y_1 X_2 Y_2 : X_N Y_N
from math import pi input1 = list(map(int,input("").split(" "))) N = int(input("")) src = {"x":input1[0],"y":input1[1]} dist = {"x":input1[2],"y":input1[3]} spring = [] for i in range(N): temp = list(map(int,input("").split(" "))) if temp[0] in range(min(src['x'],dist['x']),max(src['x'],dist['x'])+1): if temp[1] in range(min(src['y'],dist['y']),max(src['y'],dist['y'])+1): spring.append({'x':temp[0], 'y':temp[1]}) # print(spring) path = (abs(src['x']-dist['x']) + abs(src['y']-dist['y'])) * 100 if len(spring) > 0: r = 10 if src['x'] == dist['x'] or src['y'] == dist['y'] : #半円 path += r*pi - 2*r else: #1/4円 if (src['x']-dist['x'])*(src['y']-dist['y']) > 0: spring.sort(key=lambda k: k['x']) else: spring.sort(key=lambda k: k['x'], reverse=True) L[0] = spring[0]['y'] length = 1 for i in range(1,N): if L[lenth] < spring[i]['y'] L.append(spring[i]['y']) length++ else: for j in range(0,length): if spring[i]['y'] >= L[j]: temp = i break L[temp] = spring[i]['y'] path += (r*pi/2 - 2*r) * length print(path)
Statement In the city of Nevermore, there are 10^8 streets and 10^8 avenues, both numbered from 0 to 10^8-1. All streets run straight from west to east, and all avenues run straight from south to north. The distance between neighboring streets and between neighboring avenues is exactly 100 meters. Every street intersects every avenue. Every intersection can be described by pair (x, y), where x is avenue ID and y is street ID. There are N fountains in the city, situated at intersections (X_i, Y_i). Unlike normal intersections, there's a circle with radius 10 meters centered at the intersection, and there are no road parts inside this circle. The picture below shows an example of how a part of the city with roads and fountains may look like. ![1f931bf0c98ec6f07e612b0282cdb094.png](https://img.atcoder.jp/agc019/1f931bf0c98ec6f07e612b0282cdb094.png) City governors don't like encountering more than one fountain while moving along the same road. Therefore, every street contains at most one fountain on it, as well as every avenue. Citizens can move along streets, avenues and fountain perimeters. What is the shortest distance one needs to cover in order to get from intersection (x_1, y_1) to intersection (x_2, y_2)?
[{"input": "1 1 6 5\n 3\n 3 2\n 5 3\n 2 4", "output": "891.415926535897938\n \n\nOne possible shortest path is shown on the picture below. The path starts at\nthe blue point, finishes at the purple point and follows along the red line.\n\n![c49e52b9b79003f61b8a6efa5dad8ba3.png](https://img.atcoder.jp/agc019/c49e52b9b79003f61b8a6efa5dad8ba3.png)\n\n* * *"}, {"input": "3 5 6 4\n 3\n 3 2\n 5 3\n 2 4", "output": "400.000000000000000\n \n\n![f9090ab734c89424c413f3b583376990.png](https://img.atcoder.jp/agc019/f9090ab734c89424c413f3b583376990.png)\n\n* * *"}, {"input": "4 2 2 2\n 3\n 3 2\n 5 3\n 2 4", "output": "211.415926535897938\n \n\n![4b76416161f27cad20333a9ac636e00f.png](https://img.atcoder.jp/agc019/4b76416161f27cad20333a9ac636e00f.png)"}]
Print the shortest possible distance one needs to cover in order to get from intersection (x_1, y_1) to intersection (x_2, y_2), in meters. Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-11}. * * *
s569261890
Wrong Answer
p03619
Input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 N X_1 Y_1 X_2 Y_2 : X_N Y_N
def abs(x): return x if x >= 0 else -x def lower_bound(X, y): L, R = 0, len(X) while L < R: M = (L + R) >> 1 if y > X[M]: L = M + 1 else: R = M return L ADJUST = 10**49 PI = 31415926535897932384626433832795028841971693993751 ax, ay, bx, by = list(map(int, input().split())) a = (ax, ay) b = (bx, by) n = int(input()) p = [list(map(int, input().split())) for i in range(n)] p.sort() if a[0] > b[0]: a, b = b, a ans = 100 * ADJUST * (abs(a[0] - b[0]) + abs(a[1] - b[1])) mx = min(a[0], b[0]) Mx = max(a[0], b[0]) my = min(a[1], b[1]) My = max(a[1], b[1]) if a[0] == b[0]: for point in p: if point[0] == a[0]: if my < point[1] and point[1] < My: ans += 10 * PI - 20 * ADJUST elif a[1] == b[1]: for point in p: if point[1] == a[1]: if mx < point[0] and point[0] < Mx: ans += 10 * PI - 20 * ADJUST else: lis = [] for point in p: if point[0] < mx or point[0] > Mx or point[1] < my or point[1] > My: continue y = abs(point[1] - a[1]) lb = lower_bound(lis, y) if lb == len(lis): lis.append(y) else: lis[lb] = y size = len(lis) ans += size * (5 * PI - 20 * ADJUST) print("%d.%049d" % (ans // ADJUST, ans % ADJUST))
Statement In the city of Nevermore, there are 10^8 streets and 10^8 avenues, both numbered from 0 to 10^8-1. All streets run straight from west to east, and all avenues run straight from south to north. The distance between neighboring streets and between neighboring avenues is exactly 100 meters. Every street intersects every avenue. Every intersection can be described by pair (x, y), where x is avenue ID and y is street ID. There are N fountains in the city, situated at intersections (X_i, Y_i). Unlike normal intersections, there's a circle with radius 10 meters centered at the intersection, and there are no road parts inside this circle. The picture below shows an example of how a part of the city with roads and fountains may look like. ![1f931bf0c98ec6f07e612b0282cdb094.png](https://img.atcoder.jp/agc019/1f931bf0c98ec6f07e612b0282cdb094.png) City governors don't like encountering more than one fountain while moving along the same road. Therefore, every street contains at most one fountain on it, as well as every avenue. Citizens can move along streets, avenues and fountain perimeters. What is the shortest distance one needs to cover in order to get from intersection (x_1, y_1) to intersection (x_2, y_2)?
[{"input": "1 1 6 5\n 3\n 3 2\n 5 3\n 2 4", "output": "891.415926535897938\n \n\nOne possible shortest path is shown on the picture below. The path starts at\nthe blue point, finishes at the purple point and follows along the red line.\n\n![c49e52b9b79003f61b8a6efa5dad8ba3.png](https://img.atcoder.jp/agc019/c49e52b9b79003f61b8a6efa5dad8ba3.png)\n\n* * *"}, {"input": "3 5 6 4\n 3\n 3 2\n 5 3\n 2 4", "output": "400.000000000000000\n \n\n![f9090ab734c89424c413f3b583376990.png](https://img.atcoder.jp/agc019/f9090ab734c89424c413f3b583376990.png)\n\n* * *"}, {"input": "4 2 2 2\n 3\n 3 2\n 5 3\n 2 4", "output": "211.415926535897938\n \n\n![4b76416161f27cad20333a9ac636e00f.png](https://img.atcoder.jp/agc019/4b76416161f27cad20333a9ac636e00f.png)"}]
Print the shortest possible distance one needs to cover in order to get from intersection (x_1, y_1) to intersection (x_2, y_2), in meters. Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-11}. * * *
s120182993
Wrong Answer
p03619
Input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 N X_1 Y_1 X_2 Y_2 : X_N Y_N
# -*- coding: utf-8 -*- from bisect import bisect_left, bisect_right, insort from collections import deque from math import pi def inpl(): return tuple(map(int, input().split())) sx, sy, gx, gy = inpl() N = int(input()) fountains = [] for _ in range(N): x, y = inpl() if sy > gy: y = 10**8 - 1 - y insort(fountains, [x, y]) if sx > gx: sx, sy, gx, gy = gx, gy, sx, sy if sy > gy: sy, gy = 10**8 - 1 - sy, 10**8 - 1 - gy fl = bisect_left(fountains, [sx, sy]) fr = bisect_right(fountains, [gx, gy]) fount = fountains[fl:fr] que = deque([[0, sx, sy]]) res = 0 while que: count_, tx, ty = que.pop() tfl = bisect_left(fountains, [tx, sy]) for fount in fountains[tfl:fr]: if (fount[1] > ty) & (fount[1] <= gy): que.appendleft([count_ + 1, fount[0], fount[1]]) if tx != fountains[fr - 1][0]: while tfl < fr - 1: if fountains[tfl + 1][1] > ty: que.appendleft([count_, fountains[tfl + 1][0], fountains[tfl + 1][1]]) break tfl += 1 res = max(res, count_) if (gx != sx) & (gy != sy): print(((gx - sx) + (gy - sy)) * 100 - (20 - 5 * pi) * res) else: fx, fy = fountains[fl] if (fx == sx) or (fy == sy): print((((gx - sx) + (gy - sy)) * 100 + (10 * pi - 20))) else: print((((gx - sx) + (gy - sy)) * 100))
Statement In the city of Nevermore, there are 10^8 streets and 10^8 avenues, both numbered from 0 to 10^8-1. All streets run straight from west to east, and all avenues run straight from south to north. The distance between neighboring streets and between neighboring avenues is exactly 100 meters. Every street intersects every avenue. Every intersection can be described by pair (x, y), where x is avenue ID and y is street ID. There are N fountains in the city, situated at intersections (X_i, Y_i). Unlike normal intersections, there's a circle with radius 10 meters centered at the intersection, and there are no road parts inside this circle. The picture below shows an example of how a part of the city with roads and fountains may look like. ![1f931bf0c98ec6f07e612b0282cdb094.png](https://img.atcoder.jp/agc019/1f931bf0c98ec6f07e612b0282cdb094.png) City governors don't like encountering more than one fountain while moving along the same road. Therefore, every street contains at most one fountain on it, as well as every avenue. Citizens can move along streets, avenues and fountain perimeters. What is the shortest distance one needs to cover in order to get from intersection (x_1, y_1) to intersection (x_2, y_2)?
[{"input": "1 1 6 5\n 3\n 3 2\n 5 3\n 2 4", "output": "891.415926535897938\n \n\nOne possible shortest path is shown on the picture below. The path starts at\nthe blue point, finishes at the purple point and follows along the red line.\n\n![c49e52b9b79003f61b8a6efa5dad8ba3.png](https://img.atcoder.jp/agc019/c49e52b9b79003f61b8a6efa5dad8ba3.png)\n\n* * *"}, {"input": "3 5 6 4\n 3\n 3 2\n 5 3\n 2 4", "output": "400.000000000000000\n \n\n![f9090ab734c89424c413f3b583376990.png](https://img.atcoder.jp/agc019/f9090ab734c89424c413f3b583376990.png)\n\n* * *"}, {"input": "4 2 2 2\n 3\n 3 2\n 5 3\n 2 4", "output": "211.415926535897938\n \n\n![4b76416161f27cad20333a9ac636e00f.png](https://img.atcoder.jp/agc019/4b76416161f27cad20333a9ac636e00f.png)"}]
For each insert operation, print the number of elements in $S$. For each find operation, print the number of specified elements in $S$. For each dump operation, print the corresponding elements in ascending order. Print an element in a line.
s978125658
Wrong Answer
p02458
The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $x$ or 1 $x$ or 2 $x$ or 3 $L$ $R$ where the first digits 0, 1, 2 and 3 represent insert, find, delete and dump operations respectively.
def binary(l, c): fst = 0 last = len(l) mid = int(last / 2) if fst == 0 and last == 0: l.insert(0, c) return while fst < last: mid = int((fst + last) / 2) if last == mid: break elif fst == mid: break elif l[mid] >= c: last = mid elif l[mid] <= c: fst = mid if l[mid] < c: mid += 1 l.insert(mid, c) q = int(input()) S = [] a = [] for i in range(q): a.append(list(map(int, input().split()))) for i in range(q): if a[i][0] == 0: binary(S, a[i][1]) print(len(S)) elif a[i][0] == 1: if a[i][1] in S: print(1) else: print(0) elif a[i][0] == 2: if a[i][1] in S: S.remove(a[i][1]) else: for b in range(len(S)): if S[b] >= a[i][1]: for c in range(b, len(S)): if S[c] <= a[i][2]: print(S[c]) else: break break
Multi-Set For a set $S$ of integers, perform a sequence of the following operations. Note that _multiple elements can have equivalent values in $S$_. * insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation. * find($x$): Report the number of $x$ in $S$. * delete($x$): Delete all $x$ from $S$. * dump($L$, $R$): Print elements $x$ in $S$ such that $L \leq x \leq R$.
[{"input": "10\n 0 1\n 0 1\n 0 2\n 0 3\n 2 2\n 1 1\n 1 2\n 1 3\n 0 4\n 3 1 4", "output": "1\n 2\n 3\n 4\n 2\n 0\n 1\n 4\n 1\n 1\n 3\n 4"}]
For each insert operation, print the number of elements in $S$. For each find operation, print the number of specified elements in $S$. For each dump operation, print the corresponding elements in ascending order. Print an element in a line.
s303395059
Wrong Answer
p02458
The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $x$ or 1 $x$ or 2 $x$ or 3 $L$ $R$ where the first digits 0, 1, 2 and 3 represent insert, find, delete and dump operations respectively.
# AOJ ITP2_7_D: Multi-Set # Python3 2018.6.24 bal4u from bisect import bisect_left, bisect_right, insort_left dict = {} keytbl = [] cnt = 0 q = int(input()) for i in range(q): a = list(input().split()) ki = int(a[1]) if a[0] == "0": if ki not in dict: dict[ki] = 1 insort_left(keytbl, ki) else: dict[ki] += 1 cnt += 1 print(cnt) elif a[0] == "1": print(dict[ki] if ki in dict else 0) elif a[0] == "2": if ki in dict: cnt -= dict[ki] dict[ki] = 0 else: L = bisect_left(keytbl, int(a[1])) R = bisect_right(keytbl, int(a[2]), L) for j in range(L, R): if dict[keytbl[j]] > 0: print(keytbl[j])
Multi-Set For a set $S$ of integers, perform a sequence of the following operations. Note that _multiple elements can have equivalent values in $S$_. * insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation. * find($x$): Report the number of $x$ in $S$. * delete($x$): Delete all $x$ from $S$. * dump($L$, $R$): Print elements $x$ in $S$ such that $L \leq x \leq R$.
[{"input": "10\n 0 1\n 0 1\n 0 2\n 0 3\n 2 2\n 1 1\n 1 2\n 1 3\n 0 4\n 3 1 4", "output": "1\n 2\n 3\n 4\n 2\n 0\n 1\n 4\n 1\n 1\n 3\n 4"}]
Output the number of possible height selections for each floor in a line.
s270626563
Accepted
p00388
The input is given in the following format. $H$ $A$ $B$ The input line provides the height of the condominium $H$ ($1 \leq H \leq 10^5$) and the upper and lower limits $A$ and $B$ of the height adjustable range for one floor ($1 \leq A \leq B \leq H$). All data are given as integers.
H, A, B = map(int, input().split()) cnt = 0 for i in range(A, B + 1): cnt += H % i == 0 print(cnt)
Design of a Mansion Our master carpenter is designing a condominium called Bange Hills Mansion. The condominium is constructed by stacking up floors of the same height. The height of each floor is designed so that the total height of the stacked floors coincides with the predetermined height of the condominium. The height of each floor can be adjusted freely with a certain range. The final outcome of the building depends on clever height allotment for each floor. So, he plans to calculate possible combinations of per-floor heights to check how many options he has. Given the height of the condominium and the adjustable range of each floor’s height, make a program to enumerate the number of choices for a floor.
[{"input": "100 2 4", "output": "2"}, {"input": "101 3 5", "output": "0"}]
Print the answer. * * *
s160128458
Wrong Answer
p03818
The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N}
l = int(input()) t = len(set(list(map(int, input().split())))) print(t - (1 - (l & 1)))
Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
[{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}]
Print the answer. * * *
s914725942
Wrong Answer
p03818
The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N}
n = int(input()) l = [int(i) for i in input().split()] if len(set(l)) == n: print(n) exit() print(1)
Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
[{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}]
Print the answer. * * *
s640927205
Accepted
p03818
The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N}
n = int(input()) ar = list(map(int, input().split())) count = {} for val in ar: if val not in count: count[val] = 1 else: count[val] += 1 ones = 0 twos = 0 for val in count: if count[val] % 2 == 0: twos += 1 else: ones += 1 if twos % 2 == 0: print(ones + twos) else: print(ones + twos - 1)
Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
[{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}]
Print the answer. * * *
s721461054
Runtime Error
p03818
The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N}
N = int(input()) A = list(map(int, input().split())) memo = {} for a in A: if a in memo: memo[a] += 1 else: memo[a] = 1 memo_sorted = sorted(memo.items(), key=lambda x: -x[1]) memo = [] for a, b in memo_sorted: memo.append([a, b]) for key, val in enumerate(memo): val_1, val_2 = val if val_2 <= 1: continue else: if val_2 % 2 == 1: memo[key][1] = 1 elif val_2 % 2 == 0: if key < N - 1: memo[key + 1][1] -= 1 memo[key][1] = 1 ans = 0 for a, b in memo: ans += b print(ans)
Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
[{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}]
Print the answer. * * *
s437821335
Accepted
p03818
The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N}
n, *a = map(int, open(0).read().split()) b = len(set(a)) print(b - (n - b) % 2)
Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
[{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}]
Print the answer. * * *
s731442800
Accepted
p03818
The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N}
_, a = open(0) b = len(set(a.split())) print(b + b % 2 - 1)
Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
[{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}]
Print the answer. * * *
s643067037
Runtime Error
p03818
The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N}
import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc toInt(c:char): int = return int(c) - int('0') proc solve():int= var n = scan() a = newseqwith(n,scan()) vcount = newseqwith(1E5.int+1,0) for av in a: vcount[av]+=1 var odds = 0 evens = 0 for vc in vcount: if vc > 0: if vc mod 2 == 0: evens+=1 else: odds += 1 result = odds + (evens div 2) * 2 echo solve()
Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
[{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}]
Print the answer. * * *
s810780543
Accepted
p03818
The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N}
n = int(input().strip()) a = [int(x) for x in input().strip().split()] num = len(list(set(a))) print(num - (n - num) % 2)
Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
[{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}]
Print the answer. * * *
s618739264
Accepted
p03818
The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N}
n = int(input()) a = [int(i) for i in input().split(" ")] s = len(set(a)) print(s - 1 + s % 2)
Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
[{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}]
Print the answer. * * *
s428898895
Accepted
p03818
The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N}
n = int(input()) k = len(set(list(map(int, input().split())))) print(k - 1 + k % 2)
Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
[{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}]
Print the answer. * * *
s587806054
Accepted
p03818
The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N}
import sys from sys import exit from collections import deque from copy import deepcopy from bisect import bisect_left, bisect_right, insort_left, insort_right from heapq import heapify, heappop, heappush from itertools import product, permutations, combinations, combinations_with_replacement from functools import reduce from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9 + 7 def lcm(x, y): return x * y // gcd(x, y) def lgcd(l): return reduce(gcd, l) def llcm(l): return reduce(lcm, l) def powmod(n, i, mod=MOD): return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod) def div2(x): return x.bit_length() def div10(x): return len(str(x)) - (x == 0) def intput(): return int(input()) def mint(): return map(int, input().split()) def lint(): return list(map(int, input().split())) def ilint(): return int(input()), list(map(int, input().split())) def judge(x, l=["Yes", "No"]): print(l[0] if x else l[1]) def lprint(l, sep="\n"): for x in l: print(x, end=sep) def ston(c, c0="a"): return ord(c) - ord(c0) def ntos(x, c0="a"): return chr(x + ord(c0)) class counter(dict): def __init__(self, *args): super().__init__(args) def add(self, x, d=1): self.setdefault(x, 0) self[x] += d def list(self): l = [] for k in self: l.extend([k] * self[k]) return l class comb: def __init__(self, n, mod=None): self.l = [1] self.n = n self.mod = mod def get(self, k): l, n, mod = self.l, self.n, self.mod k = n - k if k > n // 2 else k while len(l) <= k: i = len(l) l.append( l[i - 1] * (n + 1 - i) // i if mod == None else (l[i - 1] * (n + 1 - i) * powmod(i, -1, mod)) % mod ) return l[k] def pf(x, mode="counter"): C = counter() p = 2 while x > 1: k = 0 while x % p == 0: x //= p k += 1 if k > 0: C.add(p, k) p = p + 2 - (p == 2) if p * p < x else x if mode == "counter": return C S = set([1]) for k in C: T = deepcopy(S) for x in T: for i in range(1, C[k] + 1): S.add(x * (k**i)) if mode == "set": return S if mode == "list": return sorted(list(S)) ###################################################### N, A = ilint() C = counter() for a in A: C.add(a) ans = 0 for k in C: ans += max(0, C[k] - 1) print(N - 2 * ((ans - 1) // 2 + 1))
Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
[{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}]
Print the answer. * * *
s879073917
Accepted
p03818
The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N}
n, *a = map(int, open(0).read().split()) a.sort() cnt = -1 prev = a[0] b = [] for i in a: if prev == i: cnt += 1 else: b.append(cnt) cnt = 0 prev = i b.append(cnt) print(n - (sum(b) + 1) // 2 * 2)
Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
[{"input": "5\n 1 2 1 3 7", "output": "3\n \n\nOne optimal solution is to perform the operation once, taking out two cards\nwith 1 and one card with 2. One card with 1 and another with 2 will be eaten,\nand the remaining card with 1 will be returned to deck. Then, the values\nwritten on the remaining cards in the deck will be pairwise distinct: 1, 3 and\n7.\n\n* * *"}, {"input": "15\n 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1", "output": "7"}]
If Fennec wins, print `Fennec`; if Snuke wins, print `Snuke`. * * *
s658460215
Wrong Answer
p03662
Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1}
# 相手のパスを潰したい # こちら側に来てほしくない場合,最短経路を潰すしか無い # 最適を簡単に表せない A - B - C - D # EF-| |-GH... # のとき、A→EFとやっていると、Bを取られて死ぬ # でもこれをいちいち計算できない # 「相手のパスを潰す」、というのは、最短経路がより短いほうが勝つと考える? # でも相手にパスが潰されるかどうかはわからない # とりあえずやってみる n = int(input()) INF = 10**6 graph = [[float("inf")] * n for i in range(n)] for i in range(n - 1): a, b = map(int, input().split()) graph[a - 1][b - 1] = 1 graph[b - 1][a - 1] = 1 # ダイクストラで0, n-1からの最短距離を求める import heapq class Dijkstra(object): def dijkstra(self, adj, start, goal=None): """ ダイクストラアルゴリズムによる最短経路を求めるメソッド 入力 adj: adj[i][j]の値が頂点iから頂点jまでの距離(頂点iから頂点jに枝がない場合,値はfloat('inf'))となるような2次元リスト(正方行列) start: 始点のID goal: オプション引数.終点のID 出力 goalを引数に持つ場合,startからgoalまでの最短経路を格納したリストを返す 持たない場合は,startから各頂点までの最短距離を格納したリストを返す >>> d = Dijkstra() >>> d.dijkstra([[float('inf'), 2, 4, float('inf'), float('inf')], [2, float('inf'), 3, 5, float('inf')], [4, 3, float('inf'), 1, 4], [float('inf'), 5, 1, float('inf'), 3], [float('inf'), float('inf'), 4, 3, float('inf')]], 0) [0, 2, 4, 5, 8] # 例えば,始点0から頂点3までの最短距離は5となる >>> d.dijkstra([[float('inf'), 2, 4, float('inf'), float('inf')], [2, float('inf'), 3, 5, float('inf')], [4, 3, float('inf'), 1, 4], [float('inf'), 5, 1, float('inf'), 3], [float('inf'), float('inf'), 4, 3, float('inf')]], 0, goal=4) [0, 2, 4] # 頂点0から頂点4までの最短経路は0 -> 2 -> 4となる """ num = len(adj) # グラフのノード数 dist = [ float("inf") for i in range(num) ] # 始点から各頂点までの最短距離を格納する prev = [ float("inf") for i in range(num) ] # 最短経路における,その頂点の前の頂点のIDを格納する dist[start] = 0 q = ( [] ) # プライオリティキュー.各要素は,(startからある頂点vまでの仮の距離, 頂点vのID)からなるタプル heapq.heappush(q, (0, start)) # 始点をpush while len(q) != 0: prov_cost, src = heapq.heappop(q) # pop # プライオリティキューに格納されている最短距離が,現在計算できている最短距離より大きければ,distの更新をする必要はない if dist[src] < prov_cost: continue # 他の頂点の探索 for dest in range(num): cost = adj[src][dest] if cost != float("inf") and dist[dest] > dist[src] + cost: dist[dest] = dist[src] + cost # distの更新 heapq.heappush( q, (dist[dest], dest) ) # キューに新たな仮の距離の情報をpush prev[dest] = src # 前の頂点を記録 if goal is not None: return self.get_path(goal, prev) else: return dist def get_path(self, goal, prev): """ 始点startから終点goalまでの最短経路を求める """ path = [goal] # 最短経路 dest = goal # 終点から最短経路を逆順に辿る while prev[dest] != float("inf"): path.append(prev[dest]) dest = prev[dest] # 経路をreverseして出力 return list(reversed(path)) d = Dijkstra() # print(d.dijkstra(graph, start=0)) # print(d.dijkstra(graph, start=n-1)) print( "Fennec" if sum(d.dijkstra(graph, start=0)) <= sum(d.dijkstra(graph, start=n - 1)) else "Snuke" )
Statement Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.
[{"input": "7\n 3 6\n 1 2\n 3 1\n 7 4\n 5 7\n 1 4", "output": "Fennec\n \n\nFor example, if Fennec first paints Cell 2 black, she will win regardless of\nSnuke's moves.\n\n* * *"}, {"input": "4\n 1 4\n 4 2\n 2 3", "output": "Snuke"}]
If Fennec wins, print `Fennec`; if Snuke wins, print `Snuke`. * * *
s828085917
Accepted
p03662
Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1}
# ARC078D - Fennec VS. Snuke (ABC067D) from collections import deque def bfs(s: int, d: "List[int]") -> None: q = deque([s]) while q: v = q.popleft() for u in G[v]: if not d[u]: q.append(u) d[u] = d[v] + 1 def main(): global G, DB, DW N, *E = map(int, open(0).read().split()) G = [[] for _ in range(N + 1)] for i in range(0, (N - 1) * 2, 2): v, u = E[i : i + 2] G[v] += [u] G[u] += [v] DB, DW = [0] * (N + 1), [0] * (N + 1) bfs(1, DB), bfs(N, DW) b, w = 0, 0 for i, j in zip(DB[1:], DW[1:]): if i <= j: b += 1 else: w += 1 flg = b > w print("Fennec" if flg else "Snuke") if __name__ == "__main__": main()
Statement Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.
[{"input": "7\n 3 6\n 1 2\n 3 1\n 7 4\n 5 7\n 1 4", "output": "Fennec\n \n\nFor example, if Fennec first paints Cell 2 black, she will win regardless of\nSnuke's moves.\n\n* * *"}, {"input": "4\n 1 4\n 4 2\n 2 3", "output": "Snuke"}]
If Fennec wins, print `Fennec`; if Snuke wins, print `Snuke`. * * *
s047304112
Runtime Error
p03662
Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1}
from collections import deque def bfs(start): queue = deque([start]) visited = [] while queue: label = queue.pop() visited.append(label) for v in d[label]: if tekazu[v] == float("inf"): tekazu[v] = tekazu[label] + 1 queue.appendleft(v) return n = int(input()) d = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) d[a - 1].append(b - 1) d[b - 1].append(a - 1) tekazu = [float("inf") for _ in range(n)] tekazu[0] = 0 bfs(0) tekazu_Fennec = tekazu tekazu = [float("inf") for _ in range(n)] tekazu[-1] = 0 bfs(n - 1) tekazu_Snuke = tekazu Fennec = 0 Snuke = 0 for i in range(n): if tekazu_Fennec[i] <= tekazu_Snuke[i]: Fennec += 1 else: Snuke += 1 if Fennec > Snuke: print("Fennec") else: print("Snuke")
Statement Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.
[{"input": "7\n 3 6\n 1 2\n 3 1\n 7 4\n 5 7\n 1 4", "output": "Fennec\n \n\nFor example, if Fennec first paints Cell 2 black, she will win regardless of\nSnuke's moves.\n\n* * *"}, {"input": "4\n 1 4\n 4 2\n 2 3", "output": "Snuke"}]
If Fennec wins, print `Fennec`; if Snuke wins, print `Snuke`. * * *
s687132937
Wrong Answer
p03662
Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1}
###template### import sys def input(): return sys.stdin.readline().rstrip() def mi(): return map(int, input().split()) ###template### N = int(input()) # a1~k~N-1, b1~k~N-1はab[0~k-1~N-2][0], ab[0~k-1~N-2][1]でアクセス ab = [list(mi()) for _ in range(N - 1)] from collections import deque
Statement Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.
[{"input": "7\n 3 6\n 1 2\n 3 1\n 7 4\n 5 7\n 1 4", "output": "Fennec\n \n\nFor example, if Fennec first paints Cell 2 black, she will win regardless of\nSnuke's moves.\n\n* * *"}, {"input": "4\n 1 4\n 4 2\n 2 3", "output": "Snuke"}]
If Fennec wins, print `Fennec`; if Snuke wins, print `Snuke`. * * *
s393382813
Runtime Error
p03662
Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1}
#相手のパスを潰したい # こちら側に来てほしくない場合,最短経路を潰すしか無い # 最適を簡単に表せない A - B - C - D # EF-| |-GH... # のとき、A→EFとやっていると、Bを取られて死ぬ # でもこれをいちいち計算できない # 「相手のパスを潰す」、というのは、最短経路がより短いほうが勝つと考える? # でも相手にパスが潰されるかどうかはわからない # とりあえずやってみる n = int(input()) INF = 10**6 graph = [[float("inf")]*n for i in range(n)] for i in range(n - 1): a, b = map(int, input().split()) graph[a - 1][b -1] = 1 graph[b - 1][a - 1] = 1 #ダイクストラで0, n-1からの最短距離を求める import heapq class Dijkstra(object): def dijkstra(self, adj, start, goal=None): ''' ダイクストラアルゴリズムによる最短経路を求めるメソッド 入力 adj: adj[i][j]の値が頂点iから頂点jまでの距離(頂点iから頂点jに枝がない場合,値はfloat('inf'))となるような2次元リスト(正方行列) start: 始点のID goal: オプション引数.終点のID 出力 goalを引数に持つ場合,startからgoalまでの最短経路を格納したリストを返す 持たない場合は,startから各頂点までの最短距離を格納したリストを返す >>> d = Dijkstra() >>> d.dijkstra([[float('inf'), 2, 4, float('inf'), float('inf')], [2, float('inf'), 3, 5, float('inf')], [4, 3, float('inf'), 1, 4], [float('inf'), 5, 1, float('inf'), 3], [float('inf'), float('inf'), 4, 3, float('inf')]], 0) [0, 2, 4, 5, 8] # 例えば,始点0から頂点3までの最短距離は5となる >>> d.dijkstra([[float('inf'), 2, 4, float('inf'), float('inf')], [2, float('inf'), 3, 5, float('inf')], [4, 3, float('inf'), 1, 4], [float('inf'), 5, 1, float('inf'), 3], [float('inf'), float('inf'), 4, 3, float('inf')]], 0, goal=4) [0, 2, 4] # 頂点0から頂点4までの最短経路は0 -> 2 -> 4となる ''' num = len(adj) # グラフのノード数 dist = [float('inf') for i in range(num)] # 始点から各頂点までの最短距離を格納する prev = [float('inf') for i in range(num)] # 最短経路における,その頂点の前の頂点のIDを格納する dist[start] = 0 q = [] # プライオリティキュー.各要素は,(startからある頂点vまでの仮の距離, 頂点vのID)からなるタプル heapq.heappush(q, (0, start)) # 始点をpush while len(q) != 0: prov_cost, src = heapq.heappop(q) # pop # プライオリティキューに格納されている最短距離が,現在計算できている最短距離より大きければ,distの更新をする必要はない if dist[src] < prov_cost: continue # 他の頂点の探索 for dest in range(num): cost = adj[src][dest] if cost != float('inf') and dist[dest] > dist[src] + cost: dist[dest] = dist[src] + cost # distの更新 heapq.heappush(q, (dist[dest], dest)) # キューに新たな仮の距離の情報をpush prev[dest] = src # 前の頂点を記録 if goal is not None: return self.get_path(goal, prev) else: return dist def get_path(self, goal, prev): ''' 始点startから終点goalまでの最短経路を求める ''' path = [goal] # 最短経路 dest = goal # 終点から最短経路を逆順に辿る while prev[dest] != float('inf'): path.append(prev[dest]) dest = prev[dest] # 経路をreverseして出力 return list(reversed(path)) d = Dijkstra() #print(d.dijkstra(graph, start=0)) #print(d.dijkstra(graph, start=n-1)) cnt = 0 for i, j in zip(d.dijkstra(graph, start=0,), d.dijkstra(graph, start=n-1)): if i <= j: cnt += 1 print("Fennec" if cnt > n//2 else "Snuke")
Statement Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.
[{"input": "7\n 3 6\n 1 2\n 3 1\n 7 4\n 5 7\n 1 4", "output": "Fennec\n \n\nFor example, if Fennec first paints Cell 2 black, she will win regardless of\nSnuke's moves.\n\n* * *"}, {"input": "4\n 1 4\n 4 2\n 2 3", "output": "Snuke"}]
Print the minimum number of inspectors that we need to deploy to achieve the objective. * * *
s625382656
Accepted
p02970
Input is given from Standard Input in the following format: N D
a, b = list(map(int, input().split())) print(int((a - 1) / (2 * b + 1)) + 1)
Statement There are N apple trees in a row. People say that one of them will bear golden apples. We want to deploy some number of inspectors so that each of these trees will be inspected. Each inspector will be deployed under one of the trees. For convenience, we will assign numbers from 1 through N to the trees. An inspector deployed under the i-th tree (1 \leq i \leq N) will inspect the trees with numbers between i-D and i+D (inclusive). Find the minimum number of inspectors that we need to deploy to achieve the objective.
[{"input": "6 2", "output": "2\n \n\nWe can achieve the objective by, for example, placing an inspector under Tree\n3 and Tree 4.\n\n* * *"}, {"input": "14 3", "output": "2\n \n\n* * *"}, {"input": "20 4", "output": "3"}]
Print the minimum number of inspectors that we need to deploy to achieve the objective. * * *
s020937285
Wrong Answer
p02970
Input is given from Standard Input in the following format: N D
N, D = [int(n) for n in input().split()] print((N - 1) // (2 * D) + 1)
Statement There are N apple trees in a row. People say that one of them will bear golden apples. We want to deploy some number of inspectors so that each of these trees will be inspected. Each inspector will be deployed under one of the trees. For convenience, we will assign numbers from 1 through N to the trees. An inspector deployed under the i-th tree (1 \leq i \leq N) will inspect the trees with numbers between i-D and i+D (inclusive). Find the minimum number of inspectors that we need to deploy to achieve the objective.
[{"input": "6 2", "output": "2\n \n\nWe can achieve the objective by, for example, placing an inspector under Tree\n3 and Tree 4.\n\n* * *"}, {"input": "14 3", "output": "2\n \n\n* * *"}, {"input": "20 4", "output": "3"}]