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 probability of having more heads than tails. The output is considered correct when the absolute error is not greater than 10^{-9}. * * *
s523144179
Accepted
p03168
Input is given from Standard Input in the following format: N p_1 p_2 \ldots p_N
from subprocess import * call( ( "pypy3", "-c", """ n=int(input()) p=list(map(float,input().split())) dp=[[0]*-~n for _ in range(n)] dp[0][1]=p[0] dp[0][0]=1-p[0] for i in range(1,n): dp[i][0]=dp[i-1][0]*(1-p[i]) for j in range(1,n+1): dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]) print(sum(dp[-1][-~n//2:])) """, ) )
Statement Let N be a positive odd number. There are N coins, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i. Taro has tossed all the N coins. Find the probability of having more heads than tails.
[{"input": "3\n 0.30 0.60 0.80", "output": "0.612\n \n\nThe probability of each case where we have more heads than tails is as\nfollows:\n\n * The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Head) is 0.3 \u00d7 0.6 \u00d7 0.8 = 0.144;\n * The probability of having (Coin 1, Coin 2, Coin 3) = (Tail, Head, Head) is 0.7 \u00d7 0.6 \u00d7 0.8 = 0.336;\n * The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Tail, Head) is 0.3 \u00d7 0.4 \u00d7 0.8 = 0.096;\n * The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Tail) is 0.3 \u00d7 0.6 \u00d7 0.2 = 0.036.\n\nThus, the probability of having more heads than tails is 0.144 + 0.336 + 0.096\n+ 0.036 = 0.612.\n\n* * *"}, {"input": "1\n 0.50", "output": "0.5\n \n\nOutputs such as `0.500`, `0.500000001` and `0.499999999` are also considered\ncorrect.\n\n* * *"}, {"input": "5\n 0.42 0.01 0.42 0.99 0.42", "output": "0.3821815872"}]
Print the probability of having more heads than tails. The output is considered correct when the absolute error is not greater than 10^{-9}. * * *
s800129922
Accepted
p03168
Input is given from Standard Input in the following format: N p_1 p_2 \ldots p_N
n = int(input()) p = list(map(float, input().split())) dp = [[0] * (2 * n + 2) for i in range(n // 2 + 1)] dp[0][n + 1] = p[0] dp[0][n] = 1 - p[0] for i in range(n // 2): p1, p2 = p[2 * i + 1], p[2 * i + 2] h, t = p1 * p2, (1 - p1) * (1 - p2) m = 1 - h - t for j in range(n - i, n + i + 2): plus = dp[i][j] dp[i + 1][j + 1] += plus * h dp[i + 1][j] += plus * m dp[i + 1][j - 1] += plus * t print(sum(dp[n // 2][n + 1 :]))
Statement Let N be a positive odd number. There are N coins, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i. Taro has tossed all the N coins. Find the probability of having more heads than tails.
[{"input": "3\n 0.30 0.60 0.80", "output": "0.612\n \n\nThe probability of each case where we have more heads than tails is as\nfollows:\n\n * The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Head) is 0.3 \u00d7 0.6 \u00d7 0.8 = 0.144;\n * The probability of having (Coin 1, Coin 2, Coin 3) = (Tail, Head, Head) is 0.7 \u00d7 0.6 \u00d7 0.8 = 0.336;\n * The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Tail, Head) is 0.3 \u00d7 0.4 \u00d7 0.8 = 0.096;\n * The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Tail) is 0.3 \u00d7 0.6 \u00d7 0.2 = 0.036.\n\nThus, the probability of having more heads than tails is 0.144 + 0.336 + 0.096\n+ 0.036 = 0.612.\n\n* * *"}, {"input": "1\n 0.50", "output": "0.5\n \n\nOutputs such as `0.500`, `0.500000001` and `0.499999999` are also considered\ncorrect.\n\n* * *"}, {"input": "5\n 0.42 0.01 0.42 0.99 0.42", "output": "0.3821815872"}]
Print the probability of having more heads than tails. The output is considered correct when the absolute error is not greater than 10^{-9}. * * *
s170775759
Accepted
p03168
Input is given from Standard Input in the following format: N p_1 p_2 \ldots p_N
def examA(): N = I() H = LI() dp = [inf] * (N) dp[0] = 0 for i in range(N - 1): dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i])) if i < N - 2: dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i])) ans = dp[-1] print(ans) return def examB(): N, K = LI() H = LI() dp = [inf] * N dp[0] = 0 for i in range(N): for k in range(1, K + 1): if i + k >= N: break if dp[i + k] > dp[i] + abs(H[i + k] - H[i]): dp[i + k] = dp[i] + abs(H[i + k] - H[i]) ans = dp[-1] print(ans) return def examC(): N = I() A = [0] * N B = [0] * N C = [0] * N for i in range(N): A[i], B[i], C[i] = LI() dp = [[0] * 3 for _ in range(N + 1)] for i in range(N): dp[i + 1][0] = max(dp[i][1], dp[i][2]) + A[i] dp[i + 1][1] = max(dp[i][0], dp[i][2]) + B[i] dp[i + 1][2] = max(dp[i][1], dp[i][0]) + C[i] ans = max(dp[N]) print(ans) return def examD(): ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): # LCS S = SI() N = len(S) T = SI() M = len(T) dp = [[0] * (M + 1) for _ in range(N + 1)] for i in range(N): for j in range(M): if S[i] == T[j]: dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j], dp[i][j + 1]) i = N j = M ans = [] while i > 0 and j > 0: if dp[i][j] == dp[i - 1][j]: i -= 1 elif dp[i][j] == dp[i][j - 1]: j -= 1 else: ans.append(S[i - 1]) i -= 1 j -= 1 print("".join(ans[::-1])) return def examG(): # http://zehnpaard.hatenablog.com/entry/2018/06/26/201512 # トポロジカルソート def topological_sort(n, outs, ins): q = deque(v1 for v1 in range(n) if ins[v1] == 0) res = [] while q: v1 = q.popleft() res.append(v1) for v2 in outs[v1]: ins[v2] -= 1 if ins[v2] == 0: q.append(v2) return res N, M = LI() V = [[] for _ in range(N)] start = [0] * N for _ in range(M): x, y = LI() x -= 1 y -= 1 V[x].append(y) start[y] += 1 Order = topological_sort(N, V, start) # print(Order) dp = [0] * N for i in Order: for v in V[i]: dp[v] = max(dp[v], dp[i] + 1) ans = max(dp) print(ans) return def examH(): H, W = LI() A = [SI() for _ in range(H)] dp = [[0] * W for _ in range(H)] dp[0][0] = 1 for i in range(H): for j in range(W): if A[i][j] == "#": continue dp[i][j] %= mod if i + 1 < H and dp[i + 1][j] != "#": dp[i + 1][j] += dp[i][j] if j + 1 < W and dp[i][j + 1] != "#": dp[i][j + 1] += dp[i][j] ans = dp[-1][-1] print(ans) return def examI(): N = I() P = LFI() dp = [[0] * (N + 1) for _ in range(N + 1)] dp[0][0] = 1 for i in range(N): for j in range(i + 1): dp[i + 1][j + 1] += dp[i][j] * P[i] dp[i + 1][j] += dp[i][j] * (1 - P[i]) ans = 0 for v in dp[N][(1 + N // 2) :]: ans += v print(ans) return import sys, copy, bisect, itertools, heapq, math from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LFI(): return list(map(float, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 alphabet = [chr(ord("a") + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == "__main__": examI() """ """
Statement Let N be a positive odd number. There are N coins, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i. Taro has tossed all the N coins. Find the probability of having more heads than tails.
[{"input": "3\n 0.30 0.60 0.80", "output": "0.612\n \n\nThe probability of each case where we have more heads than tails is as\nfollows:\n\n * The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Head) is 0.3 \u00d7 0.6 \u00d7 0.8 = 0.144;\n * The probability of having (Coin 1, Coin 2, Coin 3) = (Tail, Head, Head) is 0.7 \u00d7 0.6 \u00d7 0.8 = 0.336;\n * The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Tail, Head) is 0.3 \u00d7 0.4 \u00d7 0.8 = 0.096;\n * The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Tail) is 0.3 \u00d7 0.6 \u00d7 0.2 = 0.036.\n\nThus, the probability of having more heads than tails is 0.144 + 0.336 + 0.096\n+ 0.036 = 0.612.\n\n* * *"}, {"input": "1\n 0.50", "output": "0.5\n \n\nOutputs such as `0.500`, `0.500000001` and `0.499999999` are also considered\ncorrect.\n\n* * *"}, {"input": "5\n 0.42 0.01 0.42 0.99 0.42", "output": "0.3821815872"}]
Print each permutation in a line in order. Separate adjacency elements by a space character.
s255959383
Accepted
p02450
An integer $n$ is given in a line.
import sys sys.setrecursionlimit(10**8) n = int(input()) a = [i for i in range(1, n + 1)] def permute(deep, ans): if deep == 0: print(ans.strip()) else: for i in a: if str(i) not in ans: permute(deep - 1, ans + " " + str(i)) permute(n, "")
Permutation Enumeration For given an integer $n$, print all permutations of $\\{1, 2, ..., n\\}$ in lexicographic order.
[{"input": "2", "output": "1 2\n 2 1"}, {"input": "3", "output": "1 2 3\n 1 3 2\n 2 1 3\n 2 3 1\n 3 1 2\n 3 2 1"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s630546093
Accepted
p03241
Input is given from Standard Input in the following format: N M
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list(map(lambda x: int(x) - 1, stdin.readline().split())) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") # A def A(): n = II() if n == 1: print("Hello World") else: print(II() + II()) return # B def B(): n, t = LI() ans = inf for _ in range(n): c, ti = LI() if ti <= t: ans = min(ans, c) if ans == inf: print("TLE") return print(ans) return # C def C(): n = II() xyh = LIR(n) xyh.sort(key=lambda x: x[2], reverse=True) x1, y1, h1 = xyh[0] del xyh[0] for x in range(101): for y in range(101): h = abs(x - x1) + abs(y - y1) + h1 flg = True for xn, yn, hn in xyh: if max(h - abs(x - xn) - abs(y - yn), 0) == hn: continue flg = False break if flg: print(x, y, h) return return # D def D(): n, m = LI() ans = 1 for i in range(1, int(math.sqrt(m) + 1)): if m % i == 0: a = m // i # print(i,a) if a * n <= m: ans = max(ans, a) if i * n <= m: ans = max(ans, i) print(ans) return # Solve if __name__ == "__main__": D()
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s180168305
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
n, m = map(int, input().split()) s = [] for i in range(1, int(m**2) + 1): if m % i == 0 and i < n: s.append(i) if m / i < n: s.append(m / i) print(max(s))
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s667176027
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
import sys import math import collections import itertools import array import inspect # Set max recursion limit sys.setrecursionlimit(1000000) # Debug output def chkprint(*args): names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()} print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args)) # Binary converter def to_bin(x): return bin(x)[2:] def li_input(): return [int(_) for _ in input().split()] def gcd(n, m): if n % m == 0: return m else: return gcd(m, n % m) def gcd_list(L): v = L[0] for i in range(1, len(L)): v = gcd(v, L[i]) return v def lcm(n, m): return (n * m) // gcd(n, m) def lcm_list(L): v = L[0] for i in range(1, len(L)): v = lcm(v, L[i]) return v # Width First Search (+ Distance) def wfs_d(D, N, K): """ D: 隣接行列(距離付き) N: ノード数 K: 始点ノード """ dfk = [-1] * (N + 1) dfk[K] = 0 cps = [(K, 0)] r = [False] * (N + 1) r[K] = True while len(cps) != 0: n_cps = [] for cp, cd in cps: for i, dfcp in enumerate(D[cp]): if dfcp != -1 and not r[i]: dfk[i] = cd + dfcp n_cps.append((i, cd + dfcp)) r[i] = True cps = n_cps[:] return dfk # Depth First Search (+Distance) def dfs_d(v, pre, dist): """ v: 現在のノード pre: 1つ前のノード dist: 現在の距離 以下は別途用意する D: 隣接リスト(行列ではない) D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト """ global D global D_dfs_d D_dfs_d[v] = dist for next_v, d in D[v]: if next_v != pre: dfs_d(next_v, v, dist + d) return def sigma(N): ans = 0 for i in range(1, N + 1): ans += i return ans def comb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2, r + 1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p - 1, r, p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result def bisearch(L, target): low = 0 high = len(L) - 1 while low <= high: mid = (low + high) // 2 guess = L[mid] if guess == target: return True elif guess < target: low = mid + 1 elif guess > target: high = mid - 1 if guess != target: return False # -------------------------------------------- dp = None def main(): N, M = li_input() x = M // N ans = -1 if N == 1: print(M) return if M == 10**9: if N == 2: print(500000000) return if N == 3 or N == 4: print(250000000) return if N == 5: print(200000000) return for i in range(x, 0, -1): j = M - (i * (N - 1)) ans = max(ans, math.gcd(i, j)) if i - 1 < ans: break print(ans) main()
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s953462243
Accepted
p03241
Input is given from Standard Input in the following format: N M
import math n, m = map(int, input().split()) r = m k = 0 a = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, ] for i in range(len(a)): if m % a[i] == 0 and m >= a[i]: r = m // a[i] break if r == m and m >= 199: r = m // 199 if n > r: k = 1 while n <= r: if m % n == 0: break n += 1 if n == r + 1 or k == 1: print(1) else: print(m // n)
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s852920312
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
# 求める出力は,mの約数iのうち n*i <= m を満たす最大の整数n. N, M = map(int, input().split()) fracs = [] i = 2 m = M # mの素因数分解を求める while m > 1 and M**0.5: while m % i == 0: m //= i if len(fracs) == 0: fracs.append([i, 1]) elif fracs[-1][0] == i: fracs[-1][1] += 1 else: fracs.append([i, 1]) i += 1 if m != 1: fracs.append(m, 1) # 約数を全て列挙する divisors = [] def search(i, p): for j in range(fracs[i][1] + 1): if i != len(fracs) - 1: new_p = p * fracs[i][0] ** j search(i + 1, new_p) else: divisors.append(p * fracs[i][0] ** j) search(0, 1) print(sorted(list(filter(lambda x: x * N <= M, divisors)))[-1])
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s751570909
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(str, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #import numpy as np from decimal import * # N以上でMを割り切ることができる最小の数nを求める → 答え M//n N, M = MAP() 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) divisors.sort() return divisors divisors = make_divisors(M) print(divisors)n = divisors[bisect_left(divisors, N)] print(M//n)
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s808216869
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
def divisor(n): i = 1 res = [] for i in range(1, n**.5 + 1) if n%i == 0: res.append(i) if n//i not in res: res.append(n//i) res.sort(reverse=True) return res def main(): n, m = map(int, input().split()) md = divisor(m) for i in md: if i*n <= m: print(i) exit() if __name__ == '__main__': main()
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s894724390
Accepted
p03241
Input is given from Standard Input in the following format: N M
############################################################################### from bisect import bisect_left as binl from copy import copy, deepcopy def intin(): input_tuple = input().split() if len(input_tuple) <= 1: return int(input_tuple[0]) return tuple(map(int, input_tuple)) def intina(): return [int(i) for i in input().split()] def intinl(count): return [intin() for _ in range(count)] def modadd(x, y): global mod return (x + y) % mod def modmlt(x, y): global mod return (x * sy) % mod def lcm(x, y): while y != 0: z = x % y x = y y = z return x def make_linklist(xylist): linklist = {} for a, b in xylist: linklist.setdefault(a, []) linklist.setdefault(b, []) linklist[a].append(b) linklist[b].append(a) return linklist def calc_longest_distance(linklist, v=1): distance_list = {} distance_count = 0 distance = 0 vlist_previous = [] vlist = [v] nodecount = len(linklist) while distance_count < nodecount: vlist_next = [] for v in vlist: distance_list[v] = distance distance_count += 1 vlist_next.extend(linklist[v]) distance += 1 vlist_to_del = vlist_previous vlist_previous = vlist vlist = list(set(vlist_next) - set(vlist_to_del)) max_distance = -1 max_v = None for v, distance in distance_list.items(): if distance > max_distance: max_distance = distance max_v = v return (max_distance, max_v) def calc_tree_diameter(linklist, v=1): _, u = calc_longest_distance(linklist, v) distance, _ = calc_longest_distance(linklist, u) return distance ############################################################################### def get_factors(x): retlist = [] for i in range(1, int(x**0.5) + 3): if x % i == 0: retlist.append(i) retlist.append(x // i) return retlist def main(): n, m = intin() flist = get_factors(m) flist.sort() for f in flist: if f >= n: print(m // f) return if __name__ == "__main__": main()
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s334951777
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
N,M = map(int,input().split()) for i in range(M//N,0,-1): if m%i!=0: break else (M-N*i)%i==0: ret = i print(ret) break
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s626902606
Wrong Answer
p03241
Input is given from Standard Input in the following format: N M
a, b = map(int, input().split()) print(int(b % a))
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s032013460
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
N,M=map(int,input().split()) a=M//N x=0 for i in reversed(range(2,a+1)): if M%i==0: x=i break print(x)
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s786926905
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
N,M=map(int,input().split()) if M%N==0: print(M//N) else: s=M//N if s<100000: ans=1 while s!=1: if M%s==0: ans=s break s-=1 print(ans) else: rM=M**(1/2) s=N ans=1 while s<=rM: if M%s==0: ans=M//s break s+=1 else: s=N while s!=1: if M%s==0: ans=s break s-=1 print(ans)
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s525984708
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = l[0], M = l[1]; if (M % N == 0) Console.WriteLine(M / N); else { var div = M / N; var rem = M % N; Console.WriteLine(Gcd(div, rem)); } } static int Gcd(int a, int b) { if (a < b) Gcd(b, a); if (b == 0) return a; return Gcd(b, (a % b)); } } }
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s598597106
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
// finish date: 2018/10/08 #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++) #define rep(i, n) FOR(i,0,n) typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<vector<int>>> vvvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<double> vd; typedef vector<vector<double>> vvd; typedef vector<vector<vector<double>>> vvvd; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<string> vs; typedef vector<char> vc; typedef vector<vector<char>> vvc; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, pair<int, int>> plii; const int bigmod = 1000000007; const int INF = 1050000000; const long long INFll = 100000000000000000; //素因数分解 map<int, int> p_fact(int n) { map<int, int> mp; int i = 2; while (n >= i * i) { while (n % i == 0) mp[i]++, n /= i; i++; } if (n != 1) mp[n]++; return mp; } map<int, int> mp; int N, M; int ans = 1; void dfs(map<int, int>::iterator itr, int temp = 1) { if (itr == mp.end()) { if (M % temp == 0 && M / temp >= N) ans = max(ans, temp); return; } rep(i, itr->second + 1) { dfs(next(itr), temp * (int) (round(pow(itr->first, i)))); } } int main() { cin >> N >> M; mp = p_fact(M); dfs(mp.begin()); cout << ans << endl; return 0; }
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s303987789
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
def divisore(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) divisors.sort(reverse=True) return divisors n,m=map(int,input().split()) l=divisore(m) for i in l: if m/n>=i: print(i) exit()
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s280721596
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
vimport sys def main(): N, M = map(int, input().split()) s = M // N # 答えはs以下 m = M % N for i in range(s, 0, -1): if m % s == 0: print(s) sys.exit() else: s -= 1 m += N main()
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s541329926
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
n,m = map(int, input().split()) i = 1 ans = 0 while i * i <= m: if m % i == 0: if i >= n: if i >= n: ans = max(ans, m // i) else m // i >= n: ans = max(ans(ans, i)) print(ans)
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s747549061
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
N, M = map(int, input().split()) for i in range(2, min(int(M**0.5)+1, M//N + 1)): if M%i == 0: if M/i <= M//N: print(M/i) exit() ans = i print(i)
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s524416651
Accepted
p03241
Input is given from Standard Input in the following format: N M
#!/usr/bin/env python3 import math class Prime: seed_primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, ] def is_prime(self, n): is_prime_common = self.is_prime_common(n) if is_prime_common is not None: return is_prime_common if n < 2000000: return self.is_prime_bf(n) else: return self.is_prime_mr(n) def is_prime_common(self, n): if n == 1: return False if n in Prime.seed_primes: return True if any(map(lambda x: n % x == 0, self.seed_primes)): return False def is_prime_bf(self, n): for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True def is_prime_mr(self, n): d = n - 1 while d % 2 == 0: d //= 2 witnesses = self.get_witnesses(n) for w in witnesses: y = pow(w, d, n) while d != n - 1 and y != 1 and y != n - 1: y = (y**2) % n d *= 2 if y != n - 1 and d % 2 == 0: return False return True def get_witnesses(self, num): def _get_range(num): if num < 2047: return 1 if num < 1373653: return 2 if num < 25326001: return 3 if num < 3215031751: return 4 if num < 2152302898747: return 5 if num < 3474749660383: return 6 if num < 341550071728321: return 7 if num < 38255123056546413051: return 9 return 12 return self.seed_primes[: _get_range(num)] def gcd(self, a, b): if a < b: a, b = b, a if b == 0: return a while b: a, b = b, a % b return a @staticmethod def f(x, n, seed): p = Prime.seed_primes[seed % len(Prime.seed_primes)] return (p * x + seed) % n def find_factor(self, n, seed=1): if self.is_prime(n): return n x, y, d = 2, 2, 1 count = 0 while d == 1: count += 1 x = self.f(x, n, seed) y = self.f(self.f(y, n, seed), n, seed) d = self.gcd(abs(x - y), n) if d == n: return self.find_factor(n, seed + 1) return self.find_factor(d) def find_factors(self, n): primes = {} if self.is_prime(n): primes[n] = 1 return primes while n > 1: factor = self.find_factor(n) primes.setdefault(factor, 0) primes[factor] += 1 n //= factor return primes prime = Prime() def main(): [N, M] = list(map(int, input().split())) prime = Prime() factors = prime.find_factors(M) max_g = M // N g = 1 d = [1] for p, n in factors.items(): nd = [] for v in d: for k in range(n + 1): m = p**k if v * m <= max_g: g = max(g, v * m) nd.append(v * m) else: break d = nd print(g) if __name__ == "__main__": main()
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s912432210
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
import random def is_prime(q,k=50): if q == 2: return True if q < 2 or q&1 == 0: return False d = (q-1)>>1 while d&1 == 0: d >>= 1 for i in range(k): a = random.randint(1,q-1) t = d y = pow(a,t,q) while t != q-1 and y != 1 and y != q-1: y = pow(y,2,q) t <<= 1 if y != q-1 and t&1 == 0: return False return True n,m=(int(i) for i in input().split(' ')) if m%n>10000: for i in range(1,n): if m%i==0 and is_prime(i) and is_prime(m//i) and (i==1 or m//i<n): print('1') exit() for i in range(n,m+1): if i==m: print(1) break if m%i==0: print(m//i) break if m%(m-i+1)==0 print(m-i+1) break
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s249904822
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
import random def is_prime(q,k=50): if q == 2: return True if q < 2 or q&1 == 0: return False d = (q-1)>>1 while d&1 == 0: d >>= 1 for i in range(k): a = random.randint(1,q-1) t = d y = pow(a,t,q) while t != q-1 and y != 1 and y != q-1: y = pow(y,2,q) t <<= 1 if y != q-1 and t&1 == 0: return False return True n,m=(int(i) for i in input().split(' ')) if n<1000: for i in range(1,n): if m%i==0 and (is_prime(i) or i=1) and is_prime(m//i) and (i==1 or m//i<n): print('1') exit() for i in range(n,m+1): if i==m: print(1) break if m%i==0: print(m//i) break if m-i-n>0 and m%(m-i-n)==0 and m//(m-i-n)>n: print(m-i-n) break
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. * * *
s598920437
Runtime Error
p03241
Input is given from Standard Input in the following format: N M
n, m = map(int, input().split()) k = m//n ans = 0 for i in range(1, int(m**0.5)+1): if m%i == 0: if i <= k: if i <= k: ans = max(ans, i) if m//i <= k: ans = max(ans, m//i) print(ans)
Statement You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
[{"input": "3 14", "output": "2\n \n\nConsider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common\ndivisor is 2, and this is the maximum value.\n\n* * *"}, {"input": "10 123", "output": "3\n \n\n* * *"}, {"input": "100000 1000000000", "output": "10000"}]
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1. If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format: s_{11}s_{12}\cdots s_{1W} s_{21}s_{22}\cdots s_{2W} \vdots s_{H1}s_{H2}\cdots s_{HW} Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid. If multiple solutions exist, printing any of them will be accepted. * * *
s853318930
Runtime Error
p02903
Input is given from Standard Input in the following format: H W A B
# -*- coding: utf-8 -*- import sys import numpy as np inFile = "" # inFile = 'test2.txt' if inFile != "": f = open(inFile, "r") sys.stdin = f input = sys.stdin.readline def lineInput(tList): # ex. tList = 'sdf' buf = list(input().strip().split()) ret = [] for i in range(len(tList)): if tList[i] == "d": ret.append(int(buf[i])) elif tList[i] == "f": ret.append(float(buf[i])) else: ret.append(buf[i]) return ret def gridInput(N): grid = [] t = "d" * N for i in range(N): array = lineInput(t) grid.append(array) return grid def outputList(l): for i, d in enumerate(l): if i < len(l) - 1: print(d, end=" ") else: print(d) def outputGrid(grid): for x in grid: outputList(x) # [n] = lineInput("d") # g = gridInput(n) # outputGrid(g) def modlog(x, y): r = x % y return r def gcd(x, y): r = modlog(x, y) while r != 0: x = y y = r r = modlog(x, y) return y def kobai(x, y): z = np.gcd(x, y) return x * y / z def mondai(N, List): ret = 0 for i in range(0, N - 1): for j in range(i + 1, N): x = kobai(List[i], List[j]) ret += x ret %= 998244353 return int(ret) [N] = lineInput("d") s = "d" * N List = lineInput(s) ans = mondai(N, List) print(ans)
Statement We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied: * For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.) * For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column. Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
[{"input": "3 3 1 1", "output": "100\n 010\n 001\n \n\nEvery row contains two 0s and one 1, so the first condition is satisfied.\nAlso, every column contains two 0s and one 1, so the second condition is\nsatisfied.\n\n* * *"}, {"input": "1 5 2 0", "output": "01010"}]
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1. If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format: s_{11}s_{12}\cdots s_{1W} s_{21}s_{22}\cdots s_{2W} \vdots s_{H1}s_{H2}\cdots s_{HW} Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid. If multiple solutions exist, printing any of them will be accepted. * * *
s001735893
Wrong Answer
p02903
Input is given from Standard Input in the following format: H W A B
print(2)
Statement We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied: * For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.) * For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column. Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
[{"input": "3 3 1 1", "output": "100\n 010\n 001\n \n\nEvery row contains two 0s and one 1, so the first condition is satisfied.\nAlso, every column contains two 0s and one 1, so the second condition is\nsatisfied.\n\n* * *"}, {"input": "1 5 2 0", "output": "01010"}]
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1. If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format: s_{11}s_{12}\cdots s_{1W} s_{21}s_{22}\cdots s_{2W} \vdots s_{H1}s_{H2}\cdots s_{HW} Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid. If multiple solutions exist, printing any of them will be accepted. * * *
s731406347
Runtime Error
p02903
Input is given from Standard Input in the following format: H W A B
stdin = input() (H, W, A, B) = [int(a) for a in stdin.split(" ")] # print('{}, {}, {}, {}'.format(H, W, A, B)) ans = [[0 for w in range(W)] for h in range(H)] # print(ans) # Aの方が大きい def get_ans(H, W, A, B): h = 0 w = 0 if A >= B: # if W % A != 0 or int(W / A) * B != H: # print('No') # return while h < H: start = int(h / B) * A + h % B if (start + A - 1) < W: end = start + A - 1 for i in range(start, end + 1): ans[h][i] = 1 else: end = W - 1 for i in range(start, end + 1): ans[h][i] = 1 amari = end + 1 - start for i in range(amari): ans[h][i] = 1 h += 1 else: # if H % B != 0 or int(H / B) * A != W: # print('No') # return while w < W: start = int(w / A) * B + w % A if (start + B - 1) < H: end = start + B - 1 for i in range(start, end + 1): ans[i][w] = 1 else: end = H - 1 for i in range(start, end + 1): ans[i][w] = 1 amari = end + 1 - start for i in range(amari): ans[i][w] = 1 w += 1 for h in range(H): print("".join(map(str, ans[h]))) get_ans(H, W, A, B)
Statement We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied: * For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.) * For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column. Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
[{"input": "3 3 1 1", "output": "100\n 010\n 001\n \n\nEvery row contains two 0s and one 1, so the first condition is satisfied.\nAlso, every column contains two 0s and one 1, so the second condition is\nsatisfied.\n\n* * *"}, {"input": "1 5 2 0", "output": "01010"}]
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1. If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format: s_{11}s_{12}\cdots s_{1W} s_{21}s_{22}\cdots s_{2W} \vdots s_{H1}s_{H2}\cdots s_{HW} Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid. If multiple solutions exist, printing any of them will be accepted. * * *
s610018125
Wrong Answer
p02903
Input is given from Standard Input in the following format: H W A B
from fractions import gcd def solve(h, w, a, b): ans = [] if h == 1: ans = ["0" * a + "1" * (w - a)] return ans loop = w // gcd(w, a) val = loop * a // w base = "0" * a + "1" * (w - a) not_base = "1" * a + "0" * (w - a) loop_str = [] for i in range(loop): shift = (w // loop) * i loop_str.append(base[shift:] + base[:shift]) fill_str = [base, not_base] for i in range(h // loop + 1): if (h - loop * i) % 2 == 1: continue fill = (h - loop * i) // 2 ret = i * val + fill if ret == b: ans += loop_str * i ans += fill_str * fill return ans return None h, w, a, b = [int(item) for item in input().split()] ans = solve(h, w, a, b) if ans: for line in ans: print(line) exit() ans = solve(w, h, b, a) if ans: nans = "" for j in range(h): for i in range(w): nans += ans[i][j] nans += "\n" print(nans, end="") exit() print("No")
Statement We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied: * For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.) * For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column. Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
[{"input": "3 3 1 1", "output": "100\n 010\n 001\n \n\nEvery row contains two 0s and one 1, so the first condition is satisfied.\nAlso, every column contains two 0s and one 1, so the second condition is\nsatisfied.\n\n* * *"}, {"input": "1 5 2 0", "output": "01010"}]
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1. If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format: s_{11}s_{12}\cdots s_{1W} s_{21}s_{22}\cdots s_{2W} \vdots s_{H1}s_{H2}\cdots s_{HW} Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid. If multiple solutions exist, printing any of them will be accepted. * * *
s301835569
Runtime Error
p02903
Input is given from Standard Input in the following format: H W A B
import copy x, y, a, b = list(map(int, input().split())) base = [a, b, x, y] c1 = [0] * x c2 = copy.deepcopy(c1) c1[:a] = [1] * a c2[: (len(c1) - a)] = [1] * (len(c1) - a) d1 = [a, a, x, x] if base[3] > 1 and base[2] > 1: if x % a == 0: d2 = [1, 1, x, 2] small = d2[3] large = d1[3] ans_sum = False for i in range(base[3] // large + 1): tsum = (large) * i nokori = base[3] - tsum i2 = nokori // small if ( nokori % small == 0 and base[3] == tsum + (small * i2) and base[1] == d1[1] * i + d2[1] * i2 ): ans_sum = True break if ans_sum: ans_sum = [] if i > 0: for h in range(i): ans = [c1] cc1 = copy.deepcopy(c1) for i in range(d1[3] - 1): y1 = cc1[::-1].index(1) y2 = d1[3] - y1 cc1 = [0] * x for j in range(d1[1]): y3 = y2 + j if y3 >= d1[3]: y3 = abs(d1[3] - y3) cc1[y3] = 1 ans.append(cc1) ans_sum.append(ans) if i2 > 0: for h in range(i2): ans = [c1] cc1 = copy.deepcopy(c1) for i, name in enumerate(cc1): if name == 1: cc1[i] = 0 else: cc1[i] = 1 ans.append(cc1) ans_sum.append(ans) else: ans_sum = "No" else: if y // d1[3] == b // d1[1]: ans_sum = [] for h in range(b // d1[1]): ans = [c1] cc1 = copy.deepcopy(c1) for i in range(d1[3] - 1): y1 = cc1[::-1].index(1) y2 = d1[3] - y1 cc1 = [0] * x for j in range(d1[1]): y3 = y2 + j if y3 >= d1[3]: y3 = abs(d1[3] - y3) cc1[y3] = 1 ans.append(cc1) ans_sum.append(ans) else: ans_sum = "No" if base[2] == 1 and base[1] == 0: c1 = [0] * base[3] for i in range(base[0]): c1[i] = 1 print("".join(map(str, c1))) elif base[3] == 1 and base[0] == 0: c1 = [0] * base[2] for i in range(base[1]): c1[i] = 1 for i in c1: print(i) elif ans_sum == "No": print(ans_sum) else: for j in ans_sum: for i in j: y1 = list(map(str, i)) print("".join(y1))
Statement We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied: * For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.) * For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column. Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
[{"input": "3 3 1 1", "output": "100\n 010\n 001\n \n\nEvery row contains two 0s and one 1, so the first condition is satisfied.\nAlso, every column contains two 0s and one 1, so the second condition is\nsatisfied.\n\n* * *"}, {"input": "1 5 2 0", "output": "01010"}]
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1. If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format: s_{11}s_{12}\cdots s_{1W} s_{21}s_{22}\cdots s_{2W} \vdots s_{H1}s_{H2}\cdots s_{HW} Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid. If multiple solutions exist, printing any of them will be accepted. * * *
s587581554
Wrong Answer
p02903
Input is given from Standard Input in the following format: H W A B
H, W, A, B = map(int, input().split()) ans = [[0] * W for _ in range(H)] X = [0] * W fail = False if H == 1 and B == 0: print("1" * A + "0" * (W - A)) elif W == 1 and A == 0: for _ in range(B): print(1) for _ in range(H - B): print(0) else: for i in range(H): s = 0 while s < W and X[s] >= B: s += 1 c = 0 while s < W and c < A: ans[i][s] = 1 X[s] += 1 s += 1 c += 1 if c < A: fail = True break print("\n".join(["".join([str(x) for x in a]) for a in ans]) if not fail else "No")
Statement We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied: * For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.) * For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column. Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
[{"input": "3 3 1 1", "output": "100\n 010\n 001\n \n\nEvery row contains two 0s and one 1, so the first condition is satisfied.\nAlso, every column contains two 0s and one 1, so the second condition is\nsatisfied.\n\n* * *"}, {"input": "1 5 2 0", "output": "01010"}]
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1. If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format: s_{11}s_{12}\cdots s_{1W} s_{21}s_{22}\cdots s_{2W} \vdots s_{H1}s_{H2}\cdots s_{HW} Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid. If multiple solutions exist, printing any of them will be accepted. * * *
s308324266
Accepted
p02903
Input is given from Standard Input in the following format: H W A B
h, w, a, b = map(int, input().split()) # 横を作る # まずは左が1バージョン up = [] if a > 0: for i in range(a): up.append(1) for i in range(w - a): up.append(0) # その反転バージョン down = [1 - up[i] for i in range(w)] str_up = [str(i) for i in up] str_down = [str(i) for i in down] ans_up = "".join(str_up) ans_down = "".join(str_down) if b > 0: for i in range(b): print(ans_up) for i in range(h - b): print(ans_down)
Statement We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied: * For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.) * For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column. Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
[{"input": "3 3 1 1", "output": "100\n 010\n 001\n \n\nEvery row contains two 0s and one 1, so the first condition is satisfied.\nAlso, every column contains two 0s and one 1, so the second condition is\nsatisfied.\n\n* * *"}, {"input": "1 5 2 0", "output": "01010"}]
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1. If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format: s_{11}s_{12}\cdots s_{1W} s_{21}s_{22}\cdots s_{2W} \vdots s_{H1}s_{H2}\cdots s_{HW} Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid. If multiple solutions exist, printing any of them will be accepted. * * *
s011844366
Accepted
p02903
Input is given from Standard Input in the following format: H W A B
(H, W, A, B) = map(int, input().split()) [print(*[int((i < B) ^ (j < A)) for j in range(W)], sep="") for i in range(H)]
Statement We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied: * For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.) * For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column. Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
[{"input": "3 3 1 1", "output": "100\n 010\n 001\n \n\nEvery row contains two 0s and one 1, so the first condition is satisfied.\nAlso, every column contains two 0s and one 1, so the second condition is\nsatisfied.\n\n* * *"}, {"input": "1 5 2 0", "output": "01010"}]
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1. If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format: s_{11}s_{12}\cdots s_{1W} s_{21}s_{22}\cdots s_{2W} \vdots s_{H1}s_{H2}\cdots s_{HW} Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid. If multiple solutions exist, printing any of them will be accepted. * * *
s849466452
Wrong Answer
p02903
Input is given from Standard Input in the following format: H W A B
( lambda H, W, A, B: [ print(*[int((i < B) ^ (j < A)) for j in range(W)]) for i in range(H) ] )(*(map(int, input().split())))
Statement We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied: * For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.) * For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column. Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
[{"input": "3 3 1 1", "output": "100\n 010\n 001\n \n\nEvery row contains two 0s and one 1, so the first condition is satisfied.\nAlso, every column contains two 0s and one 1, so the second condition is\nsatisfied.\n\n* * *"}, {"input": "1 5 2 0", "output": "01010"}]
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1. If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format: s_{11}s_{12}\cdots s_{1W} s_{21}s_{22}\cdots s_{2W} \vdots s_{H1}s_{H2}\cdots s_{HW} Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid. If multiple solutions exist, printing any of them will be accepted. * * *
s323584183
Accepted
p02903
Input is given from Standard Input in the following format: H W A B
# coding: utf-8 def solve(arg: str) -> str: h, w, a, b = map(int, arg.split()) mat = [[0] * w for _ in range(h)] sumy = [0] * w for y in range(h): sumx = 0 for x in range(w): if ( (sumy[x] < b and sumx < a) or (sumy[x] < h - b and sumx < a) or (sumy[x] < b and sumx < w - a) or (sumy[x] < h - b and sumx < w - a) ): mat[y][x] = 1 sumx += 1 sumy[x] += 1 if min(sumx, w - sumx) != a: return "No" for s in sumy: if min(s, h - s) != b: return "No" ret = "" for y in range(h): for x in range(w): ret += str(mat[y][x]) if y != h - 1: ret += "\n" return ret if __name__ == "__main__": print(solve(input()))
Statement We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied: * For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.) * For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column. Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
[{"input": "3 3 1 1", "output": "100\n 010\n 001\n \n\nEvery row contains two 0s and one 1, so the first condition is satisfied.\nAlso, every column contains two 0s and one 1, so the second condition is\nsatisfied.\n\n* * *"}, {"input": "1 5 2 0", "output": "01010"}]
If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1. If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format: s_{11}s_{12}\cdots s_{1W} s_{21}s_{22}\cdots s_{2W} \vdots s_{H1}s_{H2}\cdots s_{HW} Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid. If multiple solutions exist, printing any of them will be accepted. * * *
s091856545
Wrong Answer
p02903
Input is given from Standard Input in the following format: H W A B
HWAB = list(map(int, input().split())) matrix = [[0] * HWAB[1] for i in range(HWAB[0])] count = [0] * HWAB[1] # print(matrix) judge = True if HWAB[2] == 0 and HWAB[3] == 0: jiji = 0 elif HWAB[3] == 0: for b in range(HWAB[0]): countW = 0 for z in range(HWAB[1]): if countW < HWAB[2]: matrix[b][z] = 1 countW += 1 if countW != HWAB[2]: judge = False break elif HWAB[2] == 0: for b in range(HWAB[0]): for z in range(HWAB[1]): if count[z] < HWAB[3]: matrix[b][z] = 1 count[z] += 1 else: # たて for b in range(HWAB[0]): countW = 0 # よこ for z in range(HWAB[1]): if count[z] < HWAB[3] and countW < HWAB[2]: matrix[b][z] = 1 count[z] += 1 countW += 1 if countW != HWAB[2]: judge = False break if judge: for i in range(HWAB[0]): for z in range(HWAB[1]): print(matrix[i][z], end="") print("") else: print("No")
Statement We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied: * For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.) * For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column. Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
[{"input": "3 3 1 1", "output": "100\n 010\n 001\n \n\nEvery row contains two 0s and one 1, so the first condition is satisfied.\nAlso, every column contains two 0s and one 1, so the second condition is\nsatisfied.\n\n* * *"}, {"input": "1 5 2 0", "output": "01010"}]
Print the maximum possible number of i such that a_i=X. * * *
s702190195
Accepted
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
from sys import stdin import collections lines = stdin.readlines() n = int(lines[0]) a_s = [int(x) for x in lines[1].rstrip().split()] def inc(x): return x + 1 def dec(x): return x - 1 a_s_p = [inc(x) for x in a_s] a_s_n = [dec(x) for x in a_s] a_s = a_s + a_s_p + a_s_n c = collections.Counter(a_s) print(max(list(c.values())))
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s226411056
Accepted
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
from collections import Counter N = int(input()) alist = Counter(tuple(map(int, input().split()))) max_counter = 0 com = alist.most_common() for num, cou in com: counter = 0 counter += cou counter += alist[num - 1] counter += alist[num + 1] if counter > max_counter: max_counter = counter print(max_counter)
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s957339298
Accepted
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list(map(lambda x: x - 1, MII())) ## dp ## def DD2(d1, d2, init=0): return [[init] * d2 for _ in range(d1)] def DD3(d1, d2, d3, init=0): return [DD2(d2, d3, init) for _ in range(d1)] ## math ## def to_bin(x: int) -> str: return format(x, "b") # rev => int(res, 2) def to_oct(x: int) -> str: return format(x, "o") # rev => int(res, 8) def to_hex(x: int) -> str: return format(x, "x") # rev => int(res, 16) MOD = 10**9 + 7 def divc(x, y) -> int: return -(-x // y) def divf(x, y) -> int: return x // y def gcd(x, y): while y: x, y = y, x % y return x def lcm(x, y): return x * y // gcd(x, y) def enumerate_divs(n): """Return a tuple list of divisor of n""" return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0] def get_primes(MAX_NUM=10**3): """Return a list of prime numbers n or less""" is_prime = [True] * (MAX_NUM + 1) is_prime[0] = is_prime[1] = False for i in range(2, int(MAX_NUM**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, MAX_NUM + 1, i): is_prime[j] = False return [i for i in range(MAX_NUM + 1) if is_prime[i]] def prime_factor(n): """Return a list of prime factorization numbers of n""" res = [] for i in range(2, int(n**0.5) + 1): while n % i == 0: res.append(i) n //= i if n != 1: res.append(n) return res ## libs ## from itertools import ( accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup, ) from collections import deque, Counter from heapq import heapify, heappop, heappush from bisect import bisect_left # ======================================================# def main(): n = II() aa = MII() x = {i: 0 for i in range(-1, 10**5 + 2)} for a in aa: x[a - 1] += 1 x[a] += 1 x[a + 1] += 1 print(max(x.values())) if __name__ == "__main__": main()
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s482559245
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
N = int(input()) A = list(map(int, input().split())) d = {} for a in A: for i in range(a - 1, a + 2) d[i] = d.get(i, 0) + 1 x = sorted(d.values()) print(max(x))
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s960720724
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
n = int(input()) a = list(map(int, input().split())) ary = [0 for _ in range(10**5)] ​ for i in range(n): if a[i] > 1: ary[a[i]-2] += 1 ary[a[i]-1] += 1 ary[a[i]] += 1 ​ print(max(ary))
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s268081832
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
n = int(input()) a= list(input().split()) al = list([int(i) for i in a]) aset = set([int(i) for i in a]) cnt=0 for i in aset: #print(i) #print(al.count(i-1),al.count(i),al.count(i+1)) if cnt < al.count(i-1) + al.count(i) + al.count(i+1): cnt = al.count(i-1) + al.count(i) + al.count(i+1) if cnt >= len(al) / 2 break print(cnt)
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s204745269
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
your code goes here n=int(input()) a=[int(i) for i in input().split()] a.sort() i=0 x=0 j=0 k=0 while j<len(a) and a[j]-a[i]<1: j+=1 k=j+1 while k<len(a) and a[k]-a[j]<1: k+=1 if k<len(a): if x<k-i: x=k-i i=j j=k k=j print(x)
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s914765011
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
// 入力マクロ // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; } fn main() { input! { n: usize, a: [usize; n] } let mut count = vec![0; 100_002]; for i in a { count[i] += 1; count[i+1] += 1; count[i+ 2] += 1; } let ans = count.iter().max().unwrap(); println!("{}", ans); }
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s618801681
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
!/usr/bin/env python3 n = int(input()) a = list(map(int, input().split())) if n == 1: print(1) exit(0) if n == 2: if abs(a[0]-a[1]) <= 2: print(2) else: print(1) exit(0) if n >= 3: d = [0 for _ in range(100001)] for i in range(n): d[a[i]] += 1 ans = 0 for i in range(n-2): tmp = d[i] + d[i+1] + d[i+2] if ans <= tmp: ans = tmp print(ans)
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s476692477
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
N=int(input()) a=list(map(int,input().split())) l=sorted(a) # N=10 # l=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] if N>=10**3: math. ans=1 for i in range(N): if i>=1 and l[i]==l[i-1]: continue else: t=l[i] for j in range(N-i): c=l[i+j] if abs(c-t)<=2: continue else: _ans=j if _ans>ans: ans=_ans else: pass break print(ans)
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s162337225
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
import numpy as np N = int(input()) a_s = input().split() for i in range(N): a_s[i] = int(a_s[i]) a_s = np.array(a_s) a_unique = np.unique(a_s) # a_counts = [] # for i,a in enumerate(a_unique): # a_counts.append(np.sum(a_s==a)) # a_counts = np.array(a_counts) ans = 0 for i in range(len(a_unique)): val = np.sum(a_s==a_unique[i] #a_counts[i] if (i>0): if (a_unique[i-1]+1==a_unique[i]): val += np.sum(a_s==a_unique[i-1]) #a_counts[i-1] if (i<len(a_unique)-1): if (a_unique[i+1]-1==a_unique[i]): val += np.sum(a_s==a_unique[i+1]) #a_counts[i+1] if val > ans: ans = val # if ans >= sum(a_counts[i:]): # break print(ans)
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s221936651
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
def myAnswer(N:int,A:list) -> int: if(N == 1): return 1 dic ={} for a in A: if(a == 0): for i in range(2): if(i in dic.keys()): dic[i]+=1 else: dic[i]=1 else: for i in range(a-1,a+2): if(i in dic.keys()): dic[i]+=1 else: dic[i] = 1 return max(list(dic.values())) def modelAnswer(): return def main(): N = int(input()) A = list(map(int,input().split())) print(myAnswer(N,A[:])) if __name__ =
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s569602759
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
iimport collections n=int(input()) l=list(map(int,input().split())) s=collections.Counter(l) s=list(s.items()) s=sorted(s,key=lambda x:x[0]) #print(s) f=[0]*len(s) for i in range(len(s)): f[i]=s[i][1] if i>=1: if s[i-1][0]==s[i][0]-1: f[i]+=s[i-1][1] if i<=len(s)-2: if s[i+1][0]==s[i][0]+1: f[i]+=s[i+1][1] print(max(f))
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s244070574
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
C = [0] * 100002 for i in map(int, input().split()): C[i - 1], C[i], C[i + 1] += 1 print(max(C))
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s208217966
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
c=[0]*114514;input();for i in map(int,input().split()):; c[i]+=1;print(max([sum(c[i:i+3]) for i in range(100000)]))
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s036971372
Wrong Answer
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
n = int(input()) A = [0] * (10**5 + 1) for i in input().split(): i = int(i) A[i] += 1 A[i - 1] += 1 A[i + 1] += 1 print(max(A))
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s930674504
Accepted
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
from collections import Counter c = Counter() N = int(input()) for x in input().split(): c[int(x)] += 1 A_uniq = sorted(c.keys()) def gen_candiate(seq): s = set() for n in seq: s.add(n - 1) s.add(n) s.add(n + 1) return sorted(s) # print(gen_candiate(A_uniq)) result = 0 for n in gen_candiate(A_uniq): tmp = c.get(n - 1, 0) + c.get(n, 0) + c.get(n + 1, 0) if tmp > result: result = tmp print(result)
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s025485368
Accepted
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
t = eval(input()) l = list(map(int, input().split())) L = [0 for i in range(1000000 + 3)] for i in range(t): L[l[i]] += 1 L[l[i] + 1] += 1 L[l[i] - 1] += 1 print(max(L))
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s692460681
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
n=int(input()) a= list(map(int,input().split())) #for i in a: #i=0 b=[0]*(max(a)+2) r=0 #while i<=n: for i in a: b[i]+=1 b[i+1]+=1 b[i+2]+=1 print(max(b)-1) A=a.count(a[i]+1) M=a.count(a[i]) C=a.count(a[i]-1) b[i]=A+M+C i=0 def dfs(i,j): max(dfs(i+1,j),dfs(i,j+1)) print(max(b))
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s403934222
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
from sys import stdin from collections import Counter if __name__ == "__main__": _in = [_.rstrip() for _ in stdin.readlines()] N = int(_in[0]) # type:int a_arr = list(map(int,_in[1].split(' '))) # type:list(int) # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv count = Counter(a_arr) cnt = 0 keys = sorted(count.keys()) for key in keys: _ = count[key] try: _ += count[key+1] try: _ += count[key-1] cnt = max(cnt,_) # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ print(cnt)
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s690937104
Accepted
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
def main(): N = int(input()) a = list(map(int, input().split())) num_dict = {} a.sort() a_max = a[N - 1] temp = a[0] sum = 1 for i in range(1, N): if temp == a[i]: sum += 1 else: num_dict[temp] = sum sum = 1 temp = a[i] num_dict[a[N - 1]] = sum ans = 0 judge = 0 for j in range(1, a_max): # j=1のときは特別 if j == 1 and j in num_dict: if j + 1 in num_dict: judge = num_dict[j] + num_dict[j + 1] ans = judge continue else: judge = num_dict[j] ans = judge continue if (j in num_dict) and (j - 1 in num_dict) and (j + 1 in num_dict): if judge <= (num_dict[j - 1] + num_dict[j] + num_dict[j + 1]): judge = num_dict[j - 1] + num_dict[j] + num_dict[j + 1] ans = judge continue else: continue elif (j in num_dict) and (j - 1 in num_dict): if judge <= (num_dict[j - 1] + num_dict[j]): judge = num_dict[j - 1] + num_dict[j] ans = judge continue else: continue elif (j in num_dict) and (j + 1 in num_dict): if judge <= (num_dict[j + 1] + num_dict[j]): judge = num_dict[j + 1] + num_dict[j] ans = judge continue else: continue elif (j - 1 in num_dict) and (j + 1 in num_dict): if judge <= (num_dict[j + 1] + num_dict[j - 1]): judge = num_dict[j + 1] + num_dict[j - 1] ans = judge continue else: continue elif j in num_dict: if judge <= (num_dict[j]): judge = num_dict[j] ans = judge continue else: continue else: continue if a_max - 1 in num_dict: if judge <= num_dict[a_max - 1] + num_dict[a_max]: ans = num_dict[a_max - 1] + num_dict[a_max] else: if judge <= num_dict[a_max]: ans = num_dict[a_max] return ans print(main())
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s980360407
Accepted
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
n = int(input()) l = list(map(int, input().split())) l.sort() lcount = [] count = 0 now = l[0] for i in range(n): if now == l[i]: count += 1 else: lcount.append([count, now]) count = 1 now = l[i] lcount.append([count, now]) if len(lcount) == 1: print(n) elif len(lcount) == 2: l1 = lcount[0][0] l2 = lcount[1][0] if lcount[1][1] - lcount[0][1] == 1: print(l1 + l2) else: print(max(l1, l2)) else: count = 0 for i in range(1, len(lcount) - 1): scount = 0 scount += lcount[i][0] if lcount[i][1] - lcount[i - 1][1] == 1: scount += lcount[i - 1][0] if lcount[i][1] - lcount[i + 1][1] == -1: scount += lcount[i + 1][0] if scount > count: count = scount count1 = lcount[0][0] if lcount[1][1] - lcount[0][1] == 1: count1 += lcount[1][0] count2 = lcount[-1][0] if lcount[-2][1] - lcount[-1][1] == -1: count2 += lcount[-2][0] print(max(count, count1, count2))
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s560437052
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
n = int(input()) alis = list(map(int, input().split())) xlis = set(alis) for al in alis: alis.add(al - 1) alis.add(al + 1) counter = [0 for _ in range(n)] for x in xlis: for i in range(n): if x - 1 <= alis[i] <= x + 1: counter[i] += 1 print(max(counter))
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s137348479
Accepted
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n): l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n): l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n): l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n): l[i] = SR() return l mod = 1000000007 # A # B # C n = I() d = defaultdict(int) a = LI() for i in a: d[i] += 1 d[i + 1] += 1 d[i - 1] += 1 d = list(d.values()) print(max(d)) # D # E # F # G # H # I # J # K # L # M # N # O # P # Q # R # S # T
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s565332515
Wrong Answer
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) def read_tuple(H): """ H is number of rows """ ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret def read_col(H): """ H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合 """ ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) def read_matrix(H): """ H is number of rows """ ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right N = read_a_int() A = read_ints() # どの数字を一番多くできるか n_X = [0] * (10**5 + 1) # =Xにできる個数 for a in A: for da in [-1, 0, 1]: n_X[a + da] += 1 print(max(n_X)) # https://atcoder.jp/contests/abc072/tasks/arc082_a
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s430007609
Accepted
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
n = int(input()) a = map(int, input().split()) c = [0] * (10**5 + 2) for n in a: c[n - 1] += 1 c[n] += 1 c[n + 1] += 1 print(max(c))
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the maximum possible number of i such that a_i=X. * * *
s478473762
Runtime Error
p03611
The input is given from Standard Input in the following format: N a_1 a_2 .. a_N
N = int(input()) s1 = input() s1 = [int(n) for n in s1.split()] s1 = s1[:N] dict = {} for n in range(max(s1)): count = 0 for val in s1: if val in [n, n + 1, n + 2]: count += 1 dict.update({n + 1: count}) print(sorted(dict.values())[-1])
Statement You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
[{"input": "7\n 3 1 4 1 5 9 2", "output": "4\n \n\nFor example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4,\nthe maximum possible count.\n\n* * *"}, {"input": "10\n 0 1 2 3 4 5 6 7 8 9", "output": "3\n \n\n* * *"}, {"input": "1\n 99999", "output": "1"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s004296968
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
n, m, d = map(int, input().split()) p = 1 / n if d == 0 else p = 2 * (n - d) / n / n ans = (m - 1) * p print(ans)
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s466051901
Wrong Answer
p03304
Input is given from Standard Input in the following format: n m d
a, b, c = map(int, input().split()) print(((a - c) * (b - 1)) / (a * a))
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s622921566
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
h, w = map(int, input().split()) maze = [list(input()) for _ in range(h)] group = [[0] * w for _ in range(h)] group_no = 0 color_cnt = [] for y in range(h): for x in range(w): if group[y][x] == 0: stack = [(y, x)] group_no += 1 color_cnt_tmp = [0, 0] while len(stack) > 0: tmp = stack.pop() group[tmp[0]][tmp[1]] = group_no print(tmp) if maze[tmp[0]][tmp[1]] == "#": color_cnt_tmp[0] += 1 else: color_cnt_tmp[1] += 1 for ny, nx in [(0, 1), (1, 0), (-1, 0), (0, -1)]: my = ny + tmp[0] mx = nx + tmp[1] if 0 <= my < h and 0 <= mx < w: if group[my][mx] == 0: if maze[tmp[0]][tmp[1]] != maze[my][mx]: stack.append((my, mx)) group[my][mx] = group_no color_cnt.append(color_cnt_tmp) ans = 0 for b, w in color_cnt: ans += b * w print(ans)
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s586112205
Wrong Answer
p03304
Input is given from Standard Input in the following format: n m d
n, m, _ = list(map(int, input().split())) print(m - 1 / n)
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s617462078
Wrong Answer
p03304
Input is given from Standard Input in the following format: n m d
n, m, d = (int(i) for i in input().split(" ")) print((2 * (n - d) * (n ** (m - 2)) * (m - 1)) / (n**m))
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s812578776
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
print((m - 1) / n)
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s724849461
Accepted
p03304
Input is given from Standard Input in the following format: n m d
def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(" "))) def solve(): """ 1...n 1 - 1+d 2 - 2+d ....... n-d n (n-d)*2*n^(m-2)*(m-1) / n^m (n-d)*2*(m-1) / n^2 """ n, m, d = read_ints() if d == 0: return (n - d) * (m - 1) / (n * n) return (n - d) * 2 * (m - 1) / (n * n) if __name__ == "__main__": print(solve())
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s925570767
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
n, m, d = map(int, input().split()) A = [0] * n for i in range(1, m): B = A A = [0] * n for j in range(n): for k in range(n): if k + 1 - d >= 0 and k + 1 + d <= n: A[j] = B[j] + 2 elif k + 1 - d >= 0 and k + 1 + d > n: A[j] = B[j] + 1 elif k + 1 - d < 0 and k + 1 + d <= n: A[j] = B[j] + 1 if k + 1 - d >= 0 and k + 1 + d <= n: A[j] += 2 elif k + 1 - d >= 0 and k + 1 + d > n: A[j] += 1 elif k + 1 - d < 0 and k + 1 + d <= n: A[j] += 1 print(sum(A) / (n**m))
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s623545072
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
n, m, d = list(map(int, input().split())) if (d == 0): ans = (m - 1) * (1 / n) print(ans) else: ans = (m - 1) * (2 * (n - d) / n ** 2) print(ans)
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s374204814
Wrong Answer
p03304
Input is given from Standard Input in the following format: n m d
n, m, j = map(int, input().split()) print((j + 1) / (n / m))
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s770367577
Accepted
p03304
Input is given from Standard Input in the following format: n m d
N, M, d = [int(_) for _ in input().split()] t = 0 from itertools import product def calc0(N, M, d): E = list(range(N)) t = 0 for xs in product(*([E] * M)): r = sum(abs(xs[i] - xs[i + 1]) == d for i in range(M - 1)) t += r return t, N**M, t / N**M def calc(N, M, d): if d == 0: k = N else: k = (N - d) * 2 # r = k * N**(M - 2) * (M - 1) / (N**M) r = k * (M - 1) / N**2 return r # print(calc(N, 2, d)) # print(calc(N, 3, d)) print(calc(N, M, d))
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s355212484
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
n, m, d = list(map(int, input().split())) if (d == 0): ans = 1 / n print(ans) else: ans = 2 * (n - d) / n ** 2 print(ans)
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s981012547
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
n,m,d = map(int,input().split()) """ #kuso code start = time.time() a = [random.randrange(n) for i in range(m)] a = np.array(a) b = np.abs(a[1:]-a[:-1]) cnt = np.sum(b == d) ave = cnt i = 0 while(time.time() - start < 10): a = [random.randrange(n) for i in range(m)] a = np.array(a) b = np.abs(a[1:]-a[:-1]) cnt = np.sum(b == d) ave = ((i+1)*ave + cnt)/(i+2) i += 1 print(ave) """ oks*n = 2*np.max(n-2*d,0) + 2*d) ave = oks*(m-1)/n/n print(ave)
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s397454094
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
def main(): t = input().split(" ") n, m, d = int(t[0]), int(t[1]), int(t[2]) if d == 0: r = (m-1) / n elif d > n: r = 0 else: r = 2 * (n-d) * (m-1) / n / n print(r) main()
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s026338451
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
n,m,d=map(int,input().split()) #全パターンの平均を求める=期待値を求めれば良い #ある隣り合う数(a,b)の組について、全パターンはn^2 #d=0の時、隣り合う数の組は(a,a)でなければならない if d=0: C=n #d≠0の時、隣り合う組のパターンは(1,1+d),(2,2+d)...(n-d,n)のn-d通り #逆に(d+1,1)....の時も成り立つ if d!=0: C=2*(n-d) #上の組のパターンがm-1個の組について成り立つ print((m-1)*C//n**2)
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s524350349
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
#include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <string> #include <vector> #include <complex> #include <cstdlib> #include <cstring> #include <numeric> #include <sstream> #include <iostream> #include <algorithm> #include <functional> #include <unordered_map> #include <random> #include <iomanip> #define mp make_pair #define pb push_back #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef pair<int,int> pii; const int INF=1<<29; const double EPS=1e-9; const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1}; int main() { ll N, M, D; cin >> N >> M >> D; double p; if (D == 0) { p = 1.0 / N; } else { p = (2.0 * (N - D)) / (N * N); } cout << fixed << setprecision(10) << p * (M - 1) << endl; return 0; }
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s725192463
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
import numpy as np n,m,d = map(int,input().split()) """ #kuso code start = time.time() a = [random.randrange(n) for i in range(m)] a = np.array(a) b = np.abs(a[1:]-a[:-1]) cnt = np.sum(b == d) ave = cnt i = 0 while(time.time() - start < 10): a = [random.randrange(n) for i in range(m)] a = np.array(a) b = np.abs(a[1:]-a[:-1]) cnt = np.sum(b == d) ave = ((i+1)*ave + cnt)/(i+2) i += 1 print(ave) """ oks*n = 2*np.max(n-2*d,0) + 2*d) ave = oks*(m-1)/n/n print(ave)
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s321764135
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
//----------------------------おまじない #pragma GCC optimize ("O3") #pragma GCC target ("tune=native") #pragma GCC target ("avx") //---------------------------- #define FOR(i,j,n) for (int i=(j);i<(n);i++) #define REP(i,n) for (int i=0;i<(n);i++) #define REPN(i,n) for (int i=(n);i>0;i--) #define I(n) scanf("%d", &(n)) #define LL(n) scanf("%lld", &(n)) #define pb(n) push_back((n)) #define mp(i,j) make_pair((i),(j)) #define eb(i,j) emplace_back((i),(j)) #include <bits/stdc++.h> using namespace std; //------------------------------typedef集 typedef vector<int> vi; typedef pair<int,int> pi; typedef vector<pi> vpi; typedef vector<vi> vvi; typedef vector<vpi> vvpi; typedef vector<vvi> vvvi; typedef long long ll; const int mod = 1000000009; ll n,d,m,posi; double res; int main(){ cin >> n >> m >> d; m--; posi = (n-d); if (d) posi *= 2; cerr << posi << endl; res = posi; res = res/n/n*m; printf("%.11f\n",res); }
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n. The output will be judged correct if the absolute or relative error is at most 10^{-6}. * * *
s984968279
Runtime Error
p03304
Input is given from Standard Input in the following format: n m d
import numpy as np n,m,d = map(int,input().split()) """ #kuso code start = time.time() a = [random.randrange(n) for i in range(m)] a = np.array(a) b = np.abs(a[1:]-a[:-1]) cnt = np.sum(b == d) ave = cnt i = 0 while(time.time() - start < 10): a = [random.randrange(n) for i in range(m)] a = np.array(a) b = np.abs(a[1:]-a[:-1]) cnt = np.sum(b == d) ave = ((i+1)*ave + cnt)/(i+2) i += 1 print(ave) """ oks_times_n = 2*np.max(n-2*d,0) + 2*d) ave = oks*(m-1)/n/n print(ave)
Statement Let us define the _beauty_ of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d. For example, when d=1, the beauty of the sequence (3, 2, 3, 10, 9) is 3. There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values.
[{"input": "2 3 1", "output": "1.0000000000\n \n\nThe beauty of (1,1,1) is 0. \nThe beauty of (1,1,2) is 1. \nThe beauty of (1,2,1) is 2. \nThe beauty of (1,2,2) is 1. \nThe beauty of (2,1,1) is 1. \nThe beauty of (2,1,2) is 2. \nThe beauty of (2,2,1) is 1. \nThe beauty of (2,2,2) is 0. \nThe answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1.\n\n* * *"}, {"input": "1000000000 180707 0", "output": "0.0001807060"}]
Calculate how many numbers her alien friends can count with the fingers. Print the answer modulo 1000000007 in a line.
s025118805
Runtime Error
p01339
_N M_ _S_ 1 _D_ 1 _S_ 2 _D_ 2 . . . _S_ _M_ _D_ _M_ The first line contains two integers _N_ and _M_ (1 ≤ _N_ ≤ 1000, 0 ≤ _M_ ≤ 1000) in this order. The following _M_ lines mean bend rules. Each line contains two integers _S i_ and _D i_ in this order, which mean that the finger _D i_ always bends when the finger _S i_ bends. Any finger appears at most once in _S_.
def combi(n): if n == 1: return [[1], [0]] else: s = combi(n - 1) ret = [[t] + x for x in s for t in [1, 0]] return ret N, M = map(int, input().split()) whole = combi(N) for i in range(M): select = [] s, d = map(int, input().split()) for c in whole: if c[s - 1] == 1 and c[d - 1] == 0: select.append(c) for c in select: whole.remove(c) print(len(whole))
A: Alien's Counting Natsuki and her friends were taken to the space by an alien and made friends with a lot of aliens. During the space travel, she discovered that aliens’ hands were often very different from humans’. Generally speaking, in a kind of aliens, there are _N_ fingers and _M_ bend rules on a hand. Each bend rule describes that a finger A always bends when a finger B bends. However, this rule does not always imply that the finger B bends when the finger A bends. When she were counting numbers with the fingers, she was anxious how many numbers her alien friends can count with the fingers. However, because some friends had too complicated rule sets, she could not calculate those. Would you write a program for her?
[{"input": "5 4\n 2 3\n 3 4\n 4 3\n 5 4", "output": "10"}, {"input": "5 5\n 1 2\n 2 3\n 3 4\n 4 5\n 5 1", "output": "2"}, {"input": "5 0", "output": "32"}]
Print the number of times Takahashi and Aoki will meet each other. If they meet infinitely many times, print `infinity` instead. * * *
s732679391
Wrong Answer
p02846
Input is given from Standard Input in the following format: T_1 T_2 A_1 A_2 B_1 B_2
def main(): t1, t2 = map(int, input().split(" ")) a1, a2 = map(int, input().split(" ")) b1, b2 = map(int, input().split(" ")) dist1 = a1 * t1 + a2 * t2 dist2 = b1 * t1 + b2 * t2 if dist1 == dist2: return "infinity" elif a1 == b1: return "infinity" elif a2 == b2: return 0 elif (a1 < b1 and a2 < b2) or (b1 < a1 and b2 < a2): return 0 if dist1 > dist2: a = a1 * t1 b = a2 * t2 c = b1 * t1 d = b2 * t2 else: a = b1 * t1 b = b2 * t2 c = a1 * t1 d = a2 * t2 m = (c - a) // (a + b - c - d) out = 2 * m + 1 return out out = main() print(out)
Statement Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as follows **towards the east** : * Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever. * Aoki runs B_1 meters per minute for the first T_1 minutes, then runs at B_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever. How many times will Takahashi and Aoki meet each other, that is, come to the same point? We do not count the start of the run. If they meet infinitely many times, report that fact.
[{"input": "1 2\n 10 10\n 12 4", "output": "1\n \n\nThey will meet just once, \\frac{4}{3} minutes after they start, at\n\\frac{40}{3} meters from where they start.\n\n* * *"}, {"input": "100 1\n 101 101\n 102 1", "output": "infinity\n \n\nThey will meet 101, 202, 303, 404, 505, 606, ... minutes after they start,\nthat is, they will meet infinitely many times.\n\n* * *"}, {"input": "12000 15700\n 3390000000 3810000000\n 5550000000 2130000000", "output": "113\n \n\nThe values in input may not fit into a 32-bit integer type."}]
In i-th (1 ≤ i ≤ N) line, print the expected vaule of the number of turns E869120 moves. The relative error or absolute error of output should be within 10^{-6}.
s851242753
Wrong Answer
p03754
The input is given from standard input in the following format. N u_1 v_1 u_2 v_2 : u_{N-1} v_{N-1}
print(float(3))
Statement There is an undirected connected graph with $N$ vertices and $N-1$ edges. The i-th edge connects u_i and v_i. E869120 the coder moves in the graph as follows: * He move to adjacent vertex, but he can't a visit vertex two or more times. * He ends move when there is no way to move. * Otherwise, he moves randomly. (equal probability) If he has $p$ way to move this turn, he choose each vertex with $1/p$ probability. ![](https://atcoder.jp/img/s8pc-4/5973dad11843e9098d9225dd431c9084.png) Calculate the expected value of the number of turns, when E869120 starts from vertex i, for all i (1 ≤ i ≤ N).
[{"input": "4\n 1 2\n 2 3\n 2 4", "output": "2.0\n 1.0\n 2.0\n 2.0"}]
In i-th (1 ≤ i ≤ N) line, print the expected vaule of the number of turns E869120 moves. The relative error or absolute error of output should be within 10^{-6}.
s423946339
Wrong Answer
p03754
The input is given from standard input in the following format. N u_1 v_1 u_2 v_2 : u_{N-1} v_{N-1}
class Tree: def __init__(self, n, edge): self.n = n self.tree = [[] for _ in range(n)] for e in edge: self.tree[e[0] - 1].append(e[1] - 1) self.tree[e[1] - 1].append(e[0] - 1) def setroot(self, root): self.root = root self.parent = [None for _ in range(self.n)] self.parent[root] = -1 self.depth = [None for _ in range(self.n)] self.depth[root] = 0 self.order = [] self.order.append(root) stack = [root] while stack: node = stack.pop() for adj in self.tree[node]: if self.parent[adj] is None: self.parent[adj] = node self.depth[adj] = self.depth[node] + 1 self.order.append(adj) stack.append(adj) def rerooting(self, func, merge, ti, ei): dp = [ti for _ in range(self.n)] lt = [ei for _ in range(self.n)] rt = [ei for _ in range(self.n)] inv = [ei for _ in range(self.n)] self.setroot(0) for node in self.order[::-1]: tmp = ti for adj in self.tree[node]: if self.parent[adj] == node: lt[adj] = tmp tmp = func(tmp, dp[adj]) tmp = ti for adj in self.tree[node][::-1]: if self.parent[adj] == node: rt[adj] = tmp tmp = func(tmp, dp[adj]) dp[node] = tmp for node in self.order: if node == 0: continue merged = merge(lt[node], rt[node]) par = self.parent[node] inv[node] = func(merged, inv[par]) dp[node] = func(dp[node], inv[node]) return dp import sys input = sys.stdin.readline N = int(input()) E = [tuple(map(int, input().split())) for _ in range(N - 1)] T = Tree(N, E) def func(node, adj): size = node[1] + 1 exp = (node[0] * node[1] + adj[0] + 1) / size if size else 0 return exp, size def merge(lt, rt): size = lt[1] + rt[1] exp = (lt[0] * lt[1] + rt[0] * rt[1]) / size if size else 0 return exp, size ti = (0, 0) ei = (-1, 0) D = T.rerooting(func, merge, ti, ei) res = [] for i in range(N): res.append(D[i][0]) print("\n".join(map(str, res)))
Statement There is an undirected connected graph with $N$ vertices and $N-1$ edges. The i-th edge connects u_i and v_i. E869120 the coder moves in the graph as follows: * He move to adjacent vertex, but he can't a visit vertex two or more times. * He ends move when there is no way to move. * Otherwise, he moves randomly. (equal probability) If he has $p$ way to move this turn, he choose each vertex with $1/p$ probability. ![](https://atcoder.jp/img/s8pc-4/5973dad11843e9098d9225dd431c9084.png) Calculate the expected value of the number of turns, when E869120 starts from vertex i, for all i (1 ≤ i ≤ N).
[{"input": "4\n 1 2\n 2 3\n 2 4", "output": "2.0\n 1.0\n 2.0\n 2.0"}]
For given two integers a and b, print a < b if a is less than b, a > b if a is greater than b, and a == b if a equals to b.
s375564230
Accepted
p02391
Two integers a and b separated by a single space are given in a line.
a,b = map(int, input().split()) sign = '<' if a < b else '==' if a == b else '>' print(f'a {sign} b')
Small, Large, or Equal Write a program which prints small/large/equal relation of given two integers a and b.
[{"input": "1 2", "output": "a < b"}, {"input": "4 3", "output": "a > b"}, {"input": "5 5", "output": "a == b"}]
For given two integers a and b, print a < b if a is less than b, a > b if a is greater than b, and a == b if a equals to b.
s023430363
Accepted
p02391
Two integers a and b separated by a single space are given in a line.
in_str = input() tmp_list = in_str.split() a = int(tmp_list[0]) b = int(tmp_list[1]) if abs(a) <= 1000 and abs(b) <= 1000: print("a == b" if a == b else "a > b" if a > b else "a < b")
Small, Large, or Equal Write a program which prints small/large/equal relation of given two integers a and b.
[{"input": "1 2", "output": "a < b"}, {"input": "4 3", "output": "a > b"}, {"input": "5 5", "output": "a == b"}]
For given two integers a and b, print a < b if a is less than b, a > b if a is greater than b, and a == b if a equals to b.
s966256182
Wrong Answer
p02391
Two integers a and b separated by a single space are given in a line.
input_data = [int(i) for i in input().split()] if input_data[0] > input_data[1]: print(input_data[0], ">", input_data[1]) elif input_data[0] < input_data[1]: print(input_data[0], "<", input_data[1]) else: print(input_data[0], "==", input_data[1])
Small, Large, or Equal Write a program which prints small/large/equal relation of given two integers a and b.
[{"input": "1 2", "output": "a < b"}, {"input": "4 3", "output": "a > b"}, {"input": "5 5", "output": "a == b"}]
For given two integers a and b, print a < b if a is less than b, a > b if a is greater than b, and a == b if a equals to b.
s007210267
Wrong Answer
p02391
Two integers a and b separated by a single space are given in a line.
a = input().split() if int(a[0]) > int(a[1]): print(str(a[0]) + " > " + str(a[1])) if int(a[0]) < int(a[1]): print(str(a[0]) + " < " + str(a[1])) if int(a[0]) == int(a[1]): print(str(a[0]) + " == " + str(a[1]))
Small, Large, or Equal Write a program which prints small/large/equal relation of given two integers a and b.
[{"input": "1 2", "output": "a < b"}, {"input": "4 3", "output": "a > b"}, {"input": "5 5", "output": "a == b"}]
For given two integers a and b, print a < b if a is less than b, a > b if a is greater than b, and a == b if a equals to b.
s583399665
Wrong Answer
p02391
Two integers a and b separated by a single space are given in a line.
a = int() b = int()
Small, Large, or Equal Write a program which prints small/large/equal relation of given two integers a and b.
[{"input": "1 2", "output": "a < b"}, {"input": "4 3", "output": "a > b"}, {"input": "5 5", "output": "a == b"}]
For given two integers a and b, print a < b if a is less than b, a > b if a is greater than b, and a == b if a equals to b.
s952626271
Accepted
p02391
Two integers a and b separated by a single space are given in a line.
ia = [int(i) for i in input().split(" ")] print("a < b" if ia[0] < ia[1] else "a > b" if ia[0] > ia[1] else "a == b")
Small, Large, or Equal Write a program which prints small/large/equal relation of given two integers a and b.
[{"input": "1 2", "output": "a < b"}, {"input": "4 3", "output": "a > b"}, {"input": "5 5", "output": "a == b"}]
For given two integers a and b, print a < b if a is less than b, a > b if a is greater than b, and a == b if a equals to b.
s016893136
Wrong Answer
p02391
Two integers a and b separated by a single space are given in a line.
a = 5 b = 5 a == b
Small, Large, or Equal Write a program which prints small/large/equal relation of given two integers a and b.
[{"input": "1 2", "output": "a < b"}, {"input": "4 3", "output": "a > b"}, {"input": "5 5", "output": "a == b"}]
Print the answer. * * *
s627979263
Runtime Error
p03580
Input is given from Standard Input in the following format: N s
# def makelist(n, m): # return [[0 for i in range(m)] for j in range(n)] N = int(input()) s = input() dp = [] cnt = [0]*2 cnt[int(s[0])] += 1 for i in range(1, N): if i == N-1: else: now = int(s[i]) if cnt[now] > 0: cnt[now] += 1 else: anti = (cnt + 1) % 2 if anti == 0: dp.append(-cnt[anti]) else: dp.append(cnt[anti]) cnt[anti] = 0 cnt[now] = 1 ans = 0 nex = False pre = False for e in dp: if not start and e > 0: start = True else: continue if e > 0: if nex: nex = False pre = True ans += e elif e == -1: if pre: ans -= 1 nex = True else: nex = True pre = False elif e <= -2: pre = False print(ans)
Statement N cells are arranged in a row. Some of them may contain tokens. You are given a string s that consists of `0`s and `1`s. If the i-th character of s is `1`, the i-th cell (from left) contains a token. Otherwise, it doesn't contain a token. Snuke wants to perform the following operation as many times as possible. In each operation, he chooses three consecutive cells. Let's call the cells X, Y, Z from left to right. In order for the operation to be valid, both X and Z must contain tokens and Y must not contain a token. Then, he removes these two tokens and puts a new token on Y. How many operations can he perform if he performs operations in the optimal way?
[{"input": "7\n 1010101", "output": "2\n \n\nFor example, he can perform two operations in the following way:\n\n * Perform an operation on the last three cells. Now the string that represents tokens becomes `1010010`.\n * Perform an operation on the first three cells. Now the string that represents tokens becomes `0100010`.\n\nNote that the choice of operations matters. For example, if he chooses three\ncells in the middle first, he can perform no more operations.\n\n* * *"}, {"input": "50\n 10101000010011011110001001111110000101010111100110", "output": "10"}]
Print the answer. * * *
s289319653
Runtime Error
p03580
Input is given from Standard Input in the following format: N s
# D N = int(input()) s = list(map(int, list(input()))) res = 0 i = 0 L = 0 for i in range(N): if s[i] == 1: L = i break for i in range(N): if s[i] == 1: M = i def calc_add(temp_list): return sum(temp_list) def calc_add_2(temp_list) if len(temp_list) <= 1: return 0 else: res = 0 # use 101 for left dp_l = [0]*len(temp_list) # use 101 for right dp_r = [0]*len(temp_list) # do not use 101 dp_c = [0]*len(temp_list) for i in range(len(temp_list) - 1): if temp_list[i] > 1: dp_l[i+1] = max(dp_l[i] + temp_list[i] - 1, dp_c[i] + temp_list[i]) else: dp_l[i+1] = dp_c[i] + temp_list[i] if temp_list[i] > 1: dp_r[i+1] = max(dp_l[i] + temp_list[i+1], dp_c[i] + temp_list[i+1], dp_r[i] + temp_list[i+1] - 1) else: dp_r[i+1] = dp_c[i] + temp_list[i+1] dp_c[i+1] = max(dp_l[i], dp_r[i], dp_c[i]) return max(dp_l[-1], dp_r[-1], dp_c[-1]) cont0 = 1 cont00 = 1 temp_list = [] for i in range(L, M+1): if s[i] == 1: if cont0 == 1: temp_list.append(1) cont0 = 0 cont00 = 0 else: temp_list[-1] += 1 else: if cont00 == 1: pass elif cont0 == 1: cont00 = 1 res += calc_add(temp_list) temp_list = [] else: cont0 = 1 if i == M: res += calc_add(temp_list) temp_list = [] print(res)
Statement N cells are arranged in a row. Some of them may contain tokens. You are given a string s that consists of `0`s and `1`s. If the i-th character of s is `1`, the i-th cell (from left) contains a token. Otherwise, it doesn't contain a token. Snuke wants to perform the following operation as many times as possible. In each operation, he chooses three consecutive cells. Let's call the cells X, Y, Z from left to right. In order for the operation to be valid, both X and Z must contain tokens and Y must not contain a token. Then, he removes these two tokens and puts a new token on Y. How many operations can he perform if he performs operations in the optimal way?
[{"input": "7\n 1010101", "output": "2\n \n\nFor example, he can perform two operations in the following way:\n\n * Perform an operation on the last three cells. Now the string that represents tokens becomes `1010010`.\n * Perform an operation on the first three cells. Now the string that represents tokens becomes `0100010`.\n\nNote that the choice of operations matters. For example, if he chooses three\ncells in the middle first, he can perform no more operations.\n\n* * *"}, {"input": "50\n 10101000010011011110001001111110000101010111100110", "output": "10"}]
Print the answer. * * *
s941731230
Accepted
p03580
Input is given from Standard Input in the following format: N s
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) S = readline().rstrip().decode("utf-8") def solve_partial(S): INF = 10**18 """ ・Sは1から始まり、1で終わる ・Sは00を含まない ・したがって、Sは1,01に分解可能 ・残る最小個数を調べるdp。これは、1, 101111,111101 の3種を数えることと同じ ・a, b0cccc, dddd0e として、「現在の1がどれであるか -> 最小個数」でdp ・個数はa,b,eのときに数える """ S = S.replace("01", "2") a, b, c, d, e = 1, 1, INF, 0, INF for x in S[1:]: if x == "1": a2 = min(a, c, e) + 1 c2 = c d2 = min(a, c, d, e) e2 = INF else: a2 = min(a, c, e) + 1 c2 = a d2 = min(a, c, e) e2 = d + 1 a, c, d, e = a2, c2, d2, e2 return len(S) - min(a, c, e) answer = 0 for x in S.split("00"): x = x.strip("0") if x: answer += solve_partial(x) print(answer)
Statement N cells are arranged in a row. Some of them may contain tokens. You are given a string s that consists of `0`s and `1`s. If the i-th character of s is `1`, the i-th cell (from left) contains a token. Otherwise, it doesn't contain a token. Snuke wants to perform the following operation as many times as possible. In each operation, he chooses three consecutive cells. Let's call the cells X, Y, Z from left to right. In order for the operation to be valid, both X and Z must contain tokens and Y must not contain a token. Then, he removes these two tokens and puts a new token on Y. How many operations can he perform if he performs operations in the optimal way?
[{"input": "7\n 1010101", "output": "2\n \n\nFor example, he can perform two operations in the following way:\n\n * Perform an operation on the last three cells. Now the string that represents tokens becomes `1010010`.\n * Perform an operation on the first three cells. Now the string that represents tokens becomes `0100010`.\n\nNote that the choice of operations matters. For example, if he chooses three\ncells in the middle first, he can perform no more operations.\n\n* * *"}, {"input": "50\n 10101000010011011110001001111110000101010111100110", "output": "10"}]
Print the answer. * * *
s811837769
Wrong Answer
p03580
Input is given from Standard Input in the following format: N s
n = int(input()) s = input() ss = [] cnt = 0 for c in s: if c == "1": cnt += 1 else: if cnt > 0: ss.append(cnt) cnt = 0 ss.append(cnt) if cnt > 0: ss.append(cnt) def solve(seq): l = len(seq) if not seq: return 0 while seq[-1] == 0: seq.pop() # dp = [0]*(l+1) dp = [[0] * 3 for i in range(l + 1)] # print(seq) for i in range(l): # 0 -> 0, 1 -> 0, 2 -> 0 nxt = max(dp[i]) dp[i + 1][0] = max(dp[i + 1][0], nxt) if i + 1 < l: if seq[i] >= 2: # 0 -> 1 dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + seq[i]) if seq[i] >= 2 and seq[i + 1] >= 2: # 1 -> 1 dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + seq[i] - 1) # 2 -> 1 dp[i + 1][1] = max(dp[i + 1][1], dp[i][2] + 1) # 1 -> 2 dp[i + 1][2] = max(dp[i + 1][2], dp[i][1] + max(seq[i], seq[i + 1]) - 1) # 2 -> 2 dp[i + 1][2] = max(dp[i + 1][2], dp[i][2] + seq[i + 1] - 1) if seq[i + 1] >= 2: # 0 -> 2 dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + max(seq[i], seq[i + 1] - 1)) if i + 2 <= l: dp[i + 2][0] = max(dp[i + 2][0], dp[i][0] + max(seq[i], seq[i + 1])) if seq[i] >= 2: dp[i + 2][0] = max(dp[i + 2][0], dp[i][1] + max(seq[i] - 1, seq[i + 1])) # print(dp[i]) # print(dp[l]) # print("-") return max(max(e) for e in dp) idx = 0 cur = [] ans = 0 while idx < len(ss): if idx + 1 < len(ss) and ss[idx] == ss[idx + 1] == 0: idx += 2 ans += solve(cur) cur = [] elif not cur and ss[idx] == 0: idx += 1 else: if ss[idx]: cur.append(ss[idx]) idx += 1 if cur: ans += solve(cur) print(ans)
Statement N cells are arranged in a row. Some of them may contain tokens. You are given a string s that consists of `0`s and `1`s. If the i-th character of s is `1`, the i-th cell (from left) contains a token. Otherwise, it doesn't contain a token. Snuke wants to perform the following operation as many times as possible. In each operation, he chooses three consecutive cells. Let's call the cells X, Y, Z from left to right. In order for the operation to be valid, both X and Z must contain tokens and Y must not contain a token. Then, he removes these two tokens and puts a new token on Y. How many operations can he perform if he performs operations in the optimal way?
[{"input": "7\n 1010101", "output": "2\n \n\nFor example, he can perform two operations in the following way:\n\n * Perform an operation on the last three cells. Now the string that represents tokens becomes `1010010`.\n * Perform an operation on the first three cells. Now the string that represents tokens becomes `0100010`.\n\nNote that the choice of operations matters. For example, if he chooses three\ncells in the middle first, he can perform no more operations.\n\n* * *"}, {"input": "50\n 10101000010011011110001001111110000101010111100110", "output": "10"}]
Print the answer. * * *
s203782295
Wrong Answer
p03580
Input is given from Standard Input in the following format: N s
# -*- coding: utf-8 -*- from copy import deepcopy import re result = 0 N = int(input()) s = input() + "0" # text = s.replace("10", "a").replace("a0", "100") text = s ts = text.split("00") if len(ts) > 1: for i in range(1, len(ts)): ts[i] = "0" + ts[i] for i in range(len(ts) - 1): ts[i] = ts[i] + "0" for t in ts: tmpa = 0 tmpb = 0 A = (t.replace("10", "a") + "0").replace("a0", "100") B = (t[::-1].replace("10", "a") + "0").replace("a0", "100") typea = re.findall("a1+", A) typeb = re.findall("a1+", B) for a in typea: tmpa += len(a) - 1 tmpa += re.sub("a1+", "d", A).replace("aa", "b").count("b") for b in typeb: tmpb += len(b) - 1 tmpb += re.sub("a1+", "d", B).replace("aa", "b").count("b") result += max(tmpa, tmpb) print(result)
Statement N cells are arranged in a row. Some of them may contain tokens. You are given a string s that consists of `0`s and `1`s. If the i-th character of s is `1`, the i-th cell (from left) contains a token. Otherwise, it doesn't contain a token. Snuke wants to perform the following operation as many times as possible. In each operation, he chooses three consecutive cells. Let's call the cells X, Y, Z from left to right. In order for the operation to be valid, both X and Z must contain tokens and Y must not contain a token. Then, he removes these two tokens and puts a new token on Y. How many operations can he perform if he performs operations in the optimal way?
[{"input": "7\n 1010101", "output": "2\n \n\nFor example, he can perform two operations in the following way:\n\n * Perform an operation on the last three cells. Now the string that represents tokens becomes `1010010`.\n * Perform an operation on the first three cells. Now the string that represents tokens becomes `0100010`.\n\nNote that the choice of operations matters. For example, if he chooses three\ncells in the middle first, he can perform no more operations.\n\n* * *"}, {"input": "50\n 10101000010011011110001001111110000101010111100110", "output": "10"}]
Print the answer. * * *
s006064441
Accepted
p03580
Input is given from Standard Input in the following format: N s
#!/usr/bin/python3 import re n = input() s = input() sb = re.sub(r"^0+", "", s) sb = re.sub(r"0+$", "", sb) sb = re.sub(r"00+", "-", sb) tlist = sb.split("-") counts_list = [] for t in tlist: counts = [] tt = t.split("0") for ttt in tt: counts.append(len(ttt)) counts_list.append(counts) ans = 0 for counts in counts_list: len_counts = len(counts) sum_all = sum_decr = sum_one = sum_zero = 0 for i in range(len_counts - 1): new_sum_all = new_sum_decr = new_sum_one = new_sum_zero = 0 # do nothing new_sum_all = max(sum_all, sum_decr, sum_one, sum_zero) # go to left all new_sum_decr = max(new_sum_decr, sum_all + counts[i]) new_sum_decr = max(new_sum_decr, sum_decr + counts[i] - 1) new_sum_decr = max(new_sum_decr, sum_one + 1) # go to right all - 1 new_sum_one = max(new_sum_one, sum_all + counts[i + 1] - 1) if counts[i] >= 2: new_sum_one = max(new_sum_one, sum_decr + counts[i + 1] - 1) new_sum_one = max(new_sum_one, sum_one + counts[i + 1] - 1) # go to right all new_sum_zero = max(new_sum_zero, sum_all + counts[i + 1]) if counts[i] >= 2: new_sum_zero = max(new_sum_zero, sum_decr + counts[i + 1]) new_sum_zero = max(new_sum_zero, sum_one + counts[i + 1]) sum_all = new_sum_all sum_decr = new_sum_decr sum_one = new_sum_one sum_zero = new_sum_zero ans += max(sum_all, sum_decr, sum_one, sum_zero) print(ans)
Statement N cells are arranged in a row. Some of them may contain tokens. You are given a string s that consists of `0`s and `1`s. If the i-th character of s is `1`, the i-th cell (from left) contains a token. Otherwise, it doesn't contain a token. Snuke wants to perform the following operation as many times as possible. In each operation, he chooses three consecutive cells. Let's call the cells X, Y, Z from left to right. In order for the operation to be valid, both X and Z must contain tokens and Y must not contain a token. Then, he removes these two tokens and puts a new token on Y. How many operations can he perform if he performs operations in the optimal way?
[{"input": "7\n 1010101", "output": "2\n \n\nFor example, he can perform two operations in the following way:\n\n * Perform an operation on the last three cells. Now the string that represents tokens becomes `1010010`.\n * Perform an operation on the first three cells. Now the string that represents tokens becomes `0100010`.\n\nNote that the choice of operations matters. For example, if he chooses three\ncells in the middle first, he can perform no more operations.\n\n* * *"}, {"input": "50\n 10101000010011011110001001111110000101010111100110", "output": "10"}]