output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the minimum possible number of different characters contained in the strings. * * *
s337994443
Runtime Error
p03202
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) arr = list(map(int, input().split())) arr.sort() val = 0 count_now = 0 ans = 1 for i in range(n): if arr[i] != val: val = arr[i] temp = ceil(count_now **(1/float(n))) ans = max(ans, temp) count_now = 0 else count_now += 1 print(ans)
Statement There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i?
[{"input": "3\n 3 2 1", "output": "2\n \n\nThe number of different characters contained in S_1,S_2,...,S_N would be 3\nwhen, for example, S_1=`abc`, S_2=`bb` and S_3=`c`.\n\nHowever, if we choose the strings properly, the number of different characters\ncan be 2.\n\n* * *"}, {"input": "5\n 2 3 2 1 2", "output": "2"}]
Print the minimum possible number of different characters contained in the strings. * * *
s182797481
Runtime Error
p03202
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n=int(input()) a=list(map(int, input().split())) b=[1]*a[0] for i in range(n-1): if(a[i]<a[i+1]): b=b+[1]*(a[i+1]-a[i]) elif(a[i]=a[i+1]): b=[b[0]+1]+[1]*(a[i+1]-1) else: b=b[0:a[i+1]] b[-1]=b[-1]+1 print(b[0])
Statement There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i?
[{"input": "3\n 3 2 1", "output": "2\n \n\nThe number of different characters contained in S_1,S_2,...,S_N would be 3\nwhen, for example, S_1=`abc`, S_2=`bb` and S_3=`c`.\n\nHowever, if we choose the strings properly, the number of different characters\ncan be 2.\n\n* * *"}, {"input": "5\n 2 3 2 1 2", "output": "2"}]
Print the minimum possible number of different characters contained in the strings. * * *
s227562658
Wrong Answer
p03202
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) a = [int(_) for _ in input().split()] ans = 0 for i in range(1, n): if a[i] <= a[i - 1]: ans += 1 print(ans)
Statement There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i?
[{"input": "3\n 3 2 1", "output": "2\n \n\nThe number of different characters contained in S_1,S_2,...,S_N would be 3\nwhen, for example, S_1=`abc`, S_2=`bb` and S_3=`c`.\n\nHowever, if we choose the strings properly, the number of different characters\ncan be 2.\n\n* * *"}, {"input": "5\n 2 3 2 1 2", "output": "2"}]
Print the minimum possible number of different characters contained in the strings. * * *
s537151751
Wrong Answer
p03202
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = input() A = list(map(int, input().strip().split(" "))) counter = 0 tmpcnt = 0 for i in range(len(A) - 1): if A[i + 1] < A[i]: counter += 1 tmpcnt = 0 elif A[i + 1] == A[i]: tmpcnt += 1 if tmpcnt == 2 ** A[i]: counter += 1 tmpcnt = 0 else: tmpcnt = 0 print(counter)
Statement There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i?
[{"input": "3\n 3 2 1", "output": "2\n \n\nThe number of different characters contained in S_1,S_2,...,S_N would be 3\nwhen, for example, S_1=`abc`, S_2=`bb` and S_3=`c`.\n\nHowever, if we choose the strings properly, the number of different characters\ncan be 2.\n\n* * *"}, {"input": "5\n 2 3 2 1 2", "output": "2"}]
Print the minimum possible number of different characters contained in the strings. * * *
s537080562
Wrong Answer
p03202
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) A = [int(a) for a in input().split()] l = 0 r = 2 * 10**5 m = 2 while r - l >= 2: m = l + (r - l) // 2 X = {} for i in range(1, N): try: if A[i] <= A[i - 1]: if A[i] < A[i - 1]: for j in X: if j > A[i]: X[j] = 0 # del X[j] if A[i] in X: X[A[i]] += 1 k = A[i] while k in X and X[k] >= m: X[k] = 0 if k - 1 in X: X[k - 1] += 1 else: X[k - 1] = 1 k -= 1 if k <= 0: raise Exception else: X[A[i]] = 1 except: # print(m, "Err") l = m break # print(i, X) else: # print(m, "OK") r = m # print(A) # print(X) print(r + 1)
Statement There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i?
[{"input": "3\n 3 2 1", "output": "2\n \n\nThe number of different characters contained in S_1,S_2,...,S_N would be 3\nwhen, for example, S_1=`abc`, S_2=`bb` and S_3=`c`.\n\nHowever, if we choose the strings properly, the number of different characters\ncan be 2.\n\n* * *"}, {"input": "5\n 2 3 2 1 2", "output": "2"}]
Print the minimum possible number of different characters contained in the strings. * * *
s071307681
Wrong Answer
p03202
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) A = [int(i) for i in input().split()] a = A[0] t = 1 s = -1 for i in range(1, N): if a >= A[i]: s = i t += 1 break l = [A[s], 1] for i in range(s + 1, N): if l[0] < A[i]: # print(i,t,':',l,A[i]) continue elif l[0] == A[i]: if t ** (l[0]) >= l[1] - 1: t += 1 l[1] = t ** (A[i] - 1) * (t - 1) else: l[1] += 1 print(i, t, ":", l, A[i]) else: a = l[0] b = l[1] x = b // (t ** (a - A[i])) l = [A[i], x] if t ** (l[0]) - 1 == x: t += 1 l[1] = t ** (A[i] - 1) * (t - 1) else: l[1] += 1 print(t)
Statement There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i?
[{"input": "3\n 3 2 1", "output": "2\n \n\nThe number of different characters contained in S_1,S_2,...,S_N would be 3\nwhen, for example, S_1=`abc`, S_2=`bb` and S_3=`c`.\n\nHowever, if we choose the strings properly, the number of different characters\ncan be 2.\n\n* * *"}, {"input": "5\n 2 3 2 1 2", "output": "2"}]
Print the minimum possible number of different characters contained in the strings. * * *
s530394448
Runtime Error
p03202
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# -*- coding: utf-8 -*- from sys import stdin def load(): n = stdin.readline() data = [int(x) for x in stdin.readline().split()] return data def calc(data): total = 1 old = [1] * data.pop(0) for x in data: done = False countUp = False curr = [1] * x length = min(len(curr), len(old)) for i in range(length - 1, -1, -1): if not done: if old[i] >= total: ok, upIndex = ketaage(old, i, total) if not ok: if len(curr) > length: curr[-1] = 1 else: countUp = True else: old[upIndex] += 1 for j in range(length - 1, upIndex, -1): curr[j] = 1 old[j] = 1 else: old[i] += 1 for j in range(length - 1, i, -1): curr[j] = 1 old[j] = 1 done = True curr[i] = old[i] if countUp: total += 1 curr[-1] = total old = curr return total def ketaage(curr, i, total): if curr[i] < total: return True, i elif i == 0: return False, -1 else: return ketaage(curr, i - 1, total) data = load() print(calc(data))
Statement There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i?
[{"input": "3\n 3 2 1", "output": "2\n \n\nThe number of different characters contained in S_1,S_2,...,S_N would be 3\nwhen, for example, S_1=`abc`, S_2=`bb` and S_3=`c`.\n\nHowever, if we choose the strings properly, the number of different characters\ncan be 2.\n\n* * *"}, {"input": "5\n 2 3 2 1 2", "output": "2"}]
Print the number of ways in which Takahashi can distribute the balls, modulo 998244353. * * *
s856911135
Wrong Answer
p02940
Input is given from Standard Input in the following format: N S
# 初心者なのに上級者向けのコンテストに参加してごめんなさい
Statement We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls. Takahashi will distribute these 3N balls to N people so that each person gets one red ball, one blue ball, and one green ball. The people want balls with IDs close to each other, so he will additionally satisfy the following condition: * Let a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order. * Then, \sum_j (c_j-a_j) should be as small as possible. Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo 998244353. We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.
[{"input": "3\n RRRGGGBBB", "output": "216\n \n\nThe minimum value of \\sum_j (c_j-a_j) is 18 when the balls are, for example,\ndistributed as follows:\n\n * The first person gets Ball 1, 5, and 9.\n * The second person gets Ball 2, 4, and 8.\n * The third person gets Ball 3, 6, and 7.\n\n* * *"}, {"input": "5\n BBRGRRGRGGRBBGB", "output": "960"}]
Print the number of ways in which Takahashi can distribute the balls, modulo 998244353. * * *
s681609049
Accepted
p02940
Input is given from Standard Input in the following format: N S
N = int(input()) S = input() MOD = 998244353 # 0: '' # 1: 'A' # 2: 'B' # 3: 'C' # 4: 'AB' # 5: 'BC' # 6: 'CA' dp = [N, 0, 0, 0, 0, 0, 0] ans = 1 for c in reversed(S): # print(c) # print(dp) if c == "R": if dp[5] > 0: ans = (ans * dp[5]) % MOD dp[5] -= 1 elif dp[2] > 0: ans = (ans * dp[2]) % MOD dp[2] -= 1 dp[4] += 1 elif dp[3] > 0: ans = (ans * dp[3]) % MOD dp[3] -= 1 dp[6] += 1 else: ans = (ans * dp[0]) % MOD dp[0] -= 1 dp[1] += 1 if c == "G": if dp[6] > 0: ans = (ans * dp[6]) % MOD dp[6] -= 1 elif dp[1] > 0: ans = (ans * dp[1]) % MOD dp[1] -= 1 dp[4] += 1 elif dp[3] > 0: ans = (ans * dp[3]) % MOD dp[3] -= 1 dp[5] += 1 else: ans = (ans * dp[0]) % MOD dp[0] -= 1 dp[2] += 1 if c == "B": if dp[4] > 0: ans = (ans * dp[4]) % MOD dp[4] -= 1 elif dp[1] > 0: ans = (ans * dp[1]) % MOD dp[1] -= 1 dp[6] += 1 elif dp[2] > 0: ans = (ans * dp[2]) % MOD dp[2] -= 1 dp[5] += 1 else: ans = (ans * dp[0]) % MOD dp[0] -= 1 dp[3] += 1 # print(ans) print(ans)
Statement We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls. Takahashi will distribute these 3N balls to N people so that each person gets one red ball, one blue ball, and one green ball. The people want balls with IDs close to each other, so he will additionally satisfy the following condition: * Let a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order. * Then, \sum_j (c_j-a_j) should be as small as possible. Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo 998244353. We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.
[{"input": "3\n RRRGGGBBB", "output": "216\n \n\nThe minimum value of \\sum_j (c_j-a_j) is 18 when the balls are, for example,\ndistributed as follows:\n\n * The first person gets Ball 1, 5, and 9.\n * The second person gets Ball 2, 4, and 8.\n * The third person gets Ball 3, 6, and 7.\n\n* * *"}, {"input": "5\n BBRGRRGRGGRBBGB", "output": "960"}]
Print the number of ways in which Takahashi can distribute the balls, modulo 998244353. * * *
s987852414
Wrong Answer
p02940
Input is given from Standard Input in the following format: N S
N = int(input()) S = input() mod = 998244353 L = [0 for i in range(3 * N)] R = [0 for i in range(3 * N)] Lr = [0 for i in range(3 * N + 1)] Rr = [0 for i in range(3 * N + 1)] Lg = [0 for i in range(3 * N + 1)] Rg = [0 for i in range(3 * N + 1)] Lb = [0 for i in range(3 * N + 1)] Rb = [0 for i in range(3 * N + 1)] X = [0 for i in range(3 * N)] def f(a, b, c): return max(a, b, c) - min(a, b, c) for i in range(3 * N): if S[i] == "R": Lr[i + 1] = Lr[i] + 1 Lg[i + 1] = Lg[i] Lb[i + 1] = Lb[i] elif S[i] == "G": Lr[i + 1] = Lr[i] Lg[i + 1] = Lg[i] + 1 Lb[i + 1] = Lb[i] else: Lr[i + 1] = Lr[i] Lg[i + 1] = Lg[i] Lb[i + 1] = Lb[i] + 1 L[i] = f(Lr[i], Lg[i], Lb[i]) for i in range(3 * N - 1, -1, -1): if S[i] == "R": Rr[i] = Rr[i + 1] + 1 Rg[i] = Rg[i + 1] Rb[i] = Rb[i + 1] elif S[i] == "G": Rr[i] = Rr[i + 1] Rg[i] = Rg[i + 1] + 1 Rb[i] = Rb[i + 1] else: Rr[i] = Rr[i + 1] Rg[i] = Rg[i + 1] Rb[i] = Rb[i + 1] + 1 R[i] = f(Rr[i + 1], Rg[i + 1], Rb[i + 1]) Fact = [0 for i in range(N + 1)] Fact[0] = 1 for i in range(N): Fact[i + 1] = (Fact[i] * (i + 1)) % mod # print(L) # print(Lr) # print(Lg) # print(Lb) # print(R) # print(Rr) # print(Rg) # print(Rb) ans = 1 for i in range(3 * N): if S[i] == "R": tmp = Lb[i] * Rg[i] tmp += Rb[i] * Lg[i] tmp = Lb[i] * Lg[i] tmp += Rb[i] * Rg[i] tmp %= mod ans += tmp ans %= mod X[i] = tmp # print(X) # sum(X)+N print(ans)
Statement We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls. Takahashi will distribute these 3N balls to N people so that each person gets one red ball, one blue ball, and one green ball. The people want balls with IDs close to each other, so he will additionally satisfy the following condition: * Let a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order. * Then, \sum_j (c_j-a_j) should be as small as possible. Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo 998244353. We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.
[{"input": "3\n RRRGGGBBB", "output": "216\n \n\nThe minimum value of \\sum_j (c_j-a_j) is 18 when the balls are, for example,\ndistributed as follows:\n\n * The first person gets Ball 1, 5, and 9.\n * The second person gets Ball 2, 4, and 8.\n * The third person gets Ball 3, 6, and 7.\n\n* * *"}, {"input": "5\n BBRGRRGRGGRBBGB", "output": "960"}]
Print the number of ways in which Takahashi can distribute the balls, modulo 998244353. * * *
s841476730
Wrong Answer
p02940
Input is given from Standard Input in the following format: N S
from collections import deque from heapq import heapify, heappop, heappush def count(rgb, mod): # いい感じにrgbの組を計算する if not rgb: return 1 else: left = [0] * len(rgb) right = [0] * len(rgb) ans = 1 i, c = heappop(rgb) array = [c] left[0] = 1 j = 1 while rgb: i, c = heappop(rgb) array.append(c) if c == 0: left[j] = left[j - 1] + 1 elif c == 1: left[j] = left[j - 1] - 1 else: left[j] = left[j - 1] j += 1 right[-1] = 1 for i in reversed(range(len(array) - 1)): if array[i] == 2: right[i] = right[i + 1] + 1 elif array[i] == 1: right[i] = right[i + 1] - 1 ans *= (left[i] + 1) * (right[i] + 1) % mod ans %= mod else: right[i] = right[i + 1] return ans def solve(): N = int(input()) S = input() mod = 998244353 person = 1 for i in range(N): person *= i + 1 person %= mod r, g, b = deque(), deque(), deque() for i in range(3 * N): if S[i] == "R": r.append(i) elif S[i] == "G": g.append(i) else: b.append(i) rb, rg, gr, gb, br, bg = [], [], [], [], [], [] heapify(rb) heapify(rg) heapify(gr) heapify(gb) heapify(br) heapify(bg) for i in range(N): rs, gs, bs = r.popleft(), g.popleft(), b.popleft() if rs == min(rs, gs, bs): if gs < bs: # rgb heappush(rb, (rs, 0)) heappush(rb, (gs, 1)) heappush(rb, (bs, 2)) else: # rbg heappush(rg, (rs, 0)) heappush(rg, (gs, 2)) heappush(rg, (bs, 1)) elif gs < bs: if rs < bs: # grb heappush(gb, (rs, 1)) heappush(gb, (gs, 0)) heappush(gb, (bs, 2)) else: # gbr heappush(gr, (rs, 2)) heappush(gr, (gs, 0)) heappush(gr, (bs, 1)) else: if rs < gs: # brg heappush(bg, (rs, 1)) heappush(bg, (gs, 2)) heappush(bg, (bs, 0)) else: # bgr heappush(br, (rs, 2)) heappush(br, (gs, 1)) heappush(br, (bs, 0)) ans = person ans *= count(rb, mod) ans %= mod ans *= count(rg, mod) ans %= mod ans *= count(gb, mod) ans %= mod ans *= count(gr, mod) ans %= mod ans *= count(br, mod) ans %= mod ans *= count(bg, mod) ans %= mod print(ans) return 0 if __name__ == "__main__": solve()
Statement We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls. Takahashi will distribute these 3N balls to N people so that each person gets one red ball, one blue ball, and one green ball. The people want balls with IDs close to each other, so he will additionally satisfy the following condition: * Let a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order. * Then, \sum_j (c_j-a_j) should be as small as possible. Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo 998244353. We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.
[{"input": "3\n RRRGGGBBB", "output": "216\n \n\nThe minimum value of \\sum_j (c_j-a_j) is 18 when the balls are, for example,\ndistributed as follows:\n\n * The first person gets Ball 1, 5, and 9.\n * The second person gets Ball 2, 4, and 8.\n * The third person gets Ball 3, 6, and 7.\n\n* * *"}, {"input": "5\n BBRGRRGRGGRBBGB", "output": "960"}]
Print the number of ways in which Takahashi can distribute the balls, modulo 998244353. * * *
s928278834
Wrong Answer
p02940
Input is given from Standard Input in the following format: N S
from functools import reduce N = int(input()) S = input() MOD = 998244353 class ModInt: def __init__(self, x): self.x = x % MOD def __str__(self): return str(self.x) __repr__ = __str__ def __add__(self, other): return ( ModInt(self.x + other.x) if isinstance(other, ModInt) else ModInt(self.x + other) ) def __sub__(self, other): return ( ModInt(self.x - other.x) if isinstance(other, ModInt) else ModInt(self.x - other) ) def __mul__(self, other): return ( ModInt(self.x * other.x) if isinstance(other, ModInt) else ModInt(self.x * other) ) def __truediv__(self, other): return ( ModInt(self.x * pow(other.x, MOD - 2, MOD)) if isinstance(other, ModInt) else ModInt(self.x * pow(other, MOD - 2, MOD)) ) def __pow__(self, other): return ( ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else ModInt(pow(self.x, other, MOD)) ) def __radd__(self, other): return ModInt(other + self.x) def __rsub__(self, other): return ModInt(other - self.x) def __rmul__(self, other): return ModInt(other * self.x) def __rtruediv__(self, other): return ModInt(other * pow(self.x, MOD - 2, MOD)) def __rpow__(self, other): return ModInt(pow(other, self.x, MOD)) # 先頭のボールから順に、割り当て可能な人のうち最もボールを持っている人に割り当てることを繰り返す def f(s, res, z, r, g, b, rg, gb, br): return ( ( (res * gb, z, r, g, b, rg, gb - 1, br) if gb else ( (res * g, z, r, g - 1, b, rg + 1, gb, br) if g else ( (res * b, z, r, g, b - 1, rg, gb, br + 1) if b else (res * z, z - 1, r + 1, g, b, rg, gb, br) ) ) ) if s == "R" else ( ( (res * br, z, r, g, b, rg, gb, br - 1) if br else ( (res * r, z, r - 1, g, b, rg + 1, gb, br) if r else ( (res * b, z, r, g, b - 1, rg, gb + 1, br) if b else (res * z, z - 1, r, g + 1, b, rg, gb, br) ) ) ) if s == "G" else ( (res * rg, z, r, g, b, rg - 1, gb, br) if rg else ( (res * r, z, r - 1, g, b, rg, gb, br + 1) if r else ( (res * b, z, r, g - 1, b, rg, gb + 1, br) if g else (res * z, z - 1, r, g, b + 1, rg, gb, br) ) ) ) ) ) ans, *_ = reduce(lambda acc, s: f(s, *acc), S, (ModInt(1), N, 0, 0, 0, 0, 0, 0)) print(ans)
Statement We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls. Takahashi will distribute these 3N balls to N people so that each person gets one red ball, one blue ball, and one green ball. The people want balls with IDs close to each other, so he will additionally satisfy the following condition: * Let a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order. * Then, \sum_j (c_j-a_j) should be as small as possible. Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo 998244353. We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.
[{"input": "3\n RRRGGGBBB", "output": "216\n \n\nThe minimum value of \\sum_j (c_j-a_j) is 18 when the balls are, for example,\ndistributed as follows:\n\n * The first person gets Ball 1, 5, and 9.\n * The second person gets Ball 2, 4, and 8.\n * The third person gets Ball 3, 6, and 7.\n\n* * *"}, {"input": "5\n BBRGRRGRGGRBBGB", "output": "960"}]
Print the number of ways in which Takahashi can distribute the balls, modulo 998244353. * * *
s351037464
Accepted
p02940
Input is given from Standard Input in the following format: N S
import itertools import os import sys import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 998244353 # 解説AC N = int(sys.stdin.readline()) S = sys.stdin.readline().rstrip() def test(): pos = {"R": [], "G": [], "B": []} for i, s in enumerate(S): pos[s].append(i) ret = IINF for r in itertools.permutations(pos["R"]): for g in itertools.permutations(pos["G"]): for b in itertools.permutations(pos["B"]): s = 0 for i in range(N): s += max(r[i], g[i], b[i]) - min(r[i], g[i], b[i]) ret = min(ret, s) return ret def test2(): counter = {"R": 0, "G": 0, "B": 0} L = [] R = [] for i, c in enumerate(S): pm = max(counter.values()) counter[c] += 1 if pm < max(counter.values()): L.append(i) if min(counter.values()) == 1: R.append(i) for d in counter.keys(): counter[d] -= 1 L = np.array(L) R = np.array(R) s = (R - L).sum() return s # N = 4 # # i = 0 # for rs in itertools.combinations(range(N * 3), r=N): # s = ['G'] * (N * 3) # for r in rs: # s[r] = 'R' # rem = list(set(range(N * 3)) - set(rs)) # for bs in itertools.combinations(range(N * 2), r=N): # t = s.copy() # for b in bs: # t[rem[b]] = 'B' # S = ''.join(t) # a = test() # b = test2() # assert a == b # # if i % 100 == 0: # print(i) # i += 1 def get_lr(): counter = {"R": 0, "G": 0, "B": 0} L = [] R = [] for i, c in enumerate(S): pm = max(counter.values()) counter[c] += 1 if pm < max(counter.values()): L.append(i) if min(counter.values()) == 1: R.append(i) for d in counter.keys(): counter[d] -= 1 L = np.array(L) R = np.array(R) # s = (R - L).sum() return L, R # 左右は絶対ここから選ぶ L, R = get_lr() colors = np.array(list(S)) lmr = np.array(["M"] * (N * 3), dtype=str) lmr[L] = "L" lmr[R] = "R" # 左から L, M, R の順に選ぶ組み合わせ counts = { "R": 0, "G": 0, "B": 0, } # これより右にある、使える lmr == R の数 r_counts = np.zeros(N * 3, dtype=int) # これより左にある、使える lmr == L の数 l_counts = np.zeros(N * 3, dtype=int) for i in range(N * 3): if lmr[i] == "L": counts[colors[i]] += 1 if lmr[i] == "M": if colors[i] == "R": # B か G のどっちかしかない if counts["B"]: l_counts[i] = counts["B"] # 使ったので 1 減らす counts["B"] -= 1 elif counts["G"]: l_counts[i] = counts["G"] counts["G"] -= 1 else: assert False if colors[i] == "G": if counts["B"]: l_counts[i] = counts["B"] counts["B"] -= 1 elif counts["R"]: l_counts[i] = counts["R"] counts["R"] -= 1 else: assert False if colors[i] == "B": if counts["R"]: l_counts[i] = counts["R"] counts["R"] -= 1 elif counts["G"]: l_counts[i] = counts["G"] counts["G"] -= 1 else: assert False for i in reversed(range(N * 3)): if lmr[i] == "R": counts[colors[i]] += 1 if lmr[i] == "M": if colors[i] == "R": if counts["B"]: r_counts[i] = counts["B"] counts["B"] -= 1 elif counts["G"]: r_counts[i] = counts["G"] counts["G"] -= 1 else: assert False if colors[i] == "G": if counts["B"]: r_counts[i] = counts["B"] counts["B"] -= 1 elif counts["R"]: r_counts[i] = counts["R"] counts["R"] -= 1 else: assert False if colors[i] == "B": if counts["R"]: r_counts[i] = counts["R"] counts["R"] -= 1 elif counts["G"]: r_counts[i] = counts["G"] counts["G"] -= 1 else: assert False ans = 1 for cnt in l_counts * r_counts: if cnt: ans *= cnt ans %= MOD # N! 人に割り当てる for i in range(1, N + 1): ans *= i ans %= MOD print(ans)
Statement We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls. Takahashi will distribute these 3N balls to N people so that each person gets one red ball, one blue ball, and one green ball. The people want balls with IDs close to each other, so he will additionally satisfy the following condition: * Let a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order. * Then, \sum_j (c_j-a_j) should be as small as possible. Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo 998244353. We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.
[{"input": "3\n RRRGGGBBB", "output": "216\n \n\nThe minimum value of \\sum_j (c_j-a_j) is 18 when the balls are, for example,\ndistributed as follows:\n\n * The first person gets Ball 1, 5, and 9.\n * The second person gets Ball 2, 4, and 8.\n * The third person gets Ball 3, 6, and 7.\n\n* * *"}, {"input": "5\n BBRGRRGRGGRBBGB", "output": "960"}]
Print the number of ways in which Takahashi can distribute the balls, modulo 998244353. * * *
s463605737
Accepted
p02940
Input is given from Standard Input in the following format: N S
import sys sys.setrecursionlimit(10**6) def main(): input = sys.stdin.readline N = int(input()) S = str(input().strip()) MOD = 998244353 # state = (_, r, g, b, rg, gb, br) def f(i, ans, state): if i > 3 * N - 1: return ans if min(state) < 0: return 0 no_ball, r, g, b, rg, gb, br = state if S[i] == "R": if gb > 0: ans = (ans * gb) % MOD return f(i + 1, ans, [no_ball, r, g, b, rg, gb - 1, br]) elif g > 0 or b > 0: ans = ans * (g + b) % MOD s1 = [no_ball, r, g - 1, b, rg + 1, gb, br] s2 = [no_ball, r, g, b - 1, rg, gb, br + 1] return (f(i + 1, ans, s1) + f(i + 1, ans, s2)) % MOD else: ans = (ans * no_ball) % MOD return f(i + 1, ans, [no_ball - 1, r + 1, g, b, rg, gb, br]) elif S[i] == "G": if br > 0: ans = (ans * br) % MOD return f(i + 1, ans, [no_ball, r, g, b, rg, gb, br - 1]) elif r > 0 or b > 0: ans = ans * (r + b) % MOD s1 = [no_ball, r - 1, g, b, rg + 1, gb, br] s2 = [no_ball, r, g, b - 1, rg, gb + 1, br] return (f(i + 1, ans, s1) + f(i + 1, ans, s2)) % MOD else: ans = (ans * no_ball) % MOD return f(i + 1, ans, [no_ball - 1, r, g + 1, b, rg, gb, br]) else: # S[i] == 'B': if rg > 0: ans = (ans * rg) % MOD return f(i + 1, ans, [no_ball, r, g, b, rg - 1, gb, br]) elif r > 0 or g > 0: ans = ans * (r + g) % MOD s1 = [no_ball, r - 1, g, b, rg, gb, br + 1] s2 = [no_ball, r, g - 1, b, rg, gb + 1, br] return (f(i + 1, ans, s1) + f(i + 1, ans, s2)) % MOD else: ans = (ans * no_ball) % MOD return f(i + 1, ans, [no_ball - 1, r, g, b + 1, rg, gb, br]) return f(0, 1, [N, 0, 0, 0, 0, 0, 0]) % MOD if __name__ == "__main__": print(main())
Statement We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls. Takahashi will distribute these 3N balls to N people so that each person gets one red ball, one blue ball, and one green ball. The people want balls with IDs close to each other, so he will additionally satisfy the following condition: * Let a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order. * Then, \sum_j (c_j-a_j) should be as small as possible. Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo 998244353. We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.
[{"input": "3\n RRRGGGBBB", "output": "216\n \n\nThe minimum value of \\sum_j (c_j-a_j) is 18 when the balls are, for example,\ndistributed as follows:\n\n * The first person gets Ball 1, 5, and 9.\n * The second person gets Ball 2, 4, and 8.\n * The third person gets Ball 3, 6, and 7.\n\n* * *"}, {"input": "5\n BBRGRRGRGGRBBGB", "output": "960"}]
Print the minimum possible number of the participants in the sport with the largest number of participants. * * *
s007176327
Accepted
p03652
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} A_{21} A_{22} ... A_{2M} : A_{N1} A_{N2} ... A_{NM}
n, m = (int(i) for i in input().split()) a = [[int(i) for i in input().split()] for i in range(n)] b, x, num = [0] * n, [0] * (m + 1), m for i in range(n): x[a[i][0]] += 1 z = max(x) ans, x[x.index(z)] = z, -1 while ans > (n - 1) // num + 1: for i in range(n): if x[a[i][b[i]]] == -1: while x[a[i][b[i]]] == -1: b[i] += 1 x[a[i][b[i]]] += 1 z = max(x) ans, x[x.index(z)], num = min(ans, z), -1, num - 1 print(ans)
Statement Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.
[{"input": "4 5\n 5 1 3 4 2\n 2 5 3 1 4\n 2 3 1 4 5\n 2 5 4 3 1", "output": "2\n \n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person\n1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and\nPerson 4 in Sport 4. Here, the sport with the largest number of participants\nis Sport 3, with two participants. There is no way to reduce the number of\nparticipants in the sport with the largest number of participants to 1.\nTherefore, the answer is 2.\n\n* * *"}, {"input": "3 3\n 2 1 3\n 2 1 3\n 2 1 3", "output": "3\n \n\nSince all the people have the same taste in sports, there will be a sport with\nthree participants, no matter what sports are selected. Therefore, the answer\nis 3."}]
Print the minimum possible number of the participants in the sport with the largest number of participants. * * *
s005795175
Runtime Error
p03652
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} A_{21} A_{22} ... A_{2M} : A_{N1} A_{N2} ... A_{NM}
from collections import Counter from operator import itemgetter def sub(prefers, canceled): res = Counter() for pref in prefers: p = pref[-1] while p in canceled: pref.pop() p = pref[-1] res[p] += 1 return max(res.items(), key=itemgetter(1)) def solve(m, prefers): canceled = set() ans = float('inf') for _ in [0] * m: s, c = sub(prefers, canceled) canceled.add(s) ans = min(ans, c) return ans if __name__ == '__main__': N, M = map(int, input().split()) A = [list(map(int, input().split()))[::-1] for _ in [0] * N] print(solve(M, A))
Statement Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.
[{"input": "4 5\n 5 1 3 4 2\n 2 5 3 1 4\n 2 3 1 4 5\n 2 5 4 3 1", "output": "2\n \n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person\n1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and\nPerson 4 in Sport 4. Here, the sport with the largest number of participants\nis Sport 3, with two participants. There is no way to reduce the number of\nparticipants in the sport with the largest number of participants to 1.\nTherefore, the answer is 2.\n\n* * *"}, {"input": "3 3\n 2 1 3\n 2 1 3\n 2 1 3", "output": "3\n \n\nSince all the people have the same taste in sports, there will be a sport with\nthree participants, no matter what sports are selected. Therefore, the answer\nis 3."}]
Print the minimum possible number of the participants in the sport with the largest number of participants. * * *
s599494374
Accepted
p03652
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} A_{21} A_{22} ... A_{2M} : A_{N1} A_{N2} ... A_{NM}
n, m = map(int, input().split()) rank = [] ind = [0 for i in range(n)] for i in range(n): rank.append(list(map(int, input().split()))) sports = set(range(1, m + 1)) best = n while len(sports) > 0: kol = [0 for i in range(m + 1)] for i in range(n): while rank[i][ind[i]] not in sports: ind[i] += 1 kol[rank[i][ind[i]]] += 1 best = min(best, max(kol)) new_sports = [] for s in sports: if kol[s] < best: new_sports.append(s) sports = set(new_sports) print(best)
Statement Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.
[{"input": "4 5\n 5 1 3 4 2\n 2 5 3 1 4\n 2 3 1 4 5\n 2 5 4 3 1", "output": "2\n \n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person\n1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and\nPerson 4 in Sport 4. Here, the sport with the largest number of participants\nis Sport 3, with two participants. There is no way to reduce the number of\nparticipants in the sport with the largest number of participants to 1.\nTherefore, the answer is 2.\n\n* * *"}, {"input": "3 3\n 2 1 3\n 2 1 3\n 2 1 3", "output": "3\n \n\nSince all the people have the same taste in sports, there will be a sport with\nthree participants, no matter what sports are selected. Therefore, the answer\nis 3."}]
Print the minimum possible number of the participants in the sport with the largest number of participants. * * *
s102060551
Accepted
p03652
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} A_{21} A_{22} ... A_{2M} : A_{N1} A_{N2} ... A_{NM}
N, M = map(int, input().split()) A = [[int(i) for i in input().split()] for _ in range(N)] R = [0 for i in range(M)] for i in range(N): R[A[i][0] - 1] += 1 P = 0 Q = 0 S = set() for i in range(N): if R[A[i][0] - 1] >= P: P = R[A[i][0] - 1] Q = A[i][0] S.add(Q) while len(S) < M: Pd = 0 Qd = 0 R = [0 for i in range(M)] for i in range(N): for j in range(M): if not (set([A[i][j]]) <= S): R[A[i][j] - 1] += 1 break for j in range(M): if R[j] >= Pd: Pd = R[j] Qd = j + 1 if Pd < P: P = Pd S.add(Qd) print(P)
Statement Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.
[{"input": "4 5\n 5 1 3 4 2\n 2 5 3 1 4\n 2 3 1 4 5\n 2 5 4 3 1", "output": "2\n \n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person\n1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and\nPerson 4 in Sport 4. Here, the sport with the largest number of participants\nis Sport 3, with two participants. There is no way to reduce the number of\nparticipants in the sport with the largest number of participants to 1.\nTherefore, the answer is 2.\n\n* * *"}, {"input": "3 3\n 2 1 3\n 2 1 3\n 2 1 3", "output": "3\n \n\nSince all the people have the same taste in sports, there will be a sport with\nthree participants, no matter what sports are selected. Therefore, the answer\nis 3."}]
Print the minimum possible number of the participants in the sport with the largest number of participants. * * *
s042169331
Accepted
p03652
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} A_{21} A_{22} ... A_{2M} : A_{N1} A_{N2} ... A_{NM}
from collections import Counter def update_rank_lis(rank_lis, drop_sport): return [[sport for sport in ranks if sport != drop_sport] for ranks in rank_lis] def count_first(rank_lis): first_cnt = Counter([ranks[0] for ranks in rank_lis]) return sorted([(cnt, sport) for sport, cnt in first_cnt.items()])[-1] def solve(N, M, rank_lis): min_value = N for _ in range(M): most_pop_cnt, most_pop_sport = count_first(rank_lis) min_value = min(most_pop_cnt, min_value) rank_lis = update_rank_lis(rank_lis, most_pop_sport) print(min_value) N, M = map(int, input().split()) rank_lis = [list(map(int, input().split())) for _ in range(N)] solve(N, M, rank_lis)
Statement Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.
[{"input": "4 5\n 5 1 3 4 2\n 2 5 3 1 4\n 2 3 1 4 5\n 2 5 4 3 1", "output": "2\n \n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person\n1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and\nPerson 4 in Sport 4. Here, the sport with the largest number of participants\nis Sport 3, with two participants. There is no way to reduce the number of\nparticipants in the sport with the largest number of participants to 1.\nTherefore, the answer is 2.\n\n* * *"}, {"input": "3 3\n 2 1 3\n 2 1 3\n 2 1 3", "output": "3\n \n\nSince all the people have the same taste in sports, there will be a sport with\nthree participants, no matter what sports are selected. Therefore, the answer\nis 3."}]
Print the minimum possible number of the participants in the sport with the largest number of participants. * * *
s028143180
Wrong Answer
p03652
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} A_{21} A_{22} ... A_{2M} : A_{N1} A_{N2} ... A_{NM}
n, m = map(int, input().split()) a = [None] * n for i in range(n): a[i] = [int(x) for x in input().split()] def s(i, x): if i == m: if len(x) == 0: return 301 d = [0] * m for j in range(n): M = a[j][x[0]] l = x[0] for k in x: if a[j][k] > M: M = a[j][k] l = k d[l] += 1 # print(d) return max(d) x.append(i) r = s(i + 1, x) x.pop() return min(r, s(i + 1, x)) print(s(0, []))
Statement Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.
[{"input": "4 5\n 5 1 3 4 2\n 2 5 3 1 4\n 2 3 1 4 5\n 2 5 4 3 1", "output": "2\n \n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person\n1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and\nPerson 4 in Sport 4. Here, the sport with the largest number of participants\nis Sport 3, with two participants. There is no way to reduce the number of\nparticipants in the sport with the largest number of participants to 1.\nTherefore, the answer is 2.\n\n* * *"}, {"input": "3 3\n 2 1 3\n 2 1 3\n 2 1 3", "output": "3\n \n\nSince all the people have the same taste in sports, there will be a sport with\nthree participants, no matter what sports are selected. Therefore, the answer\nis 3."}]
Print the minimum possible number of the participants in the sport with the largest number of participants. * * *
s360346788
Accepted
p03652
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} A_{21} A_{22} ... A_{2M} : A_{N1} A_{N2} ... A_{NM}
N, M = list(map(int, input().strip().split(" "))) A = [] for _ in range(N): A += [list(map(int, input().strip().split(" ")))[::-1]] current = [0] * (M + 1) deleted = [0] * (M + 1) for j in range(N): current[A[j][-1]] += 1 # print(current) MAX = max(current) ANS = MAX index = -1 for j in range(1, len(current)): if current[j] == MAX: index = j good = 0 if MAX == 1: good = 1 print(1) if good == 0: count = 0 while count < M - 1: current = [0] * (M + 1) deleted[index] = 1 for x in range(N): while deleted[A[x][-1]] == 1: A[x].pop() if A[x] == []: break for x in range(N): if A[x] != []: current[A[x][-1]] += 1 MAX = max(current) if MAX < ANS: ANS = MAX for x in range(M + 1): if current[x] == MAX: index = x count += 1 print(ANS)
Statement Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.
[{"input": "4 5\n 5 1 3 4 2\n 2 5 3 1 4\n 2 3 1 4 5\n 2 5 4 3 1", "output": "2\n \n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person\n1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and\nPerson 4 in Sport 4. Here, the sport with the largest number of participants\nis Sport 3, with two participants. There is no way to reduce the number of\nparticipants in the sport with the largest number of participants to 1.\nTherefore, the answer is 2.\n\n* * *"}, {"input": "3 3\n 2 1 3\n 2 1 3\n 2 1 3", "output": "3\n \n\nSince all the people have the same taste in sports, there will be a sport with\nthree participants, no matter what sports are selected. Therefore, the answer\nis 3."}]
Print the minimum possible number of the participants in the sport with the largest number of participants. * * *
s703294638
Accepted
p03652
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} A_{21} A_{22} ... A_{2M} : A_{N1} A_{N2} ... A_{NM}
from subprocess import * call( ( "python3", "-c", """ from numpy import* a=loadtxt(open(0),'i',skiprows=1,ndmin=2) n=x=len(a) while a.any(): t=bincount(a[:,0]) x,a=min(x,max(t)),reshape(a[a!=argmax(t)],(n,-1)) print(x) """, ) )
Statement Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.
[{"input": "4 5\n 5 1 3 4 2\n 2 5 3 1 4\n 2 3 1 4 5\n 2 5 4 3 1", "output": "2\n \n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person\n1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and\nPerson 4 in Sport 4. Here, the sport with the largest number of participants\nis Sport 3, with two participants. There is no way to reduce the number of\nparticipants in the sport with the largest number of participants to 1.\nTherefore, the answer is 2.\n\n* * *"}, {"input": "3 3\n 2 1 3\n 2 1 3\n 2 1 3", "output": "3\n \n\nSince all the people have the same taste in sports, there will be a sport with\nthree participants, no matter what sports are selected. Therefore, the answer\nis 3."}]
Print the minimum possible number of the participants in the sport with the largest number of participants. * * *
s632339249
Runtime Error
p03652
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} A_{21} A_{22} ... A_{2M} : A_{N1} A_{N2} ... A_{NM}
from sys import stdout printn = lambda x: stdout.write(str(x)) inn = lambda: int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda: input().strip() DBG = True and False BIG = 999999999 R = 10**9 + 7 def ddprint(x): if DBG: print(x) def foo(x): b = [] for i in range(n): b.append([x for x in a[i]]) # ddprint(b) cnt = 0 rem = [False] * m while cnt < n: top = [0] * m ok = True for i in range(n): top[b[i][-1]] += 1 for j in range(m): if top[j] > x: ok = False rem[j] = True cnt += 1 if cnt == n: return False if ok: return True for i in range(n): while len(b[i]) > 0 and rem[b[i][-1]]: b[i].pop() return True n, m = inm() a = [] for i in range(n): aa = inl() aa = [x - 1 for x in aa] aa.reverse() a.append(aa) ddprint(a) mx = n mn = 0 while mx > mn + 1: mid = (mx + mn) // 2 if foo(mid): mx = mid else: mn = mid print(mx)
Statement Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.
[{"input": "4 5\n 5 1 3 4 2\n 2 5 3 1 4\n 2 3 1 4 5\n 2 5 4 3 1", "output": "2\n \n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person\n1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and\nPerson 4 in Sport 4. Here, the sport with the largest number of participants\nis Sport 3, with two participants. There is no way to reduce the number of\nparticipants in the sport with the largest number of participants to 1.\nTherefore, the answer is 2.\n\n* * *"}, {"input": "3 3\n 2 1 3\n 2 1 3\n 2 1 3", "output": "3\n \n\nSince all the people have the same taste in sports, there will be a sport with\nthree participants, no matter what sports are selected. Therefore, the answer\nis 3."}]
Print the minimum possible number of the participants in the sport with the largest number of participants. * * *
s059291820
Wrong Answer
p03652
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} A_{21} A_{22} ... A_{2M} : A_{N1} A_{N2} ... A_{NM}
import math # 配列の中で一番多い要素を返す def maxElem(lis): L = lis[:] # copy S = set(lis) S = list(S) MaxCount = 0 ret = "nothing..." for elem in S: c = 0 while elem in L: ind = L.index(elem) foo = L.pop(ind) c += 1 if c > MaxCount: MaxCount = c ret = elem return ret def numEle(lis, ele): count = 0 for i in range(len(lis)): if ele == lis[i]: count += 1 return count """ N人、M種目 →1つ以上の種目を選ぶ A(ij):人 i が j 番目に好きなスポーツ →みんな自分が最も好きなスポーツのみ参加 →「最も多くの人が参加しているスポーツの参加人数の最小値」 """ input1s = input() input1 = [int(i) for i in input1s.split(" ")] N = input1[0] # 行 M = input1[1] # 列 # append を使って二次配列 arr = [] arrow = [] for i in range(N): input2s = input() input2 = [int(j) for j in input2s.split(" ")] arr.append(input2) arrow.append(0) # 後で使う矢印の配列 min_M = math.ceil(M / N) count = 0 # 全ての配列に矢印を指して min_M と比べて、矢印をスライド for i in range(M): arrow_point = [] for j in range(N): arrow_point.append(arr[j][arrow[j]]) max_ele = maxElem(arrow_point) for k in range(N): if count != min_M: if arr[k][arrow[k]] == max_ele: arrow[k] += 1 # print (arrow_point) if min_M == numEle(arrow_point, max_ele): break print(numEle(arrow_point, max_ele))
Statement Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event. Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports. Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.
[{"input": "4 5\n 5 1 3 4 2\n 2 5 3 1 4\n 2 3 1 4 5\n 2 5 4 3 1", "output": "2\n \n\nAssume that Sports 1, 3 and 4 are selected to be played. In this case, Person\n1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and\nPerson 4 in Sport 4. Here, the sport with the largest number of participants\nis Sport 3, with two participants. There is no way to reduce the number of\nparticipants in the sport with the largest number of participants to 1.\nTherefore, the answer is 2.\n\n* * *"}, {"input": "3 3\n 2 1 3\n 2 1 3\n 2 1 3", "output": "3\n \n\nSince all the people have the same taste in sports, there will be a sport with\nthree participants, no matter what sports are selected. Therefore, the answer\nis 3."}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s710572448
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
m, n = list(map(int, input().split())) tbl = [[0 for i in range(n + 1)] for j in range(m + 1)] s = [0 for i in range(n + 1)] for i in range(m): l = list(map(int, input().split())) l.append(sum(l)) tbl[i] = l for j in range(n + 1): for i in range(m): s[j] += tbl[i][j] tbl[m] = s for i in range(m + 1): for j in range(n): print(tbl[i][j], end=" ") print(tbl[i][n], end="\n")
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s781996907
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
while True: try: n, m = map(int, input().split()) b = [] for j in range(n): a = list(map(int, input().split())) b.append(a) S = sum(a) c = list(zip(*b)) D = [sum(x) for x in c] X = sum(D) print(*a, S) print(*D, X) except: break
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s437685746
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
r, c = map(int, input().split()) sums = [0] * (c + 1) for x in range(0, r): raw = list(map(int, input().split())) raw_t = 0 for x in range(0, c): sums[x] += raw[x] raw_t += raw[x] raw.append(raw_t) sums[c] += raw_t print(*raw) print(*sums)
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s509187082
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
r, c = map(int, input().split()) out = [[]] * (r + 1) sumrow = [0 for i in range(c + 1)] for line in range(0, r): vals = list(map(int, input().split())) vals.append(sum(vals)) for itm in vals[:-1]: print(itm, end=" ") print(vals[-1]) for ids in range(c + 1): sumrow[ids] += vals[ids] for itm in sumrow[:-1]: print(itm, end=" ") print(sumrow[-1])
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s381332094
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
data = [] da = [] a = input().split() a[0] = int(a[0]) a[1] = int(a[1]) for i in range(a[0]): b = input().split() for j in range(a[1]): b[j] = int(b[j]) data.append(b) for i in range(len(data)): data[i].append(sum(data[i])) for i in range(a[1] + 1): da.append(0) for i in range(a[0]): for j in range(a[1] + 1): da[j] += data[i][j] data.append(da) for i in data: for j in range(len(i)): i[j] = str(i[j]) for i in data: print(" ".join(i))
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s328668411
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
r, c = [int(k) for k in input().split()] arr = [[]] * r for i in range(r): arr[i] = [int(k) for k in input().split()] arr += [[0] * c] for i in range(r): arr[i].append(sum(arr[i])) arr[r] = [arr[r][k] + arr[i][k] for k in range(c)] arr[r].append(0) for v in arr[r]: arr[r][c] += v arr[r][c] //= 2 for i in range(r + 1): for j in range(c + 1): arr[i][j] = str(arr[i][j]) for x in arr: print(" ".join(x))
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s976134260
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
size = list(map(int, input().split())) sheet = [] for i in range(size[0]): value = list(map(int, input().split())) sheet.extend(value) sheet.append(sum(value)) for i in range(size[1] + 1): point = i vsum = 0 for j in range(size[0]): vsum += sheet[point] point += size[1] + 1 sheet.append(vsum) for i in range(len(sheet)): if (i + 1) % (size[1] + 1) == 0: print(sheet[i]) else: print(str(sheet[i]) + " ", end="")
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s775659733
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
import sys write = sys.stdout.write number_of_numbers = [] numbers = [] number_of_numbers = input().split() number_of_numbers[0] = int(number_of_numbers[0]) number_of_numbers[1] = int(number_of_numbers[1]) for i in range(0, number_of_numbers[0]): line_nunmbers = [] line_numbers = input().split() for j in range(0, len(line_numbers)): line_numbers[j] = int(line_numbers[j]) numbers.append(line_numbers) right_end_numbers = [] under_end_numbers = [] for i in range(0, len(numbers)): right_end_numbers.append(sum(numbers[i])) for i in range(0, len(numbers[0])): under_end_number = 0 for j in range(0, len(numbers)): under_end_number += numbers[j][i] under_end_numbers.append(under_end_number) for i in range(0, len(numbers)): for j in range(0, len(numbers[0])): write(str(numbers[i][j])) write(" ") print(right_end_numbers[i]) for i in range(0, len(numbers[0])): write(str(under_end_numbers[i])) write(" ") print(sum(under_end_numbers))
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s261715994
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
rc=list(map(int,input().split())) a=[[0 for x in range(rc[1]+1)]for x in range(rc[0]+1)] for x in range(rc[0]): code=list(map(int,input().split())) result=0 for y in range(rc[1]): a[x][y]=code[y] result+=code[y] a[x][rc[1]]=result for y in range(rc[1]+1): result=0 for x in range(rc[0]): result+=a[x][y] a[rc[0]][y]=result for x in range(rc[0]+1): string="" for y in range(rc[1]+1): string+=str(a[x][y]) if (y!=rc[1]): string+=" " print(string)
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s123633585
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
max_row, max_col = map(int, input().split(" ")) rows = [[0 for i in range(max_col)] for j in range(max_row)] row = "" for i in range(max_row): row = input().split(" ") total_row = 0 for j in range(max_col): rows[i][j] = int(row[j]) total_row = total_row + int(row[j]) rows[i].append(total_row) # get summery of each columns total = [0 for i in range(max_col + 1)] for m in range(max_col + 1): for n in range(max_row): total[m] = total[m] + rows[n][m] rows.append(total) for i in range(max_row + 1): out_str = "" for j in range(max_col + 1): out_str = out_str + " " + str(rows[i][j]) print(out_str.strip())
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s967793681
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
n, m = map(int, input().split()) c = [] d = [0 for i in range(m + 1)] for i in range(n): arr = input().split() sum = 0 for j in range(m): sum += int(arr[j]) d[j] += int(arr[j]) arr.append(sum) d[m] += sum c.append(arr) c.append(d) for i in range(n + 1): print(" ".join(map(str, c[i])))
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s419833148
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
r, c = map(int, input().strip().split()) l = [[0 for j in range(c + 1)] for i in range(r + 1)] for i in range(r): l[i] = list(map(int, input().strip().split())) l[i].append(sum(l[i][0:c])) l[r] = [l[r][j] + l[i][j] for j in range(c + 1)] print(" ".join(map(str, l[i]))) print(" ".join(map(str, l[r])))
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s839900285
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
# Spreadsheet sheet = [int(i) for i in input().rstrip().split()] rows = sheet[0] columns = sheet[1] spreadSheet = [] for i in range(rows): row = [int(j) for j in input().rstrip().split()] rowTotal = 0 for element in row: rowTotal += element row.append(rowTotal) spreadSheet.append(row) # print(spreadSheet) spreadColumns = columns + 1 totalRow = [] for column in range(spreadColumns): columnTotal = 0 for i in range(rows): columnTotal += spreadSheet[i][column] totalRow.append(columnTotal) spreadSheet.append(totalRow) # print(spreadSheet) for spreadRow in spreadSheet: row_str = [str(element) for element in spreadRow] print(" ".join(row_str))
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s031329574
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
r, c = map(int, input().split()) mtx = [[int(i) for i in input().split()] for j in range(r)] for m in mtx: m.append(sum(m)) print(" ".join(list(map(str, m)))) print(" ".join(list(map(str, [sum([j[i] for j in mtx]) for i in range(c + 1)]))))
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s823451838
Wrong Answer
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s101021301
Runtime Error
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
while True: (a, op, b) = input().split() a = int(a) b = int(b) if op == "?": break elif op == "+": print(a + b) elif op == "-": print(a - b) elif op == "*": print(a * b) elif op == "/": print(a // b)
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s482012489
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
ans = "" r, c = map(int, input().split(" ")) i = 0 L = [0] * (c + 1) while i < r: a = list(map(int, input().split(" "))) atot = 0 j = 0 while j < c: atot += a[j] L[j] += a[j] j += 1 ans += " ".join(map(str, a)) + " " + str(atot) + "\n" L[c] += atot i += 1 if ans != "": ans += " ".join(map(str, L)) print(ans)
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s249944514
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
r, c = map(int, input().split()) cel = [] com = [0] * (c + 1) for i in range(r + 1): if i < r: cel.append(list(map(int, input().split()))) cel[i].append(sum(cel[i])) com = [x + y for (x, y) in zip(com, cel[i])] if i == r: cel.append(com) cel[i] = " ".join(map(str, cel[i])) [print(result) for result in cel]
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s855955066
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
r, c = map(int, input().split(" ")) sumall = [0] * (c + 1) for i in range(r): x = list(map(int, input().split(" "))) sumx = sum(x) for j in range(c): sumall[j] += x[j] # print(sumall) sumall[c] += sumx newl = " ".join(map(str, x)) print(newl + " " + str(sumx)) lastl = " ".join(map(str, sumall)) print(lastl)
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s204630988
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
h, w = map(int, input().split()) all_total = 0 col_total = [0] * w for _ in range(h): nums = list(map(int, input().split())) row_total = sum(nums) col_total = list(map(sum, zip(nums, col_total))) all_total += row_total print(" ".join(map(str, nums + [row_total]))) print(" ".join(map(str, col_total + [all_total])))
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s191624979
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
rows, columns = [int(x) for x in input().split()] numbers_list = [] for _ in range(rows): numbers = [int(y) for y in input().split()] numbers.append(sum(numbers)) numbers_list.append(numbers) column_sums = [sum(x) for x in zip(*numbers_list)] numbers_list.append(column_sums) string_list = [] for number_list in numbers_list: string_list.append([str(x) for x in number_list]) for number_list in string_list: print(" ".join(number_list))
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s739875719
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
r, c = [int(s) for s in input().split(" ")] data = [[int(s) for s in input().split(" ")] for i in range(r)] [row.append(sum(row)) for row in data] T = [[row[i] for row in data] for i in range(c + 1)] bottom = [sum(t) for t in T] data += [bottom] data_s = [" ".join([str(i) for i in row]) for row in data] [print(row) for row in data_s]
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s866160366
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
row, col = map(int, input().split()) row = int(row) end_num = 0 row_col_list = [] while True: base_suit = input() row_col_list.append(base_suit) end_num += 1 if row == end_num: break col_sum_list = [] for row in row_col_list: term = row.split() row_sum = 0 col_list = [] for r in term: row_sum += int(r) col_list.append(int(r)) print("{} ".format(r), end="") col_list.append(row_sum) print(row_sum) col_sum_list.append(col_list) for i in range(0, col + 1): col_sum = 0 for c in col_sum_list: col_sum += c[i] print("{}".format(col_sum), end="") if i != col: print(" ", end="") print()
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the new table of (r+1) × (c+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
s951732599
Accepted
p02413
In the first line, two integers r and c are given. Next, the table is given by r lines, each of which consists of c integers separated by space characters.
def test(): inputs = list(map(int, input().split())) r = inputs[0] c = inputs[1] sheet = [[0 for i in range(c + 1)] for j in range(r + 1)] for i in range(r): inputs = list(map(int, input().split())) for j in range(c): sheet[i][j] = inputs[j] sheet[i][c] += sheet[i][j] sheet[r][j] += sheet[i][j] sheet[r][c] += sheet[i][j] for i in range(r + 1): for j in range(c + 1): print(f"{sheet[i][j]}", end="") if j != c: print(" ", end="") print("") if __name__ == "__main__": test()
Spreadsheet Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
[{"input": "5\n 1 1 3 4 5\n 2 2 2 4 5\n 3 3 0 1 1\n 2 3 4 4 6", "output": "1 3 4 5 14\n 2 2 2 4 5 15\n 3 3 0 1 1 8\n 2 3 4 4 6 19\n 8 9 9 13 17 56"}]
Print the answer. * * *
s118215489
Wrong Answer
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
import sys sys.setrecursionlimit(1000000) # def input(): # return sys.stdin.readline()[:-1] """ n=int(input()) for i in range(n): a[i]=int(input()) a[i],b[i]=map(int,input().split()) a=[int(x) for x in input().split()] n,m=map(int,input.split()) from operator import itemgetter a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)] print(sorted(a)) # 0 番目の要素でソート、先頭の要素が同じなら 1 番目以降の要素も見る print(sorted(a, key=itemgetter(0))) # 0 番目の要素だけでソート print(sorted(a, key=itemgetter(0, 2))) # 0 番目と 2 番目の要素でソート print(sorted(a, key=lambda x: x[0] * x[2])) # 0 番目の要素 * 2 番目の要素でソート print(sorted(a, reverse=True)) # 降順にソート a.sort() # 破壊的にソート、sorted() よりも高速 try: # エラーキャッチ list index out of range for i in range(): k=b[i] except IndexError as e: print(i) """ test_data1 = """\ 3 4 ABC A L B L B R A R """ test_data2 = """\ 2 3 0 4 5 6 7 8 9 -1 2 -5 """ test_data3 = """\ 10 15 SNCZWRCEWB B R R R E R W R Z L S R Q L W L B R C L A L N L E R Z L S L """ td_num = 1 def GetTestData(index): if index == 1: return test_data1 if index == 2: return test_data2 if index == 3: return test_data3 if False: with open("../test.txt", mode="w") as f: f.write(GetTestData(td_num)) with open("../test.txt") as f: # Start Input code --------------------------------------- n, q = map(int, f.readline().split()) s = str(f.readline()) t = [""] * q d = [""] * q for i in range(q): t[i], d[i] = map(str, f.readline().split()) # End Input code --------------------------------------- else: for i in range(1): # Start Input code --------------------------------------- n, q = map(int, input().split()) s = str(input()) t = [""] * q d = [""] * q for i in range(q): t[i], d[i] = map(str, input().split()) # End Input code --------------------------------------- def order(x): # return goal of x-th golem l = x for i in range(q): if s[l] == t[i]: l += 1 if d[i] == "R" else -1 if l >= n or l < 0: rt = 1 if l >= n else -1 return rt return 0 ans = 0 # find leftest golem lc = 0 rc = n - 1 lv = order(lc) rv = order(rc) while rc - lc > 1: cc = int((rc + lc) / 2) cv = order(cc) if cv == 1: rc = cc rv = cv cc = int((lc + cc) / 2) else: lc = cc lv = cv cc = int((cc + rc) / 2) r = lc if rv == 1 else rc # find rightest golem lc = 0 rc = n - 1 lv = order(lc) rv = order(rc) while rc - lc > 1: cc = int((rc + lc) / 2) cv = order(cc) if cv == -1: lc = cc lv = cv cc = int((cc + rc) / 2) else: rc = cc rv = cv cc = int((lc + cc) / 2) l = rc if lv == -1 else lc print(r - l + 1)
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s603294185
Wrong Answer
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
N, Q = (int(i) for i in input().split()) s = list(input()) list1 = [] # [[A,L]] for i in range(Q): j = [str(h) for h in input().split()] list1.append(j) a = list1.count([s[0], "L"]) b = list1.count([s[N - 1], "R"]) print(N - (a + b))
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s028902059
Accepted
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*- # -*- coding: utf-8 -*- from sys import stdin ############################################ # from sys import stdin import numpy as np # read data for n sequences. d = stdin.readline().split() N = int(d[0]) Q = int(d[1]) data = str(stdin.readline().split()[0]) q = [] for _ in range(Q): q.append(stdin.readline().split()) count = 0 def leftsearch(N, q, data): x = 0 for spell in q: now = data[N] if now == spell[0]: if spell[1] == "R": N += 1 else: N -= 1 if N < 0: x = 1 break elif N == len(data): break return x def rightsearch(N, q, data): x = 0 for spell in q: now = data[N] if now == spell[0]: if spell[1] == "R": N += 1 else: N -= 1 if N >= len(data): x = 1 break elif N == 0: break return x # binary search left = 0 right = len(data) - 1 while right >= left: mid = left + int((right - left) / 2) if 1 == leftsearch(mid, q, data): left = mid + 1 else: right = mid - 1 # print("left:",mid) if mid == 0: if 0 == leftsearch(mid, q, data): leftamount = 0 else: leftamount = 1 else: if 1 == leftsearch(mid, q, data): leftamount = mid + 1 else: leftamount = mid # right binary left = 0 right = len(data) - 1 while right >= left: mid = left + int((right - left) / 2) # print(mid) if 1 == rightsearch(mid, q, data): right = mid - 1 else: left = mid + 1 # print("right:",mid) # if mid == len(data)-1: if 0 == rightsearch(mid, q, data): rightamount = 0 else: rightamount = 1 rightamount += len(data) - 1 - mid print(len(data) - (leftamount + rightamount))
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s374801625
Wrong Answer
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
#!/usr/bin/python3 N, Q = [int(x) for x in input().split()] S = input() qs = [] for _ in range(Q): t, d = [x for x in input().split()] # print(t, d) qs.append((t, -1 if d == "L" else 1)) memo = [None] * N memo.append(N) def move(i): org = i if memo[i]: return memo[i] for t, d in qs: if S[i] == t: i += d if i == -1: break elif i == N: break memo[org] = i return i def search_right(lo, hi, x): while lo < hi: mid = lo + (hi - lo) // 2 if x < move(mid): hi = mid else: # e <= t lo = mid + 1 return lo def search_left(lo, hi, x): while lo < hi: mid = lo + (hi - lo) // 2 if move(mid) < x: lo = mid + 1 else: # e <= t hi = mid return lo # l = search(0, N-1, -1) # assert move(l) == 2, "%d" % move(l) # print("search(-1)=", l) l = search_right(0, N - 1, -1) r = search_left(0, N, N) if 1 == 0: print(S) for t, d in qs: print(t, {-1: "L", 1: "R"}[d]) m = [move(i) for i in range(N + 1)] print(" ".join("%2d" % i for i in range(N + 1))) print(" ".join("%+d" % x for x in m)) print(" ".join(" *" if l == i else " " for i in range(N + 1))) print(" ".join(" *" if r == i else " " for i in range(N + 1))) print(r - l)
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s263069122
Accepted
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
#!/usr/bin/env python3 import sys from collections import defaultdict def sim(N, s, t, d, i): # print(s, i) curr = i for tt, dd in zip(t, d): if tt == s[curr]: if dd == "R": curr += 1 # print("cuz", tt, dd, curr) else: curr -= 1 # print("cuz", tt, dd, curr) if curr >= N: return "right" elif curr < 0: return "left" return "stay" # def dfs_2(N, Q, s, t, d): # # 消滅は、(s[-1],R)の呪文 # if Q == 0: # return 0 # ans = 0 # for i in range(Q): # if t[i] == s[-1] and d[i] == 'R': # ans += 1 + dfs_2(N, i, s[:-1], t[:i], d[:i]) # return ans def solve(N: int, Q: int, s: str, t: "List[str]", d: "List[str]"): wa = 0 ca, cb = -1, N while True: if ca == cb or ca + 1 == cb: break # 右側に飛び出す curr = (cb + ca) // 2 # print("1 ca, curr, cb", ca, curr, cb) state = sim(N, s, t, d, curr) if state == "right": cb = curr else: ca = curr # print("1 ca, curr, cb", ca, curr, cb) wa += N - cb ca, cb = -1, N while True: if ca == cb or ca + 1 == cb: break # 左に飛び出す curr = (cb + ca) // 2 # print("2 ca, curr, cb", ca, curr, cb) state = sim(N, s, t, d, curr) # print("2 ", state) if state == "left": ca = curr else: cb = curr # print("2 ca, curr, cb", ca, curr, cb) wa += ca + 1 print(N - wa) # print(sim(N, s, t, d, 1)) # guide = defaultdict(list) # for i in range(N): # O(N) # guide[s[i]] += [i] # pos = [1]*N # for i in range(Q): # O(Q*(N/26)) # direc = 1 if d[i] == 'R' else -1 # copied = guide[t[i]].copy() # guide[t[i]] = [] # for j in copied: # pos[j] -= 1 # if 0 <= j + direc and j + direc < N: # pos[j+direc] += 1 # guide[s[j+direc]] += [j+direc] # # print("here", s[j+direc]) # # print(pos) # # print(guide) # print(sum(pos)) # return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int Q = int(next(tokens)) # type: int s = next(tokens) # type: str t = [str()] * (Q) # type: "List[str]" d = [str()] * (Q) # type: "List[str]" for i in range(Q): t[i] = next(tokens) d[i] = next(tokens) solve(N, Q, s, t, d) if __name__ == "__main__": main()
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s425734563
Wrong Answer
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
# -*- coding: utf-8 -*- # WAなのは分かってるけど良いアイデアだと思ったのが空振って悔しいのでとりあえず投稿 from sys import stdin def load(): n = stdin.readline() return n n, q = [int(x) for x in load().strip().split(" ")] n = int(n) index = {} for i, x in enumerate(load().strip()): if x not in index: index[x] = [i] else: index[x].append(i) move = {x: 0 for x in index.keys()} for line in stdin.readlines(): t, d = line.strip().split(" ") if t not in move: continue if d == "L": move[t] -= 1 else: move[t] += 1 living_golem = n for x, hosu in move.items(): for target in index[x]: if target + hosu >= n or target - hosu < 0: living_golem -= 1 print(living_golem)
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s185014292
Runtime Error
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
n,q = list(map(int,input().split())) s = str(input()) t =[] d = [] for i in range(q): t_,d_ = list(map(str,input().split())) t.append(t_) d.append(d_) ind = -1 for i in range(q-1,-1,-1): if t[i]==s[ind]: if d[i]=='L': if ind<=n-1 ind+=1 if d[i]=='R': if ind>=0: ind-=1 ind_ = n for i in range(q-1,-1,-1): if t[i]==s[ind]: if d[i]=='L': if ind<=n-1 ind+=1 if d[i]=='R': if ind>=0: ind-=1 if ind>=ind_-1: print(0) else: print(ind_-ind-1)
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s227156048
Runtime Error
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
# coding: utf-8 # Your code here! i = input().split() n = int(i[0]) q = int(i[1]) i = input().split() mass = list(i[0]) # print(mass) table: dict = {} for j in range(len(mass)): c = mass[j] a = table.get(c) if a is None: table[c] = [] table[c].append(j) else: table[c].append(j) # print(table) golem_num_list = [1] * len(mass) # print(n, q) # 呪文回数 for i in range(q): a = input().split() mass_char = a[0] move = a[1] index_list = table.get(mass_char) if index_list is None: continue # index for j in index_list: if golem_num_list[j] != 0: # for j in range(len(mass)): # if mass_char == mass[j] and golem_num_list[j] != 0: # print("一致 {} {}".format(mass_char, move)) if move == "L": if j != 0: golem_num_list[j - 1] += golem_num_list[j] golem_num_list[j] = 0 else: golem_num_list[j] = 0 elif move == "R": if j != len(mass) - 1: golem_num_list[j + 1] += golem_num_list[j] golem_num_list[j] = 0 else: golem_num_list[j] = 0 # print(golem_num_list) sum = 0 for item in range(len(golem_num_list)): sum += int(golem_num_list[item]) print(sum)
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s398309135
Wrong Answer
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
import numpy as np print(np)
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s216829111
Runtime Error
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
n,q=map(int,input().split()) s=list(input()) s1=[1 for i in range(n)] for i in range(q): t[i],d[i]=input().split() for i in range(q):#回数 if d[i]=="R": for j in range(n)[::-1]:#マス番号 if t[i]==s[j]: if j==n: s[j]=0 else: s[j+1]=s[j+1]+s[j] if d[i]=="L": for j in range(n): if t[i]==s[j]: if t[i]==s[j]: if j==0: s[j]=0 else: s[j-1]=s[j-1]+s[j] count=0 for i in range(n): count=count+s[i] print(count)
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s516619901
Wrong Answer
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
N, Q = map(int, input().split()) s = input() print(N)
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s059099425
Runtime Error
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
n, q = map(int, input().split()) s = input() L = [1 for i in range(n)] #カウント用 x = [list(input().split()) for i in range(q)] for i in range(q):#呪文ループ for j in range(n):#マスループ 左から if x[i][0] == s[j]: if x[i][1]=='L': if j-1>=0: L[j-1] +=L[j] L[j] = 0 else: L[j] = 0 else: if (j+1)<=(n-1): L[j+1] +=L[j] L[j] = 0 else: L[j] = 0 print(sum(L))
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s874484616
Wrong Answer
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
def moveGolemToRight(golems, i): if i != n - 1: print("i=" + str(i)) golems[i + 1] += golems[i] golems[i] = 0 return golems def moveGolemToLeft(golems, i): if i != 0: golems[i - 1] += golems[i] golems[i] = 0 return golems def move(golems, addresses, t, d): i = 0 for address in addresses: print("影響を受ける住所=" + address) print("それは何番目=" + str(i)) if t == address: if d == "R": print("moveRight") print("セル" + str(i)) golems = moveGolemToRight(golems, i) else: print("moveLeft") print("セル" + str(i)) golems = moveGolemToLeft(golems, i) i += 1 return golems def makeAddresses(str, n): addresses = [] for char in str: addresses.append(char) return addresses n, q = [int(i) for i in input().split()] addresses = makeAddresses(input(), n) golems = [1] * n print(golems) for i in range(q): t, d = input().split() print(str(i) + "回目の呪文") golems = move(golems, addresses, t, d) print(golems) print("===") print(sum(golems))
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s067183018
Runtime Error
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
N, Q = map(int, input().split()) s = input() AlphabetSet = set() ThingDict = {} ShiftDict = {} for i, alphabet in enumerate(s): ThingDict.setdefault(alphabet, []) ThingDict[alphabet].append(i) ShiftDict.setdefault(alphabet, []) Step = 1 for i in range(Q): t, d = input().split() if d == "L": try: ShiftDict[t].append([-1, Step]) Step += 1 except KeyError: pass elif d == "R": try: ShiftDict[t].append([1, Step]) Step += 1 except KeyError: pass # Gone from left side MinusList = [] PlusList = [] for i, alphabet in enumerate(s): tempMinusList = [] tempPlusList = [] for sdict in ShiftDict[alphabet]: if sdict[0] == -1: tempMinusList.append(sdict[1]) if sdict[0] == 1: tempPlusList.append(sdict[1]) if tempMinusList != []: MinusList.append(tempMinusList) PlusList.append(tempPlusList) else: break tempStep = [] for i in range(len(MinusList) - 1): Ml_i = MinusList[i] Pl_ip1 = PlusList[i + 1] Ml_ip1 = MinusList[i + 1] for Mi in Ml_i: Max_Pip1 = 0 for Pip1 in Pl_ip1: if Pip1 < Mi and Pip1 > Max_Pip1: Max_Pip1 = Pip1 Max_Mip1 = 0 for Mip1 in Ml_ip1: if Mip1 < Mi and Mip1 > Max_Mip1: Max_Mip1 = Mip1 if Max_Mip1 == 0: tempStep.append(i) break elif Max_Mip1 > Max_Pip1: tempStep.append(i) else: tempStep.append(i) break if len(tempStep) > 0: Ans = N - max(tempStep) - 1 # Gone from right side MinusList = [] PlusList = [] for i, alphabet in enumerate(reversed(s)): tempMinusList = [] tempPlusList = [] for sdict in ShiftDict[alphabet]: if sdict[0] == -1: tempMinusList.append(sdict[1]) if sdict[0] == 1: tempPlusList.append(sdict[1]) if tempPlusList != []: MinusList.append(tempMinusList) PlusList.append(tempPlusList) else: break tempStep = [] for i in range(len(PlusList) - 1, 1, -1): Pl_i = PlusList[i] Pl_ip1 = PlusList[i - 1] Ml_ip1 = MinusList[i - 1] for Pi in Pl_i: Max_Mip1 = 0 for Mip1 in Ml_ip1: if Mip1 < Pi and Mip1 > Max_Mip1: Max_Mip1 = Mip1 Max_Pip1 = 0 for Pip1 in Pl_ip1: if Mip1 < Pi and Pip1 > Max_Pip1: Max_Pip1 = Pip1 if Max_Pip1 == 0: tempStep.append(i) break elif Max_Pip1 > Max_Mip1: tempStep.append(i) else: tempStep.append(i) break if len(tempStep) > 0: Ans = Ans - max(tempStep) - 1 print(Ans)
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s581058320
Wrong Answer
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
N, Q = map(int, input().split()) s = input() T = [0 for i in range(Q)] D = [0 for i in range(Q)] for i in range(Q): T[i], D[i] = input().split() for i in range(Q): if T[i] == "A": T[i] = 0 elif T[i] == "B": T[i] = 1 elif T[i] == "C": T[i] = 2 elif T[i] == "D": T[i] = 3 elif T[i] == "E": T[i] = 4 elif T[i] == "F": T[i] = 5 elif T[i] == "G": T[i] = 6 elif T[i] == "H": T[i] = 7 elif T[i] == "I": T[i] = 8 elif T[i] == "J": T[i] = 9 elif T[i] == "K": T[i] = 10 elif T[i] == "L": T[i] = 11 elif T[i] == "M": T[i] = 12 elif T[i] == "N": T[i] = 13 elif T[i] == "O": T[i] = 14 elif T[i] == "P": T[i] = 15 elif T[i] == "Q": T[i] = 16 elif T[i] == "R": T[i] = 17 elif T[i] == "S": T[i] = 18 elif T[i] == "T": T[i] = 19 elif T[i] == "U": T[i] = 20 elif T[i] == "V": T[i] = 21 elif T[i] == "W": T[i] = 22 elif T[i] == "X": T[i] = 23 elif T[i] == "Y": T[i] = 24 elif T[i] == "Z": T[i] = 25 for i in range(Q): if D[i] == "L": D[i] = 0 elif D[i] == "R": D[i] = 1 word_of_cell = [0] * N for i in range(1, N + 1): w = s[i - 1 : i] if w == "A": word_of_cell[i - 1] = 0 elif w == "B": word_of_cell[i - 1] = 1 elif w == "C": word_of_cell[i - 1] = 2 elif w == "D": word_of_cell[i - 1] = 3 elif w == "E": word_of_cell[i - 1] = 4 elif w == "F": word_of_cell[i - 1] = 5 elif w == "G": word_of_cell[i - 1] = 6 elif w == "H": word_of_cell[i - 1] = 7 elif w == "I": word_of_cell[i - 1] = 8 elif w == "J": word_of_cell[i - 1] = 9 elif w == "K": word_of_cell[i - 1] = 10 elif w == "L": word_of_cell[i - 1] = 11 elif w == "M": word_of_cell[i - 1] = 12 elif w == "N": word_of_cell[i - 1] = 13 elif w == "O": word_of_cell[i - 1] = 14 elif w == "P": word_of_cell[i - 1] = 15 elif w == "Q": word_of_cell[i - 1] = 16 elif w == "R": word_of_cell[i - 1] = 17 elif w == "S": word_of_cell[i - 1] = 18 elif w == "T": word_of_cell[i - 1] = 19 elif w == "U": word_of_cell[i - 1] = 20 elif w == "V": word_of_cell[i - 1] = 21 elif w == "W": word_of_cell[i - 1] = 22 elif w == "X": word_of_cell[i - 1] = 23 elif w == "Y": word_of_cell[i - 1] = 24 elif w == "Z": word_of_cell[i - 1] = 25 g_leave = [[[0 for i in range(N + 3)] for d in range(2)] for t in range(26)] g_enter = [[[0 for i in range(N + 3)] for d in range(2)] for t in range(26)] for t in range(26): for d in range(2): for i in range(1, N + 1): if word_of_cell[i - 1] == t and d == 0: g_enter[t][d][0] += 1 g_enter[t][d][g_enter[t][d][0]] = i g_leave[t][d][0] += 1 g_leave[t][d][g_leave[t][d][0]] = i + 1 if word_of_cell[i - 1] == t and d == 1: g_enter[t][d][0] += 1 g_enter[t][d][g_enter[t][d][0]] = i + 2 g_leave[t][d][0] += 1 g_leave[t][d][g_leave[t][d][0]] = i + 1 golem_count = [0] * (N + 2) for i in range(1, N + 1): golem_count[i] = 1 print(golem_count) import copy for q in range(Q): previous_golem_count = copy.deepcopy(golem_count) for i in range(1, g_enter[T[q]][D[q]][0] + 1): if D[q] == 0: golem_count[g_enter[T[q]][D[q]][i] - 1] += previous_golem_count[ g_enter[T[q]][D[q]][i] ] if D[q] == 1: golem_count[g_enter[T[q]][D[q]][i] - 1] += previous_golem_count[ g_enter[T[q]][D[q]][i] - 2 ] for i in range(1, g_leave[T[q]][D[q]][0] + 1): print("leave:" + str(g_leave[T[q]][D[q]][i])) golem_count[g_leave[T[q]][D[q]][i] - 1] -= previous_golem_count[ g_leave[T[q]][D[q]][i] - 1 ] print(golem_count) print(N - golem_count[0] - golem_count[N + 1])
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s927356624
Wrong Answer
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
l = input().split(" ") n = int(l[0]) q = int(l[1]) s = "*" + input() + "*" gorems = [1 for i in range(n + 2)] gorems[0] = 0 gorems[-1] = 0 l = [] for i in range(q): spell = input().split(" ") l.append(spell) for j in range(q): # to right if l[j][1] == "R": for i in range(1, n + 1): if l[j][0] == s[i]: gorems[i + 1] = gorems[i + 1] + gorems[i] gorems[i] = 0 # to left if l[j][1] == "L": for i in range(1, n + 1): if l[j][0] == s[-i - 1]: gorems[-i - 2] = gorems[-i - 2] + gorems[-i - 1] gorems[-i - 1] = 0 print(n - gorems[0] - gorems[-1])
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s796442374
Runtime Error
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
num = [int(i) for i in input().split(" ")] map_ = [i for i in input()] print(map_) golem = [1 for i in range(len(map_))] for i in range(len(map_) + 1): print(golem) magic = [i for i in input().split(" ")] lr = magic[1] place = [i for i, x in enumerate(map_) if x == magic[0]] for j in place: if j == 0: golem[j] = 0 elif j == "L": golem[j - 1] += golem[j] else: golem[j + 1] += golem[j] golem[j] = 0 print(sum(golem))
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print the answer. * * *
s282031681
Wrong Answer
p03081
Input is given from Standard Input in the following format: N Q s t_1 d_1 \vdots t_{Q} d_Q
n, q = map(int, input().split()) s = list(str(input())) J = [] Al = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", ] for i in range(26): J.append([j for j, x in enumerate(s) if x == Al[i]]) for i in range(q): t, d = map(str, input().split()) k = Al.index(t) if d == "L": J[k] = [i - 1 for i in J[k] if i - 1 >= 0] elif d == "R": J[k] = [i + 1 for i in J[k] if i + 1 <= n - 1] # print(J) ans = 0 for i in range(26): ans += len(J[i]) print(ans)
Statement There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
[{"input": "3 4\n ABC\n A L\n B L\n B R\n A R", "output": "2\n \n\n * Initially, there is one golem on each square.\n * In the first spell, the golem on Square 1 tries to move left and disappears.\n * In the second spell, the golem on Square 2 moves left.\n * In the third spell, no golem moves.\n * In the fourth spell, the golem on Square 1 moves right.\n * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n AABCBDBA\n A L\n B R\n A R", "output": "5\n \n\n * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n SNCZWRCEWB\n B R\n R R\n E R\n W R\n Z L\n S R\n Q L\n W L\n B R\n C L\n A L\n N L\n E R\n Z L\n S L", "output": "3"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s217625845
Wrong Answer
p02690
Input is given from Standard Input in the following format: X
kai = int(input()) for x in range(-1000, kai): for y in range(-1000, kai): if x**5 - y**5 == kai: print(x, y)
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s955604538
Accepted
p02690
Input is given from Standard Input in the following format: X
c = 24000 exec(c * 2 * f"i,j=c%200,c//200;i**5-j**5-{input()}or exit(print(i,j));c-=1;")
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s497732848
Accepted
p02690
Input is given from Standard Input in the following format: X
c = 5**6 exec(c * 2 * f"i,j=c%120,c//120;c-=i**5-j**5!={input()}or exit(print(i,j));")
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s561177618
Wrong Answer
p02690
Input is given from Standard Input in the following format: X
c = 20000 exec(c * 2 * f"i=c%200;j=c//200;i**5-j**5-{input()}or exit(print(i,j));c-=1;")
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s165869049
Accepted
p02690
Input is given from Standard Input in the following format: X
exec( "x=int(input());i=0;" + 'j=-i;exec("i**5-x-j**5or exit(print(i,j));j+=1;"*i*2);i+=1;' * 200 )
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s937925001
Accepted
p02690
Input is given from Standard Input in the following format: X
x=int(input()) import math import sys A=[math.pow(i,5) for i in range(-1000,1000,1)] B=[math.pow(i,5) for i in range(-1000,1000,1)] for n in A: for m in B: if n-m==x: print(-1000+A.index(n),-1000+B.index(m)) sys.exit()
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s447816140
Wrong Answer
p02690
Input is given from Standard Input in the following format: X
def do(): x = int(input()) # x1=math.sqrt(x) # print(math.sqrt(x1)) for i in range(int(x + 1)): for j in range(int(x + 1)): if (i**5) - (j**5) == x: return i, j elif (i**5) + (j**5) == x: return i, -j elif -(i**5) + (j**5) == x: return -i, -j elif -(i**5) - (j**5) == x: return -i, j # print((i ** 5) - (j ** 5)) print(do())
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s196738573
Accepted
p02690
Input is given from Standard Input in the following format: X
n = int(input()) arr = [] for i in range(1, int(pow(n, 1 / 2)) + 1): if n % i == 0: arr.append(i) res = [] for i in range(len(arr)): for j in range(-arr[i] - 1, int(pow(n, 1 / 2) + 1)): if (j + arr[i]) ** 5 - j**5 == n: res = [j + arr[i], j] break print(*res)
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s253370132
Wrong Answer
p02690
Input is given from Standard Input in the following format: X
x, r = int(input()), range(-99, 130) [i**5 - x - j**5 or print(i, j) for i in r for j in r]
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s672671597
Wrong Answer
p02690
Input is given from Standard Input in the following format: X
x = int(input()) a = int(x**0.2) a2 = a + 1 b = int((x - a**5) ** 0.2) b2 = b if (x - a2**5) > 0: b2 = x - a2**5 b2 = int(b2**0.2) y = a**5 - b**5 if y == x: print(a, b) elif a2**5 - b2**5 == x: print(a2, b2) elif a**5 + b**5 == x: print(a, -b) elif a2**5 + b2**5 == x: print(a2, b2)
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s633447268
Accepted
p02690
Input is given from Standard Input in the following format: X
X = abs(int(input())) size = 1000 L = [i**5 for i in range(size)] if X == 0: print(0, 0) for l in range(size): for m in range(l + 1): if L[l] + L[m] == X: print(l, -m) exit(0) if L[l] - L[m] == X: print(l, m) exit(0)
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s066864905
Wrong Answer
p02690
Input is given from Standard Input in the following format: X
n = int(input()) x = 1 y = 0 while x**5 < n: y = n - x**5 y = int(y) if x**5 + y**5 == n: print(x, -1 * y, sep=" ") break x += 1 if x**5 + y**5 != n: i = 1 while i <= 200: if n % i == 0: j = 0 ok = False while (i + j) ** 5 - j**5 <= n: if (i + j) ** 5 - j**5 == n: print(i + j, j, sep=" ") ok = True break j += 1 i += 1 if ok == True: break
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s009821915
Wrong Answer
p02690
Input is given from Standard Input in the following format: X
x = int(input()) d = [[0 for i in range(110)] for j in range(110)] e = [[0 for i in range(110)] for j in range(110)] for i in range(110): d[0][i] = i**5 d[i][0] = i**5 for i in range(1, 110): for j in range(1, 110): d[i][j] = d[0][j] - d[i][0] e[i][j] = d[0][j] + d[i][0] for m in range(110): if x in d[m]: print(d[m].index(x), m) break elif x in e[m]: print(e[m].index(x), -m) break
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s725258503
Wrong Answer
p02690
Input is given from Standard Input in the following format: X
import math x = int(input()) y = math.pow(abs(x), 1.0 / 5.0) a = math.ceil(y) b1 = round(math.pow(abs(a ^ 5 - x), 1 / 5)) b2 = round(math.pow(abs((a - 1) ^ 5 - x), 1 / 5)) if a ^ 5 - b1 ^ 5 == x: print(a, b1) elif a ^ 5 - b1 ^ 5 == -x: print(b1, a) elif (a - 1) ^ 5 + b2 ^ 5 == x: print(a - 1, -b2) else: print(-b2, a - 1)
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s769137189
Runtime Error
p02690
Input is given from Standard Input in the following format: X
X = int(input()) five = [0] * 64 five_inv = [0] * 64 for i in range(64): five[i] = i**5 five_inv[i] = -five[i] def check(x): for i in range(64): if X + five[i] in five: B = i A = five.index(five[i] + X) break elif X - five[i] in five: B = -i A = five.index(-five[i] + X) break elif X + five[i] in five_inv: B = i A = -five_inv.index(five[i] + X) break elif X - five[i] in five_inv: B = -i A = -five_inv.index(-five[i] + X) break return "{} {}".format(A, B) print(check(X))
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them. A B * * *
s048647165
Runtime Error
p02690
Input is given from Standard Input in the following format: X
x = int(input()) if x == 1: print(0, -1) exit() def divisorize(fct): b, e = fct.pop() # base, exponent pre_div = divisorize(fct) if fct else [[]] suf_div = [[(b, k)] for k in range(e + 1)] return [pre + suf for pre in pre_div for suf in suf_div] def factorize(n): fct = [] # prime factor b, e = 2, 0 # base, exponent while b * b <= n: while n % b == 0: n = n // b e = e + 1 if e > 0: fct.append((b, e)) b, e = b + 1, 0 if n > 1: fct.append((n, 1)) return fct def num(fct): a = 1 for base, exponent in fct: a = a * base**exponent return a c = [] fct = factorize(x) for div in divisorize(fct): c.append(num(div)) chk = False # print(c) for s in c: if chk: break for i in range(1000): if (i + s) ** 5 - i**5 > x: break if (i + s) ** 5 - i**5 == x: ans = (i + s, i) chk = True break for p in range(1, 1000): j = -1 * p # print(s,(j+s)**5-j**5) if (j + s) ** 5 - j**5 > x: break if (j + s) ** 5 - j**5 == x: ans = (j + s, j) chk = True break print(*ans)
Statement Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
[{"input": "33", "output": "2 -1\n \n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\n* * *"}, {"input": "1", "output": "0 -1"}]
Output "yes" if the jumper can complete the roundtrip, or "no" if he/she cannot.
s383749273
Runtime Error
p00357
The input is given in the following format. N d_1 d_2 : d_N The first line provides the number of trampolines N (2 ≤ N ≤ 3 × 105). Each of the subsequent N lines gives the maximum allowable jumping distance in integer meters for the i-th trampoline d_i (1 ≤ d_i ≤ 106).
fi = int(input()) tramp = [int(input()) for i in range(fi)] is_reachable = [0 for i in range(fi)] def jump(n): is_reachable[n] = 1 if n == fi: return for j in range(min(tramp[n] // 10, fi - n - 1)): if not is_reachable[n + j + 1]: jump(n + j + 1) jump(0) if not is_reachable[-1]: print("no") exit() tramp = tramp[::-1] is_reachable = [0 for i in range(fi)] jump(0) if not is_reachable[-1]: print("no") exit() print("yes")
Trampoline A plurality of trampolines are arranged in a line at 10 m intervals. Each trampoline has its own maximum horizontal distance within which the jumper can jump safely. Starting from the left-most trampoline, the jumper jumps to another trampoline within the allowed jumping range. The jumper wants to repeat jumping until he/she reaches the right-most trampoline, and then tries to return to the left-most trampoline only through jumping. Can the jumper complete the roundtrip without a single stepping-down from a trampoline? Write a program to report if the jumper can complete the journey using the list of maximum horizontal reaches of these trampolines. Assume that the trampolines are points without spatial extent.
[{"input": "4\n 20\n 5\n 10\n 1", "output": "no"}, {"input": "3\n 10\n 5\n 10", "output": "no"}, {"input": "4\n 20\n 30\n 1\n 20", "output": "yes"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s773503022
Runtime Error
p03828
The input is given from Standard Input in the following format: N
N = int(input()) if N == 1: print(1) # calculate primes by sieve primes = list(range(2, N + 1)) prime_index = 0 n = primes[prime_index] while n**2 <= N: primes = list(filter(lambda x: x == n or x % n != 0, primes)) prime_index += 1 n = primes[prime_index] # calculate exponents exponents = [0 for _ in range(len(primes))] for n in range(2, N + 1): for prime_index, prime in enumerate(primes): exponent = 0 tmp = n while tmp % prime == 0: tmp //= prime exponent += 1 exponents[prime_index] += exponent # calculate answer const = 10**9 + 7 answer = 1 for e in exponents: answer = answer * (e + 1) answer %= const print(answer)
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s801671065
Runtime Error
p03828
The input is given from Standard Input in the following format: N
n=int(input()) p=[0 for i in range(10000)] p[0]=0 p[1]=0 for i in range(2,n+1): if p[i]==1: for j in range(i*i,n+1,i): p[j]=0 ans=1 for i in range(2,n+1): if p[i]: c=0 k=i while n//k>0: c=c+(n//k)%m k=k*k ans=(ans*((c+1)%m))%m print(ans)
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s450778185
Accepted
p03828
The input is given from Standard Input in the following format: N
# # Written by NoKnowledgeGG @YlePhan # ('ω') # # import math # mod = 10**9+7 # import itertools # import fractions # import numpy as np # mod = 10**4 + 7 """def kiri(n,m): r_ = n / m if (r_ - (n // m)) > 0: return (n//m) + 1 else: return (n//m)""" """ n! mod m 階乗 mod = 1e9 + 7 N = 10000000 fac = [0] * N def ini(): fac[0] = 1 % mod for i in range(1,N): fac[i] = fac[i-1] * i % mod""" """mod = 1e9+7 N = 10000000 pw = [0] * N def ini(c): pw[0] = 1 % mod for i in range(1,N): pw[i] = pw[i-1] * c % mod""" """ def YEILD(): yield 'one' yield 'two' yield 'three' generator = YEILD() print(next(generator)) print(next(generator)) print(next(generator)) """ """def gcd_(a,b): if b == 0:#結局はc,0の最大公約数はcなのに return a return gcd_(a,a % b) # a = p * b + q""" """def extgcd(a,b,x,y): d = a if b!=0: d = extgcd(b,a%b,y,x) y -= (a//b) * x print(x,y) else: x = 1 y = 0 return d""" def readInts(): return list(map(int, input().split())) mod = 10**9 + 7 def main(): n = int(input()) m = 1 for _ in range(n, 1, -1): m *= _ cnt = 1 for i in range(2, n + 1): tmp = 1 while m % i == 0: m //= i tmp += 1 cnt *= tmp print(cnt % mod) if __name__ == "__main__": main()
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s441765153
Accepted
p03828
The input is given from Standard Input in the following format: N
import numpy as np primes = np.array( [ 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, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, ], dtype=np.int64, ) n = int(input()) div = primes[primes <= n] mod = 10**9 + 7 def divide(p, n): if n < p: return 0 return divide(p, n // p) + n // p ans = 1 for p in div: ans *= divide(p, n) + 1 ans %= mod print(ans)
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s768925912
Runtime Error
p03828
The input is given from Standard Input in the following format: N
g
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s973668166
Wrong Answer
p03828
The input is given from Standard Input in the following format: N
3
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s417934896
Runtime Error
p03828
The input is given from Standard Input in the following format: N
def kjsoinscount(n): res_ls = [] for i in range(n): # nの階乗 if i + 1 > 1: N = i + 1 for j in range(i + 1): # 階乗の各要素について素因数分解 if j + 1 > 1: while N % (j + 1) == 0: res_ls.append(j + 1) N = N / (j + 1) return res_ls + [1] def yakspattern(soins_ls): import itertools from operator import mul from functools import reduce yaks_ls = {} for i in range(len(soins_ls)): if i > 0: comb_tup = itertools.combinations(soins_ls, i + 1) for j in comb_tup: # print(j) a = reduce(mul, j) a = str(a) if a not in yaks_ls: # print(j) yaks_ls[a] = "ok" for i in soins_ls: q = str(i) yaks_ls[q] = "ok" yaks_ls return yaks_ls.keys def kjyakscount(n): import itertools from operator import mul from functools import reduce yaks_ls = [] kj_ls = [i + 1 for i in range(n)] for i in range(n): if i > 0: comb_tup = itertools.combinations(kj_ls, i + 1) for j in comb_tup: # print(j) yaks_ls.append(reduce(mul, j)) # print(set(yaks_ls)) return set(kj_ls + yaks_ls) # return(yaks_ls.extend(kj_ls)) n = int(input()) kj = 1 for i in range(n): kj = kj * (i + 1) print(len(yakspattern(kjsoinscount(n))))
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s761780633
Runtime Error
p03828
The input is given from Standard Input in the following format: N
n=int(input()) p=[1 for i in range(10000)] p[0]=0 p[1]=0 for i in range(2,n+1): if p[i]==1: for j in range(i*i,n+1,i): p[j]=0 ans=1 for i in range(2,n+1): if p[i]: c=0 k=i while n//k>0: c=c+(n//k)%m k=k*k ans=(ans*((c+1)%m))%m print(ans)
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s776815528
Accepted
p03828
The input is given from Standard Input in the following format: N
## ......... ## .7>?7n. .(wWWVyyyVyVyyyWWAw-. ## J~::::<HyyyyyyyyyyyVyyyyyyyZZuXV<. ## .?<(((JXF:::::+KW#ZuZyyyyyyZZXZZuuuZOvvrw.?. ## ,!-vvrwD:;XaJ++jWUWSw_OuVVTV7XzXkzzvo(wrrrrrw+_i ## .>.zrrvrd>jdXvvvvrrwWOtrrrwzvvrrrwHkrrrrvrvrvrrvw+?. ## .!(rrvrvwXm0vrrwAOrtwRtttrrrrrtttttW0rrrvrvrvrvrrvro.i ## .~JrvrrvwVW0<zrwXKtltwRtttttrtrrttttX0rrrvrrvrrvrvrrrw.1 ## <JrrvvvQVWS<czrwWZllOuRttttrtrrtttttXktrvrvrvrrrrZ (rr/> ## .<jZ<wrrwHWSwx-JwXKO1lOu$tttrrtrrrrttcJ0rrrrvrwXOltt< .rrw-i ## .jdvI-jCwXWSrrrvvwW0o(jwZrrOrrrrrzzvrZ>JVtrrrrrtwXOlltrrrrrI,; ## ,+XHvrvrrdHHvrvvvvZWrttrwKCw<jvuzu>?zz:.JZ=lOroJrtwSllltrvvwrl(. ## .~JZU0rvvvvUWSrrvvzzZStrrrdC1duZZZZZXwuuv<dOllwXrvvrtwklllrrrdRr-> ##(_7 JrrrrrwHWXrvvzzuuStltOr Jwzzuuuuzzvvv1Izl=lZwrvrtOXOlltrrZ4vI-- ## kwyvrrdpKrrvvzzzw0lllZ (ZttOtrrttttrd>~1==ldOrrrtZklltrrO(kr{> ## .kdSvvrdWSvvwwuuzdI??1{ z=====llllllw< 1z=lXOrrttXOtlrrr(Rrl( ## .0d+rrvXWXvwWXuuwOI??v .z>??????==z$~ ?z=lXOtttdZttrrvzSvw(_ ## .0W(rrvXHXvwWuuwZjVTO=!???<O&x>>+I???d! ..(?79UUUVU6wkrrrrrv0vr>) ## .kW(rvvwKXvdWuXw$(z?z 1z1>>zz?1> 1zOvOtrXzuzvvrvrvlt ## .SW(rrvdWqvwHurd:.I?; ...~?<<<_<< .. _1I(wrdXZuvvrrvv01 ## OWrrrrdWHvwHzwK 1v~.(ggggJ.?! (<(.JggJ.. .TdKZuzvwkvrXj ## .WDzvrdHWwwHzdH. (MHM###MkTU_ .UTWM##NMMN, ?Huuuw(WvrX( ## O>zrrwWHkwHzWW{.dY!jNWML .r_! !jMd@F k?Wo juuuIJWvvW( ## (zrzVWKdMwb.:(% .H@HNM@@N W@HNMagM. C_,kzzCdWvvfz ## 1wvXWWXHX>_> .hJHXZWHN XJWUWWHM: (Rzz1Hkvw\(- ## 1wdWvHHW<>_ ?U0zzXX= ,WVCO4y= ydzZJ 4wd ## (wf[?Wr1>(. .. .3JuO\ .SI ## (Wb zH, .__-_____- -__~__.-..~.k2 ,\ ## .4 4WHeo~~~~~~~_. .~~:~<::~.dqH? ! ## 4fWTe .1WW&&&&W1 .(OkP ## 4f ,n. \Y Y1 .d!.H: ## ? Wx. &_ _ 2 .dMK ? ## 4 ?a.. ~ ..JWDOq% ## (HkMNmx.... ....(&kHP,kk\.K ## ...?qHNWB:::::::::WHHH-.dK ## .J>:jz77<:(C:::::::::O_:~?7f;?3(. ## ..z>::::u-~::::~::~:::::(<:::(3::::?- ## .,C-::::::<:?x<1+-_~~:~~:(J++?!(3~<:<(J=_<.. ## .? ._1.....~~(z-.._(-1+,.....-J!.._(v! ?1, ## .< ! ?1--...~?iv>___~(T+..J=_(Jv^ <. ## .= _ ?7u-((JXJ-((JJZ6+JwY!_ _ (. ## .} ?1&J-:<Z<<<:<+=_ . _. : ## / : . _d7COZW>~ (. . .. ## .: ! ( .>.~(:d (~ . !- ## ( ~ ( .z777TT .. _ . : ## : ~ <_ J<<<<<j_ ._ : { ( ## . ! >_ >.....({ (_ < . (. ## - ~ >_ ,~.~..~v) < < ; .; ## . .> <..~.._Il ~ ( . > ## . .~ .>.~..~(Iz ( . ( ## < -~ ,_..~..(>j . . ## { <. <..~..~(<j. .. _ ## >. >..~...z:(_ _ < ## . >. .<.~..~_C(<} } . ## _ .~. .~..~..(>(:> } _ ## : (~. ._..~..(<(+> > ~ ## ~ <~_ ??<<!! < . import math def prime(x): p = {} cnt = 2 Flag = True while Flag: last = math.ceil(x**0.5) if cnt > last: break for i in range(cnt, last + 1): if x % i == 0: x //= i p[i] = 1 cnt = i + 2 while x % i == 0: x //= i p[i] += 1 cnt = i + 1 break if i == last: Flag = False if x != 1: p[x] = 1 return p N = int(input()) R = {} MOD = 10**9 + 7 for i in range(1, N + 1): t = prime(i) for i in t.keys(): if i not in R: R[i] = t[i] else: R[i] += t[i] ans = 1 for i in R.values(): ans = ans * (i + 1) % MOD print(ans)
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s335542799
Runtime Error
p03828
The input is given from Standard Input in the following format: N
def 解(): iN = int(input()) iD = 10**9 + 7 if iN < 3: print(iN) exit() d素={2:1} for i in range(2,iN + 1): b素 = 1 for j in range(2,int(i**0.5)+2): if i % j == 0: b素 = 0 break if b素 : d素[i]=1 for i in range(2,iN+1): for i素 in d素: while i % i素 == 0: d素[i素]+=1 i //= i素 if i == 0: break iAns = 1 for i素,num in d素.items(): iAns *= num iAns %= iD print(iAns) 解()
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s758071442
Runtime Error
p03828
The input is given from Standard Input in the following format: N
N = int(input()) ls = [1] ans = 0 if N == 1: print(1) else: for i in range(1, N+1): new_ls = map(lambda x: x*i, ls) for j in new_ls if j not in ls: ans += 1 ls.append(j) print(ans)
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s541911750
Accepted
p03828
The input is given from Standard Input in the following format: N
n = int(input()) mod = 10**9 + 7 prime = [1] * 1001 # 素因数の個数の初期値を1に設定する for num in range(2, n + 1): while num % 2 == 0: # 偶数のとき prime[2] += 1 # 2で割れる回数を記録 num //= 2 # 2で割っておく odd = 3 while odd**2 <= num: # 奇数の素因数を考える while num % odd == 0: # ある奇数で割れた時 prime[odd] += 1 # 奇数の素因数の個数を記録する num //= odd # 奇数で割っておく odd += 2 # 次の奇数にする if num != 1: # numが1でない時はそれ自身で割れるので1追加する prime[num] += 1 ans = 1 # ansの初期値を定義する for i in range(1001): ans *= prime[i] # 約数の個数を計算する print(ans % mod) # modで割った余りを出力する
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s841747474
Accepted
p03828
The input is given from Standard Input in the following format: N
from math import sqrt def make_prime_list(n): if n < 2: return [] numbers = [i for i in range(n)] numbers[1] = 0 for number in numbers: if number > sqrt(n): break if number == 0: continue for non in range(2 * number, n, number): numbers[non] = 0 return [number for number in numbers if number != 0] N = int(input()) MOD = 10**9 + 7 dictionary = {} primes = make_prime_list(N + 1) for prime in primes: dictionary[prime] = 0 x = prime while x <= N: dictionary[prime] += N // x x *= prime answer = 1 for value in dictionary.values(): answer *= value + 1 answer %= MOD print(answer)
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s188290524
Runtime Error
p03828
The input is given from Standard Input in the following format: N
// ......... // .7>?7n. .(wWWVyyyVyVyyyWWAw-. // J~::::<HyyyyyyyyyyyVyyyyyyyZZuXV<. // .?<(((JXF:::::+KW#ZuZyyyyyyZZXZZuuuZOvvrw.?. // ,!-vvrwD:;XaJ++jWUWSw_OuVVTV7XzXkzzvo(wrrrrrw+_i // .>.zrrvrd>jdXvvvvrrwWOtrrrwzvvrrrwHkrrrrvrvrvrrvw+?. // .!(rrvrvwXm0vrrwAOrtwRtttrrrrrtttttW0rrrvrvrvrvrrvro.i // .~JrvrrvwVW0<zrwXKtltwRtttttrtrrttttX0rrrvrrvrrvrvrrrw.1 // <JrrvvvQVWS<czrwWZllOuRttttrtrrtttttXktrvrvrvrrrrZ (rr/> // .<jZ<wrrwHWSwx-JwXKO1lOu$tttrrtrrrrttcJ0rrrrvrwXOltt< .rrw-i // .jdvI-jCwXWSrrrvvwW0o(jwZrrOrrrrrzzvrZ>JVtrrrrrtwXOlltrrrrrI,; // ,+XHvrvrrdHHvrvvvvZWrttrwKCw<jvuzu>?zz:.JZ=lOroJrtwSllltrvvwrl(. // .~JZU0rvvvvUWSrrvvzzZStrrrdC1duZZZZZXwuuv<dOllwXrvvrtwklllrrrdRr-> //(_7 JrrrrrwHWXrvvzzuuStltOr Jwzzuuuuzzvvv1Izl=lZwrvrtOXOlltrrZ4vI-- // kwyvrrdpKrrvvzzzw0lllZ (ZttOtrrttttrd>~1==ldOrrrtZklltrrO(kr{> // .kdSvvrdWSvvwwuuzdI??1{ z=====llllllw< 1z=lXOrrttXOtlrrr(Rrl( // .0d+rrvXWXvwWXuuwOI??v .z>??????==z$~ ?z=lXOtttdZttrrvzSvw(_ // .0W(rrvXHXvwWuuwZjVTO=!???<O&x>>+I???d! ..(?79UUUVU6wkrrrrrv0vr>) // .kW(rvvwKXvdWuXw$(z?z 1z1>>zz?1> 1zOvOtrXzuzvvrvrvlt // .SW(rrvdWqvwHurd:.I?; ...~?<<<_<< .. _1I(wrdXZuvvrrvv01 // OWrrrrdWHvwHzwK 1v~.(ggggJ.?! (<(.JggJ.. .TdKZuzvwkvrXj // .WDzvrdHWwwHzdH. (MHM###MkTU_ .UTWM##NMMN, ?Huuuw(WvrX( // O>zrrwWHkwHzWW{.dY!jNWML .r_! !jMd@F k?Wo juuuIJWvvW( // (zrzVWKdMwb.:(% .H@HNM@@N W@HNMagM. C_,kzzCdWvvfz // 1wvXWWXHX>_> .hJHXZWHN XJWUWWHM: (Rzz1Hkvw\(- // 1wdWvHHW<>_ ?U0zzXX= ,WVCO4y= ydzZJ 4wd // (wf[?Wr1>(. .. .3JuO\ .SI // (Wb zH, .__-_____- -__~__.-..~.k2 ,\ // .4 4WHeo~~~~~~~_. .~~:~<::~.dqH? ! // 4fWTe .1WW&&&&W1 .(OkP // 4f ,n. \Y Y1 .d!.H: // ? Wx. &_ _ 2 .dMK ? // 4 ?a.. ~ ..JWDOq% // (HkMNmx.... ....(&kHP,kk\.K // ...?qHNWB:::::::::WHHH-.dK // .J>:jz77<:(C:::::::::O_:~?7f;?3(. // ..z>::::u-~::::~::~:::::(<:::(3::::?- // .,C-::::::<:?x<1+-_~~:~~:(J++?!(3~<:<(J=_<.. // .? ._1.....~~(z-.._(-1+,.....-J!.._(v! ?1, // .< ! ?1--...~?iv>___~(T+..J=_(Jv^ <. // .= _ ?7u-((JXJ-((JJZ6+JwY!_ _ (. // .} ?1&J-:<Z<<<:<+=_ . _. : // / : . _d7COZW>~ (. . .. // .: ! ( .>.~(:d (~ . !- // ( ~ ( .z777TT .. _ . : // : ~ <_ J<<<<<j_ ._ : { ( // . ! >_ >.....({ (_ < . (. // - ~ >_ ,~.~..~v) < < ; .; // . .> <..~.._Il ~ ( . > // . .~ .>.~..~(Iz ( . ( // < -~ ,_..~..(>j . . // { <. <..~..~(<j. .. _ // >. >..~...z:(_ _ < // . >. .<.~..~_C(<} } . // _ .~. .~..~..(>(:> } _ // : (~. ._..~..(<(+> > ~ // ~ <~_ ??<<!! < . import java.util.* fun main(args : Array<String>) { val sc = Scanner(System.`in`) val k = sc.nextInt() val s = sc.nextInt() var result = 0 for (x in 0..k) { for (y in 0..k) { if (0 <= s - (x + y) <= k){ result += 1 } } } print(result) } import math def prime(x): p = {} cnt = 2 Flag = True while Flag: last = math.ceil(x ** 0.5) if cnt > last: break for i in range(cnt, last + 1): if x % i == 0: x //= i p[i] = 1 cnt = i + 2 while x % i == 0: x //= i p[i] += 1 cnt = i + 1 break if i == last: Flag = False if x != 1: p[x] = 1 return p N = int(input()) R = {} MOD = 10 ** 9 + 7 for i in range(1, N + 1): t = prime(i) for i in t.keys(): if i not in R: R[i] = t[i] else: R[i] += t[i] ans = 1 for i in R.values(): ans = ans * (i + 1) % MOD print(ans)
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s489854994
Runtime Error
p03828
The input is given from Standard Input in the following format: N
import sys def main(): N = input() N = int(N) k = 1 s = [] #lst = list(range(1,N+1)) primes = prime(N) num = len(primes) # N=1 lst = [0] * N if N ==1: print(1) exit() # N>=2 for i in range(2,N+1): b =[] b = bunkai(i) for i in b: lst[primes.index(i)] += 1 ans = 1 for i in lst: if i is not 0: ans = ans * (i+1) print(ans%1000000007) def prime(n): primes = [] for i in range(2,n): flag = True for j in range(2,i): if i%j == 0: flag = False if flag: primes.append(i) return primes def bunkai(i): bunkai =[] s =0 while s ==0: for j in range(2,i+1): if i % j ==0: bunkai.append(j) i = int(i/j) if i ==1: s=1 break return bunkai if __name__ == "__main__": main() shunki@ ~/scripts/python/atcoder/abc/abc_000 $ vim c.py shunki@ ~/scripts/python/atcoder/abc/abc_000 $ python c.py 2 2 shunki@ ~/scripts/python/atcoder/abc/abc_000 $ python c.py 3 4 shunki@ ~/scripts/python/atcoder/abc/abc_000 $ cat c.py import sys def main(): N = input() N = int(N) k = 1 s = [] #lst = list(range(1,N+1)) primes = prime(N+1) num = len(primes) # N=1 lst = [0] * N if N ==1: print(1) exit() # N>=2 for i in range(2,N+1): b =[] b = bunkai(i) for i in b: lst[primes.index(i)] += 1 ans = 1 for i in lst: if i is not 0: ans = ans * (i+1) print(ans%1000000007) def prime(n): primes = [] for i in range(2,n): flag = True for j in range(2,i): if i%j == 0: flag = False if flag: primes.append(i) return primes def bunkai(i): bunkai =[] s =0 while s ==0: for j in range(2,i+1): if i % j ==0: bunkai.append(j) i = int(i/j) if i ==1: s=1 break return bunkai if __name__ == "__main__": main()
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s573796004
Runtime Error
p03828
The input is given from Standard Input in the following format: N
import math def prime_decomposition(n): i = 2 table = [] while i * i <= n: while n % i == 0: n = n // i table.append(i) i += 1 if n > 1: table.append(n) return table n = int(input()) n_kai = math.factorial(n) soin = prime_decomposition(n_kai) tmp = soin[0] counter = 0 num_dict = {} forfor i in range(len(soin)): if soin[i] != tmp: tmp = soin[i] counter = 1 if i+1 == len(soin): num_dict[tmp] = counter + 1 else: if tmp != soin[i]: num_dict[tmp] = counter + 1 else: counter+=1 num_dict[tmp] = counter + 1 ans = 1 for i in num_dict.values(): ans *= i print(ans % (10**9 + 7))
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s394646708
Accepted
p03828
The input is given from Standard Input in the following format: N
def get_prime_factorized(N): R = [] b, e = 2, 0 while b**2 <= N: while N % b == 0: N = N // b e += 1 if e > 0: R.append([b, e]) b, e = b + 1, 0 if N > 1: R.append([N, 1]) return R N = int(input()) H = {} R = 1 for n in range(1, N + 1): for l in get_prime_factorized(n): k, c = l if k in H.keys(): H[k] += c else: H[k] = c for k in H.keys(): R *= H[k] + 1 R %= 10**9 + 7 print(R)
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]