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
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s915424123
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
N = list(int(i) for i in input().split()) if abs(N[2]-N[0]) <= N[3]: print(“Yes”) elif abs(N[1]-N[0])+abs(N[2]-N[1]) <= 2*N[3]: print(“Yes”) else: print(“No”)
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s376200571
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
s = input() K = int(input()) f1 = "" f2 = "" f3 = "" f4 = "" f5 = "" for a1 in range(0, len(s)): for a2 in range(a1 + 1, len(s) + 1): w = s[a1:a2] if w != f1 and w != f2 and w != f3 and w != f4 and w != f5: if f5 == "" or w < f5: f5 = w if f4 == "" or f5 < f4: t = f4 f4 = f5 f5 = t if f3 == "" or f4 < f3: t = f3 f3 = f4 f4 = t if f2 == "" or f3 < f2: t = f2 f2 = f3 f3 = t if f1 == "" or f2 < f1: t = f1 f1 = f2 f2 = t if K == 1: print(f1) if K == 2: print(f2) if K == 3: print(f3) if K == 4: print(f4) if K == 5: print(f5)
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s529136404
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d=map(int,input().split()) print("Yes" if ((abs(a-b)<=d and (abs(c-b)<=d or abs(c-a)<=d) else "No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s259052027
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
import math print(int(math.sqrt(int(input()))) ** 2)
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s910468485
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d=(map(int,input().split()) if abs(a-b)<=d: print("Yes") elif abd(a-c)<=d and abs(b-c)<=d: print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s276525186
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d = map(int, input().split()) if abs(c-a) <= d: print(“Yes”) elif abs(b-a) + abs(c-b) <= 2*d: print(“Yes”) else: print(“No”)
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s802283405
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d=map(int,input().split()) AB=abs(a-b) BC=abs(b-c) AC=abs(a-c) if AC=<d or (AC>d and AB<d and BC<d): print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s396725137
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
N = map(int, input().split()) if abs(N[2]-N[0]) <= N[3]: print(“Yes”) elif abs(N[1]-N[0])+abs(N[2]-N[1]) <= 2*N[3]: print(“Yes”) else: print(“No”)
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s859287527
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
lst=list(map(int,input().split())) if abs(lst[0]-lst[2])<=lst[3] or (abs(lst[0]-lst[1])<=lst[3] and abs(lst[2]-lst[1])<=lst[3]: print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
Print N lines. In i-th line print the answer to the question when k = i. * * *
s858187319
Accepted
p02540
Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_N y_N
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline class UnionFind: def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find_root(self, x): while self.root[x] >= 0: x = self.root[x] return x def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.find_root(x) == self.find_root(y) def size(self, x): return -self.root[self.find_root(x)] class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, w): if w <= 0: return 0 x = 0 k = 1 << (self.size.bit_length() - 1) while k: if x + k <= self.size and self.tree[x + k] < w: w -= self.tree[x + k] x += k k >>= 1 return x + 1 N = int(input()) XY = [] x2i = [0] * (N + 1) y2i = [0] * (N + 1) for i in range(1, N + 1): x, y = map(int, input().split()) XY.append((x, y)) x2i[x] = i y2i[y] = i bit = Bit(N) UF = UnionFind(N) XY.sort(key=lambda z: z[1]) r = N + 1 for i in range(N): x, y = XY[i] bit.add(x, 1) # print(x, r) if x < r: for xx in range(x, r - 1): UF.unite(x2i[xx], x2i[xx + 1]) if bit.sum(N) - bit.sum(r - 1) != N - r + 1: UF.unite(x2i[r - 1], x2i[r]) r = x if r == 1: break for i in range(1, N + 1): print(UF.size(i)) if __name__ == "__main__": main()
Statement There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N). For each k = 1,2,\dots,N, find the answer to the following question: Rng is in City k. Rng can perform the following move arbitrarily many times: * move to another city that has a smaller x-coordinate and a smaller y-coordinate, or a larger x-coordinate and a larger y-coordinate, than the city he is currently in. How many cities (including City k) are reachable from City k?
[{"input": "4\n 1 4\n 2 3\n 3 1\n 4 2", "output": "1\n 1\n 2\n 2\n \n\nRng can reach City 4 from City 3, or conversely City 3 from City 4.\n\n* * *"}, {"input": "7\n 6 4\n 4 3\n 3 5\n 7 1\n 2 7\n 5 2\n 1 6", "output": "3\n 3\n 1\n 1\n 2\n 3\n 2"}]
Print N lines. In i-th line print the answer to the question when k = i. * * *
s701719628
Accepted
p02540
Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_N y_N
N, *XY = map(int, open(0).read().split()) X, Y = XY[::2], XY[1::2] XtoY = [0] * (N + 1) for x, y in zip(X, Y): XtoY[x] = y ans = [0] * (N + 1) l = 1 min_y = N + 1 for x in range(1, N + 1): min_y = min(min_y, XtoY[x]) if x + min_y == N + 1: for i in range(l, x + 1): ans[i] = x - l + 1 l, min_y = x + 1, N + 1 for x in X: print(ans[x])
Statement There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N). For each k = 1,2,\dots,N, find the answer to the following question: Rng is in City k. Rng can perform the following move arbitrarily many times: * move to another city that has a smaller x-coordinate and a smaller y-coordinate, or a larger x-coordinate and a larger y-coordinate, than the city he is currently in. How many cities (including City k) are reachable from City k?
[{"input": "4\n 1 4\n 2 3\n 3 1\n 4 2", "output": "1\n 1\n 2\n 2\n \n\nRng can reach City 4 from City 3, or conversely City 3 from City 4.\n\n* * *"}, {"input": "7\n 6 4\n 4 3\n 3 5\n 7 1\n 2 7\n 5 2\n 1 6", "output": "3\n 3\n 1\n 1\n 2\n 3\n 2"}]
Print N lines. In i-th line print the answer to the question when k = i. * * *
s160579197
Wrong Answer
p02540
Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_N y_N
input()
Statement There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N). For each k = 1,2,\dots,N, find the answer to the following question: Rng is in City k. Rng can perform the following move arbitrarily many times: * move to another city that has a smaller x-coordinate and a smaller y-coordinate, or a larger x-coordinate and a larger y-coordinate, than the city he is currently in. How many cities (including City k) are reachable from City k?
[{"input": "4\n 1 4\n 2 3\n 3 1\n 4 2", "output": "1\n 1\n 2\n 2\n \n\nRng can reach City 4 from City 3, or conversely City 3 from City 4.\n\n* * *"}, {"input": "7\n 6 4\n 4 3\n 3 5\n 7 1\n 2 7\n 5 2\n 1 6", "output": "3\n 3\n 1\n 1\n 2\n 3\n 2"}]
Print N lines. In i-th line print the answer to the question when k = i. * * *
s932919678
Wrong Answer
p02540
Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_N y_N
import sys readline = sys.stdin.readline def gcd(a, b): while b: a, b = b, a % b return a def egcd(a, b): if a == 0: return b, 0, 1 else: g, y, x = egcd(b % a, a) return g, x - (b // a) * y, y N = int(readline()) res = [] for i in range(1, N): if i * i > 8 * N: break if (8 * N) % i: continue res.append(i) res.append(8 * N // i) def sqrt(x): ok = 0 ng = 10**18 while (ng - ok) > 1: med = (ok + ng) // 2 if med * med <= x: ok = med else: ng = med return ok M = 8 * N ans = 2 * N for r in res: if r == 1: continue u = M // r if u == 1 or u == 2: continue if gcd(r, u) > 2: continue gc, xx, yy = egcd(r, u) if gc == 1: xx *= 2 yy *= 2 xx *= -1 yy *= -1 xx %= u k = xx * r Ml = k * (k + 2) j = (sqrt(1 + Ml) - 1) // 2 ans = min(ans, j) print(ans)
Statement There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N). For each k = 1,2,\dots,N, find the answer to the following question: Rng is in City k. Rng can perform the following move arbitrarily many times: * move to another city that has a smaller x-coordinate and a smaller y-coordinate, or a larger x-coordinate and a larger y-coordinate, than the city he is currently in. How many cities (including City k) are reachable from City k?
[{"input": "4\n 1 4\n 2 3\n 3 1\n 4 2", "output": "1\n 1\n 2\n 2\n \n\nRng can reach City 4 from City 3, or conversely City 3 from City 4.\n\n* * *"}, {"input": "7\n 6 4\n 4 3\n 3 5\n 7 1\n 2 7\n 5 2\n 1 6", "output": "3\n 3\n 1\n 1\n 2\n 3\n 2"}]
Print N lines. In i-th line print the answer to the question when k = i. * * *
s774732767
Accepted
p02540
Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_N y_N
class DisjointSet: def __init__(self, size): self.parent = list(range(size)) self.rank = [0] * size def find(self, x): stack = [] parent = self.parent while parent[x] != x: stack.append(x) x = parent[x] for y in stack: parent[y] = x return x def union(self, x, y): xr, yr = self.find(x), self.find(y) if self.rank[xr] > self.rank[yr]: self.parent[yr] = xr elif self.rank[xr] < self.rank[yr]: self.parent[xr] = yr elif xr != yr: self.parent[yr] = xr self.rank[xr] += 1 max2 = lambda x, y: x if x > y else y min2 = lambda x, y: x if x < y else y import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline def solve(points): N = len(points) XI = [0] * N YI = [0] * N for i, (x, y) in enumerate(points): XI[x] = i YI[y] = i ds = DisjointSet(N) offset = N y_max_connected = -1 rep = -1 for i in YI: x0, y0 = points[i] if x0 >= offset: continue t = y0 for j in XI[x0 + 1 : offset]: x, y = points[j] if y >= y0: ds.union(i, j) t = max2(t, y) offset = x0 if y_max_connected >= y0: ds.union(rep, i) y_max_connected = max2(y_max_connected, t) else: y_max_connected = t rep = i # print(y0, y_max_connected) cnt = [0] * N for i in range(N): cnt[ds.find(i)] += 1 return [cnt[ds.find(i)] for i in range(N)] # import numpy as np # from itertools import combinations # def naive(points): # N = len(points) # grid = np.zeros((N,N), dtype=bool) # for x,y in points: # grid[x,y] = True # ds = DisjointSet(N) # for i,j in combinations(range(N),2): # x0,y0 = points[i] # x1,y1 = points[j] # if np.any(grid[max(x0,x1):,max(y0,y1):]) or np.any(grid[:min(x0,x1),:min(y0,y1)]): # ds.union(i,j) # cnt = [0]*N # for i in range(N): # cnt[ds.find(i)] += 1 # return [cnt[ds.find(i)] for i in range(N)] # from random import shuffle if __name__ == "__main__": N = int(readline()) m = map(lambda x: int(x) - 1, read().split()) points = tuple(zip(m, m)) print(*solve(points), sep="\n") # N = 12 # X = list(range(N)) # for k in range(100000): # if k % 10000: # print(k) # Y = list(range(N)) # shuffle(Y) # points = [(x,y) for x,y in zip(X,Y)] # r1,r2 = solve(points),naive(points) # if r1 != r2: # print(Y) # print(r1) # print(r2) # break
Statement There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N). For each k = 1,2,\dots,N, find the answer to the following question: Rng is in City k. Rng can perform the following move arbitrarily many times: * move to another city that has a smaller x-coordinate and a smaller y-coordinate, or a larger x-coordinate and a larger y-coordinate, than the city he is currently in. How many cities (including City k) are reachable from City k?
[{"input": "4\n 1 4\n 2 3\n 3 1\n 4 2", "output": "1\n 1\n 2\n 2\n \n\nRng can reach City 4 from City 3, or conversely City 3 from City 4.\n\n* * *"}, {"input": "7\n 6 4\n 4 3\n 3 5\n 7 1\n 2 7\n 5 2\n 1 6", "output": "3\n 3\n 1\n 1\n 2\n 3\n 2"}]
Print N lines. In i-th line print the answer to the question when k = i. * * *
s769377009
Accepted
p02540
Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_N y_N
class UnionFind(): def __init__(self,n): self.n=n self.root=[-1]*(n+1) self.rank=[0]*(n+1) def FindRoot(self,x): if self.root[x]<0: return x else: self.root[x]=self.FindRoot(self.root[x]) return self.root[x] def Unite(self,x,y): x=self.FindRoot(x) y=self.FindRoot(y) if x==y: return else: if self.rank[x]>self.rank[y]: self.root[x]+=self.root[y] self.root[y]=x elif self.rank[x]<=self.rank[y]: self.root[y]+=self.root[x] self.root[x]=y if self.rank[x]==self.rank[y]: self.rank[y]+=1 def isSameGroup(self,x,y): return self.FindRoot(x)==self.FindRoot(y) def Count(self,x): return -self.root[self.FindRoot(x)] n=int(input()) uf=UnionFind(n) arr=[list(map(int,input().split()))+[i+1] for i in range(n)] arr=sorted(arr,key=lambda x:x[0]) x,y,i=arr[0] tmp=[] for tx,ty,j in arr: if y<=ty: uf.Unite(i,j) for tx2,ty2,j2 in tmp: if ty2<=ty: uf.Unite(j,j2) tmp=[] else: tmp.append([x,y,i]) x=tx y=ty i=j arr=sorted(arr,reverse=True,key=lambda x:x[1]) x,y,i=arr[0] tmp=[] for tx,ty,j in arr: if x>=tx: uf.Unite(i,j) for tx2,ty2,j2 in tmp: if tx2>=tx: uf.Unite(j,j2) tmp=[] else: tmp.append([x,y,i]) x=tx y=ty i=j for i in range(1,n+1): print(uf.Count(i))
Statement There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N). For each k = 1,2,\dots,N, find the answer to the following question: Rng is in City k. Rng can perform the following move arbitrarily many times: * move to another city that has a smaller x-coordinate and a smaller y-coordinate, or a larger x-coordinate and a larger y-coordinate, than the city he is currently in. How many cities (including City k) are reachable from City k?
[{"input": "4\n 1 4\n 2 3\n 3 1\n 4 2", "output": "1\n 1\n 2\n 2\n \n\nRng can reach City 4 from City 3, or conversely City 3 from City 4.\n\n* * *"}, {"input": "7\n 6 4\n 4 3\n 3 5\n 7 1\n 2 7\n 5 2\n 1 6", "output": "3\n 3\n 1\n 1\n 2\n 3\n 2"}]
Print N lines. In i-th line print the answer to the question when k = i. * * *
s076407423
Wrong Answer
p02540
Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_N y_N
n = int(input()) towns = [0] * n nw = [] nw_points = [] xmax = 0 xmin = 200001 ymax = 0 ymin = 200001 for i in range(n): x, y = map(int, input().split()) if (xmax < x and ymin > y) or (xmin > x and ymax < y): # botti towns[i] = len(nw) nw.append(1) # node count nw_points.append((x, x, y, y)) # xmax, xmin, ymax, ymin else: # not botti # search for j, p in enumerate(nw_points): if (p[0] < x and p[3] > y) or (p[1] > x and p[2] < y): # notjoin pass else: # join towns[i] = j nw[j] += 1 nw_points[j] = (max(p[0], x), min(p[1], x), max(p[2], y), min(p[3], y)) xmax = max(xmax, x) xmin = min(xmin, x) ymax = max(ymax, y) ymin = min(ymin, y) for t in towns: print(nw[t])
Statement There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N). For each k = 1,2,\dots,N, find the answer to the following question: Rng is in City k. Rng can perform the following move arbitrarily many times: * move to another city that has a smaller x-coordinate and a smaller y-coordinate, or a larger x-coordinate and a larger y-coordinate, than the city he is currently in. How many cities (including City k) are reachable from City k?
[{"input": "4\n 1 4\n 2 3\n 3 1\n 4 2", "output": "1\n 1\n 2\n 2\n \n\nRng can reach City 4 from City 3, or conversely City 3 from City 4.\n\n* * *"}, {"input": "7\n 6 4\n 4 3\n 3 5\n 7 1\n 2 7\n 5 2\n 1 6", "output": "3\n 3\n 1\n 1\n 2\n 3\n 2"}]
Print N lines. In i-th line print the answer to the question when k = i. * * *
s646699060
Wrong Answer
p02540
Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_N y_N
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x + "\n") class UnionFindTree: def __init__(self, n): self.n = n self.parent = list(range(n)) self.size = [1] * n def root(self, i): inter = set() while self.parent[i] != i: inter.add(i) i = self.parent[i] r = i for i in inter: self.parent[i] = r return r def connect(self, i, j): ri = self.root(i) rj = self.root(j) if ri == rj: return if self.size[ri] < self.size[rj]: self.parent[ri] = rj self.size[rj] += self.size[ri] else: self.parent[rj] = ri self.size[ri] += self.size[rj] ### BIT binary def init(bit, values): for i, v in enumerate(values): add(bit, i + 1, v) # a1 ~ aiまでの和 O(logn) def query(bit, i): res = 0 while i > 0: res += bit[i] i -= i & (-i) return res # ai += x(logN) def add(bit, i, x): if i == 0: raise RuntimeError while i <= len(bit) - 1: bit[i] += x i += i & (-i) return def index(bit, v): """a1,...,aiの和がv以上になる最小のindexを求める 存在しないとき配列サイズを返す """ i = 0 n = len(bit) - 1 k = 1 << ((n - 1).bit_length()) while k > 0: if i + k < n + 1 and bit[i + k] < v: v -= bit[i + k] i += k k //= 2 if v == 1: return i + 1 else: return n + 1 n = int(input()) xy = [] dx = {} dy = {} for i in range(n): x, y = map(lambda x: int(x) - 1, input().split()) xy.append((i, x, y)) dx[x] = i dy[y] = i uf = UnionFindTree(n) xy.sort(key=lambda item: item[1]) bit = [0] * (n + 1) for i, x, y in xy: num = query(bit, y + 1) if num > 0: ii = dy[index(bit, num) - 1] uf.connect(i, ii) add(bit, y + 1, 1) bit = [0] * (n + 1) c = 0 for i, x, y in reversed(xy): num = query(bit, y + 1) if c - num > 0: ii = dy[index(bit, num + 1) - 1] uf.connect(i, ii) add(bit, y + 1, 1) c += 1 xy.sort(key=lambda item: item[2]) bit = [0] * (n + 1) for i, x, y in xy: num = query(bit, x + 1) if num > 0: ii = dx[index(bit, num) - 1] uf.connect(i, ii) add(bit, x + 1, 1) bit = [0] * (n + 1) c = 0 for i, x, y in reversed(xy): num = query(bit, x + 1) if c - num > 0: ii = dx[index(bit, num + 1) - 1] uf.connect(i, ii) add(bit, x + 1, 1) c += 1 ans = [None] * n for i in range(n): ans[i] = uf.size[uf.parent[i]] write("\n".join(map(str, ans)))
Statement There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N). For each k = 1,2,\dots,N, find the answer to the following question: Rng is in City k. Rng can perform the following move arbitrarily many times: * move to another city that has a smaller x-coordinate and a smaller y-coordinate, or a larger x-coordinate and a larger y-coordinate, than the city he is currently in. How many cities (including City k) are reachable from City k?
[{"input": "4\n 1 4\n 2 3\n 3 1\n 4 2", "output": "1\n 1\n 2\n 2\n \n\nRng can reach City 4 from City 3, or conversely City 3 from City 4.\n\n* * *"}, {"input": "7\n 6 4\n 4 3\n 3 5\n 7 1\n 2 7\n 5 2\n 1 6", "output": "3\n 3\n 1\n 1\n 2\n 3\n 2"}]
For each case, you have to output the maximum duration (in minutes) for which he can watch television without seeing any commercial.
s502493151
Accepted
p00592
The input will consist of several cases. In each case, the first line of the input will be n, the number of channels, which will then be followed by p and q, the time interval between which he will be watching the TV. It will be followed by 2n lines, giving the time slots for each of the channels. For each channel, the first line will be k, the number of commercial slots, and it will then be followed by 2k numbers giving the commercial slots in order. The input will be terminated by values 0 for each of n, p, q. This case should not be processed.
conv = lambda t: (t // 100) * 60 + (t % 100) while 1: N, P, Q = map(int, input().split()) if N == P == Q == 0: break P = conv(P) Q = conv(Q) CM = [0] * (Q - P + 1) for i in range(N): k = int(input()) (*T,) = map(int, input().split()) for s, t in zip(T[::2], T[1::2]): s = conv(s) t = conv(t) CM[s - P] += 1 CM[t - P] -= 1 cnt = ans = 0 for i in range(Q - P): CM[i + 1] += CM[i] if CM[i] < N: cnt += 1 else: cnt = 0 ans = max(ans, cnt) print(ans)
Boring Commercial Now it is spring holidays. A lazy student has finally passed all final examination, and he decided to just kick back and just watch TV all day. Oh, his only source of entertainment is watching TV. And TV commercial, as usual, are a big nuisance for him. He can watch any thing on television, but cannot bear even a single second of commercial. So to prevent himself from the boredom of seeing the boring commercial, he keeps shuffling through the TV channels, so that he can watch programs on different channels without seeing even a single commercial. Given the number of channels, and the duration at which the TV commercials are showed on each of the channels, you have to write a program which will print the longest interval for which the lazy student can watch the television by shuffling between the different channels without ever seeing an TV commercial. For example, consider the simplified situation where there are only three television channels, and suppose that he is watching TV from 2100 hrs to 2400 hrs. Suppose that the commercials are displayed at following time on each of the channels. * Channel 1: 2100 to 2130, 2200 to 2230 and 2300 to 2330 * Channel 2: 2130 to 2200, 2330 to 2400 * Channel 3: 2100 to 2130, 2330 to 2400 Then in this case, he can watch TV without getting interrupted by commercials for full 3 hours by watching Channel 2 from 2100 to 2130, then Channel 3 from 2130 to 2330, and then Channel 1 from 2330 to 2400.
[{"input": "2100 2400\n 1\n 2130 2200\n 3 2100 2400\n 3\n 2100 2130 2200 2230 2300 2330\n 2\n 2130 2200 2330 2400\n 2\n 2100 2130 2330 2400\n 0 0 0", "output": "180"}]
For each case, you have to output the maximum duration (in minutes) for which he can watch television without seeing any commercial.
s999395515
Runtime Error
p00592
The input will consist of several cases. In each case, the first line of the input will be n, the number of channels, which will then be followed by p and q, the time interval between which he will be watching the TV. It will be followed by 2n lines, giving the time slots for each of the channels. For each channel, the first line will be k, the number of commercial slots, and it will then be followed by 2k numbers giving the commercial slots in order. The input will be terminated by values 0 for each of n, p, q. This case should not be processed.
from queue import deque def to_tv_times(cm_times): if cm_times[0] <= p: cm_times.popleft() else: cm_times.appendleft(p) if cm_times[-1] >= q: cm_times.pop() else: cm_times.append(q) return cm_times def to_minute(hhmm): return hhmm // 100 * 60 + hhmm % 100 while True: n, p, q = map(int, input().split()) if n == 0: break cm_times = deque([p, q]) for _ in range(n): if not cm_times: input() input() continue k = int(input()) tv_times = to_tv_times(deque(map(int, input().split()))) for tvs, tvt in zip(*[iter(tv_times)] * 2): new_cm_times = deque() while cm_times: cms = cm_times.popleft() if tvt < cms: cm_times.appendleft(cms) break cmt = cm_times.popleft() if cmt < tvs: new_cm_times.append(cms) new_cm_times.append(cmt) continue if cms < tvs: new_cm_times.append(cms) new_cm_times.append(tvs) if tvt < cmt: cm_times.appendleft(cmt) cm_times.appendleft(tvt) break elif tvt == cmt: break else: continue else: if cmt < tvt: continue elif cmt == tvt: break else: cm_times.appendleft(cmt) cm_times.appendleft(tvt) break cm_times = new_cm_times + cm_times if not cm_times: print(to_minute(q) - to_minute(p)) else: final_tv_times = to_tv_times(cm_times) print(max(t - s for s, t in zip(*[map(to_minute, final_tv_times)] * 2)))
Boring Commercial Now it is spring holidays. A lazy student has finally passed all final examination, and he decided to just kick back and just watch TV all day. Oh, his only source of entertainment is watching TV. And TV commercial, as usual, are a big nuisance for him. He can watch any thing on television, but cannot bear even a single second of commercial. So to prevent himself from the boredom of seeing the boring commercial, he keeps shuffling through the TV channels, so that he can watch programs on different channels without seeing even a single commercial. Given the number of channels, and the duration at which the TV commercials are showed on each of the channels, you have to write a program which will print the longest interval for which the lazy student can watch the television by shuffling between the different channels without ever seeing an TV commercial. For example, consider the simplified situation where there are only three television channels, and suppose that he is watching TV from 2100 hrs to 2400 hrs. Suppose that the commercials are displayed at following time on each of the channels. * Channel 1: 2100 to 2130, 2200 to 2230 and 2300 to 2330 * Channel 2: 2130 to 2200, 2330 to 2400 * Channel 3: 2100 to 2130, 2330 to 2400 Then in this case, he can watch TV without getting interrupted by commercials for full 3 hours by watching Channel 2 from 2100 to 2130, then Channel 3 from 2130 to 2330, and then Channel 1 from 2330 to 2400.
[{"input": "2100 2400\n 1\n 2130 2200\n 3 2100 2400\n 3\n 2100 2130 2200 2230 2300 2330\n 2\n 2130 2200 2330 2400\n 2\n 2100 2130 2330 2400\n 0 0 0", "output": "180"}]
For each dataset, print the chessboard made of '#' and '.'. Print a blank line after each dataset.
s893612289
Wrong Answer
p02405
The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero).
# 15chess H, W = (int(i) for i in input().split()) while H != 0 or W != 0: S = "." for i in range(H): if S[0] == "#": S = "." else: S = "#" for i in range(W - 1): if S[-1] == "#": S += "." else: S += "#" print(S, end="") print("\n") H, W = (int(i) for i in input().split())
Print a Chessboard Draw a chessboard which has a height of H cm and a width of W cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm. #.#.#.#.#. .#.#.#.#.# #.#.#.#.#. .#.#.#.#.# #.#.#.#.#. .#.#.#.#.# Note that the top left corner should be drawn by '#'.
[{"input": "4\n 5 6\n 3 3\n 2 2\n 1 1\n 0 0", "output": "#.#.\n .#.#\n #.#.\n \n #.#.#.\n .#.#.#\n #.#.#.\n .#.#.#\n #.#.#.\n \n #.#\n .#.\n #.#\n \n #.\n .#\n \n #"}]
For each dataset, print the chessboard made of '#' and '.'. Print a blank line after each dataset.
s104343562
Accepted
p02405
The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero).
c = [] def listcreate(): global c c = [] for y in range(a[0]): b = [] for x in range(a[1]): if (x + y) % 2 == 0: b.append("#") else: b.append(".") c.append(b) return def listdraw(): global c for y in range(len(c)): for x in range(len(c[0])): print(c[y][x], end="") print() return for i in range(10000): a = list(map(int, input().split())) if sum(a) == 0: break listcreate() listdraw() print()
Print a Chessboard Draw a chessboard which has a height of H cm and a width of W cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm. #.#.#.#.#. .#.#.#.#.# #.#.#.#.#. .#.#.#.#.# #.#.#.#.#. .#.#.#.#.# Note that the top left corner should be drawn by '#'.
[{"input": "4\n 5 6\n 3 3\n 2 2\n 1 1\n 0 0", "output": "#.#.\n .#.#\n #.#.\n \n #.#.#.\n .#.#.#\n #.#.#.\n .#.#.#\n #.#.#.\n \n #.#\n .#.\n #.#\n \n #.\n .#\n \n #"}]
Print the answer. * * *
s390978876
Accepted
p03644
Input is given from Standard Input in the following format: N
N = input() saidai = 0 for i in range(1, int(N) + 1): count = 0 flag = 0 x = i while flag == 0: y = int(int(x) % 2) if y == 0: count = int(int(count) + 1) x = int(int(x) / 2) elif y == 1: flag = 1 if int(count) >= int(saidai): saidai = count z = i print(z)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s278773459
Wrong Answer
p03644
Input is given from Standard Input in the following format: N
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list(map(lambda x: int(x) - 1, stdin.readline().split())) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 # A def A(): n = II() print("ABC" + str(n)) return # B def B(): ni = [2**i for i in range(1, 10)] n = II() ans = 1 for i in range(1, n + 1): if i in ni: ans = i print(ans) return # C def C(): return # D def D(): return # E def E(): return # F def F(): return # G def G(): return # H def H(): return # Solve if __name__ == "__main__": A()
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s330922439
Wrong Answer
p03644
Input is given from Standard Input in the following format: N
import sys import os import math import string ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: x * y / math.gcd(x, y) MOD = 10**9 + 7 def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N = ii() cnt = 0 ret = 0 for n in range(1, N + 1): tmp = 0 q = n while n % 2 == 0: n = n // 2 tmp += 1 if tmp > cnt: ret = q cnt = tmp print(ret) if __name__ == "__main__": main()
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s303396053
Wrong Answer
p03644
Input is given from Standard Input in the following format: N
# # abc068 b # import unittest from io import StringIO import sys def input(): return sys.stdin.readline().rstrip() # def resolve(): # N = int(input()) # # ans = 1 # ansn = 0 # for i in range(1, N+1): # tmp = 0 # j = i # while j % 2 == 0: # tmp += 1 # j //= 2 # # if tmp > ansn: # ansn = tmp # ans = i # # print(ans) def resolve(): N = int(input()) for i in reversed(range(1, 7)): if 2**i <= N < 2 ** (i + 1): print(2**i) class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """7""" output = """4""" self.assertIO(input, output) def test_入力例_2(self): input = """32""" output = """32""" self.assertIO(input, output) def test_入力例_3(self): input = """1""" output = """1""" self.assertIO(input, output) def test_入力例_4(self): input = """100""" output = """64""" self.assertIO(input, output) if __name__ == "__main__": # unittest.main() resolve()
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s225522674
Wrong Answer
p03644
Input is given from Standard Input in the following format: N
n = int(input()) nums = [0, 2, 4, 8, 16, 32, 64] maxi = 0 for i in range(len(nums)): if nums[i] <= n: maxi = nums[i] print(maxi)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s278498263
Runtime Error
p03644
Input is given from Standard Input in the following format: N
def resolve(): n = int(input()) ans = 0 for i in range(1, n+1): if i % 2 == 0: ans += 1 print(ans) resolve()
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s729585139
Runtime Error
p03644
Input is given from Standard Input in the following format: N
n = int(input()) for i in range(n): if i = 2**a and 2**a < n and n < 2**(a+1): print(i)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s992699770
Accepted
p03644
Input is given from Standard Input in the following format: N
print(1 << int(input()).bit_length() - 1)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s534334122
Runtime Error
p03644
Input is given from Standard Input in the following format: N
if 2**i <=n:
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s410588493
Runtime Error
p03644
Input is given from Standard Input in the following format: N
import math math.log2(2)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s230113953
Runtime Error
p03644
Input is given from Standard Input in the following format: N
N = int(input()) counter = -1 number = 0 for i + 1 in range(N): k = i now_counter = 0 while k % 2 == 0: now_counter += 1 k /= 2 if now_counter > counter: number = i print(number)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s319202072
Runtime Error
p03644
Input is given from Standard Input in the following format: N
N=int(input()) if N=1: print(1) elif 2<=N<=3: print(2) elif 4<=N<=7: print(4) elif 8<=N<=15: print(8) elif 16<=N<=31: print(16) elif 32<=N<=63: print(32) elif 64<=N<=100: print(64)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s683156028
Runtime Error
p03644
Input is given from Standard Input in the following format: N
N = int(input()) a = [] for i in range(1,N + 1): count = 0 while True: if i % 2 == 0: i /= 2 count += 1 else: break a.append(count) print(a.index(max(X) + 1)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s357424548
Runtime Error
p03644
Input is given from Standard Input in the following format: N
N = int(input()) a = [] for i in range(1,N + 1): count = 0 while True: if i % 2 == 0: i /= 2 count += 1 else: break a.append(count) print(a.index(max(X) + 1))
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s534441790
Runtime Error
p03644
Input is given from Standard Input in the following format: N
N=int(input()) while i<N+1: count(i)=o if i%2==0: count(i)+=1 else: break if count(a)=max(count(i)): print(a)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s741692933
Accepted
p03644
Input is given from Standard Input in the following format: N
n = int(input()) num = [2**i for i in range(10)] while n not in num: n -= 1 print(n)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s639415559
Accepted
p03644
Input is given from Standard Input in the following format: N
n = int(input()) print( 64 if n > 63 else ( 32 if n > 31 else 16 if n > 15 else 8 if n > 7 else 4 if n > 3 else 2 if n > 1 else 1 ) )
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s500061054
Runtime Error
p03644
Input is given from Standard Input in the following format: N
N = int(input()) count = 0 While N%2==0: N = N/2 count += 1 else: break print(count)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s203561697
Wrong Answer
p03644
Input is given from Standard Input in the following format: N
N = int(input()) tmp = 1 flag = True while flag: tmp = tmp * 2 print(tmp) if tmp >= N: flag = False print(int(tmp / 2))
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s434405590
Accepted
p03644
Input is given from Standard Input in the following format: N
x = input() x = int(x) y = 1 while x >= y: y = y * 2 else: print(int(y / 2))
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s368486152
Runtime Error
p03644
Input is given from Standard Input in the following format: N
n = int(input()) ans=0 while(n%2==0): ans++ n/=2 print(ans)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s928300153
Runtime Error
p03644
Input is given from Standard Input in the following format: N
n=int(input()) b=0 for i in range(7): if 2**i=<n: b=2**i print(b)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s807501970
Runtime Error
p03644
Input is given from Standard Input in the following format: N
a = int(input()) c = 1 while (c <= a): c = c * 2 print(int(c/2))
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s282655724
Runtime Error
p03644
Input is given from Standard Input in the following format: N
print(2**(len(bin(int(input()))-3))
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s571717745
Runtime Error
p03644
Input is given from Standard Input in the following format: N
n = int(input()) for i in range(7): if n < 2 ** i: print(2**(i-1)) break
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s611874201
Wrong Answer
p03644
Input is given from Standard Input in the following format: N
N = bin(int(input())) print(len(N) - 3)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s949689055
Runtime Error
p03644
Input is given from Standard Input in the following format: N
N = int(input()) exp = 0 for N >= 2: N = N // 2 exp += 1 print(2 ** exp)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s697553108
Runtime Error
p03644
Input is given from Standard Input in the following format: N
N=int(input()) if N=1: print(1) elif 2<=N<=3: print(2) elif 4<=N<=7: print(4) elif 8<=N<=15: print(8) elif 16<=N<=31: print(16) elif 32<=N<=64: print(32) else 64<=N<=100: print(64)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s452359743
Runtime Error
p03644
Input is given from Standard Input in the following format: N
N = int(input()) num=1 for i in range(1, N): if num*2 > N: print(num): break else: num = num*2
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s700639070
Runtime Error
p03644
Input is given from Standard Input in the following format: N
n = int(input()) def cnt(a): if a == 1: return 0: return cnt(a//2) res = 0 for a in range(1, n + 1): res = max(res, cnt(a)) print(res)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s794271733
Runtime Error
p03644
Input is given from Standard Input in the following format: N
n=int(input()) ln=[0]*n for a in range(n): if a %2 ==0: ln[a-1}=a//2 else: ln[a-1]=0 print(max(ln))
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s684000114
Accepted
p03644
Input is given from Standard Input in the following format: N
n = int(input()) kai = 0 nn = 0 while 2**nn <= n: nn += 1 nn -= 1 print(2**nn)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s251023348
Runtime Error
p03644
Input is given from Standard Input in the following format: N
N = int(input()) n = 1 while n <= N: n *= 2 print(n // 2)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s954130561
Wrong Answer
p03644
Input is given from Standard Input in the following format: N
li = [2, 4, 8, 16, 32, 64, 128] n = int(input()) for i in li: if n < i: print(li.index(i))
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s319228783
Runtime Error
p03644
Input is given from Standard Input in the following format: N
i=int(input()) for n in range(0,9): if 2**n=<i<2**(n+1): print(2**n) break
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s810885020
Wrong Answer
p03644
Input is given from Standard Input in the following format: N
# 68B Break Number n = int(input()) maxnum = 0 maxtrial = 2 while maxtrial < n: maxtrial *= 2 print(int(maxtrial / 2))
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s593524198
Runtime Error
p03644
Input is given from Standard Input in the following format: N
N = int(input()) count = 0 While True: if N%2==0: count += 1 else: break print(count)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s781885355
Accepted
p03644
Input is given from Standard Input in the following format: N
n_b = bin(int(input()))[::-1] print(2 ** (n_b.index("b") - 1))
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s019112024
Runtime Error
p03644
Input is given from Standard Input in the following format: N
n = int(input()) i=0 while (2**i <= n): i += 1 print(2**(i-1))
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s252292987
Runtime Error
p03644
Input is given from Standard Input in the following format: N
N = int(input()) i = 0 while 2**i <-=N: i += 1 print(2**(i-1))
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s372682526
Runtime Error
p03644
Input is given from Standard Input in the following format: N
a = int(input()) i = 1 while(i<=a) i *= 2 print(i/2)
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s615142371
Runtime Error
p03644
Input is given from Standard Input in the following format: N
j = int(input()) print([2**i for i in range(8) if 2**i <= N][-1])
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the answer. * * *
s552203100
Wrong Answer
p03644
Input is given from Standard Input in the following format: N
s = input() print(s[0] + str(len(s[1:-1])) + s[-1])
Statement Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
[{"input": "7", "output": "4\n \n\n4 can be divided by 2 twice, which is the most number of times among 1, 2,\n..., 7.\n\n* * *"}, {"input": "32", "output": "32\n \n\n* * *"}, {"input": "1", "output": "1\n \n\n* * *"}, {"input": "100", "output": "64"}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s214816121
Wrong Answer
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
import sys from bisect import bisect_left input = sys.stdin.readline Q = 998244353 def main(): N = int(input()) X = [0] * N Y = [0] * N XY = [tuple(map(int, input().split())) for _ in range(N)] for i in range(N): X[i], Y[i] = XY[i] X.sort() Y.sort() ans = pow(2, N, Q) * N % Q s = pow(2, Q - 2, Q) for x, y in XY: i = bisect_left(X, x) j = bisect_left(Y, y) now = 0 if i > 1: now = (now + pow(2, i, Q) - 1 - i) % Q if i < N - 1: now = now + pow(2, N - i, Q) - 1 - (N - i) if j > 1: now = (now + pow(2, j, Q) - 1 - j) % Q if j < N - 1: now = now + pow(2, N - j, Q) - 1 - (N - j) ans = (ans - now * s % Q) % Q print(ans) if __name__ == "__main__": main()
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s307023623
Runtime Error
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
from itertools import product import numpy as np n = int(input()) xy = [tuple(map(int, input().split())) for _ in range(n)] mod = 998244353 xs = [x for x, y in xy] ys = [y for x, y in xy] xs.sort() ys.sort() x_dict = dict(zip(xs, range(1, 1 + n))) y_dict = dict(zip(ys, range(1, 1 + n))) points = set((x_dict[x], y_dict[y]) for x, y in xy) # cum_array = [[0] * (n + 1) for _ in range(1 + n)] # for i in range(1, 1 + n): # for j in range(1, 1 + n): # cum_array[i][j] = ( # cum_array[i][j - 1] # + cum_array[i - 1][j] # - cum_array[i - 1][j - 1] # + ((i, j) in points) # ) cum_array = np.zeros((n + 1, n + 1), dtype=np.int) for x, y in points: cum_array[x, y] = 1 cum_array = np.cumsum(cum_array, 0) cum_array = np.cumsum(cum_array, 1) ans = 0 for x, y in points: n0 = cum_array[x - 1][y - 1] n1 = cum_array[n][y] - cum_array[x][y] n2 = cum_array[x][n] - cum_array[x][y] n3 = n - cum_array[n][y] - cum_array[x][n] + cum_array[x][y] counts = [n0, n1, n2, n3] for exist in product([False, True], repeat=4): # Trueならあり tmp = 1 for e, c in zip(exist, counts): if e: tmp *= (2**c) % mod - 1 if (exist[1] & exist[2]) | (exist[0] & exist[3]): tmp *= 2 ans += tmp ans %= mod print(ans)
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s218626537
Accepted
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
import sys input = sys.stdin.readline n = int(input()) l = [list(map(int, input().split())) for i in range(n)] mod = 998244353 from operator import itemgetter l.sort(key=itemgetter(1)) for i in range(n): l[i][1] = i l.sort(key=itemgetter(0)) No = 2 while No <= n: No *= 2 tree = [0] * (2 * No) def add(k, x): k += No - 1 while k >= 0: tree[k] += x k = (k - 1) // 2 def query(l, r): L = l + No - 1 R = r + No - 1 s = 0 while L <= R: if R & 1: s += tree[R] R -= 2 else: R -= 1 if L & 1: L -= 1 else: s += tree[L] L >>= 1 R >>= 1 return s pow2 = [1 for i in range(n + 2)] t = 2 for i in range(1, n + 2): pow2[i] = t t *= 2 t %= mod ans = 0 for x, y in l: lu = query(y, n) ld = query(0, y) ru = n - 1 - y - lu rd = y - ld ans += ( pow2[n - 1] + (pow2[lu] - 1) * (pow2[rd] - 1) % mod * (pow2[ru] + pow2[ld] - 1 + (pow2[ld] - 1) * (pow2[ru] - 1)) % mod + (pow2[ld] - 1) * (pow2[ru] - 1) % mod * (pow2[rd] + pow2[lu] - 1) % mod ) ans %= mod add(y, 1) print(ans)
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s494710331
Accepted
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines class Seg_sum: def __init__(self, x): #####単位元###### self.ide_ele_min = 0 self.func = lambda a, b: a + b self.n = len(x) # num_max:n以上の最小の2のべき乗 self.num_max = 2 ** (self.n - 1).bit_length() self.x = [self.ide_ele_min] * 2 * self.num_max for i, num in enumerate(x, self.num_max): self.x[i] = num for i in range(self.num_max - 1, 0, -1): self.x[i] = self.func(self.x[i << 1], self.x[(i << 1) + 1]) def update(self, i, x): i += self.num_max self.x[i] = x while i > 0: i = i // 2 self.x[i] = self.func(self.x[i << 1], self.x[(i << 1) + 1]) def query(self, i, j): res = self.ide_ele_min if i >= j: return res i += self.num_max j += self.num_max - 1 while i <= j: if i == j: res = self.func(res, self.x[i]) break if i & 1: res = self.func(res, self.x[i]) i += 1 if not j & 1: res = self.func(res, self.x[j]) j -= 1 i = i >> 1 j = j >> 1 return res n = int(readline()) xy = [list(map(int, i.split())) for i in readlines()] mod = 998244353 xy.sort() ys = [i[1] for i in xy] ys.sort() y_rank = {} for i, y in enumerate(ys): y_rank[y] = i point = [[0, 0] for _ in range(n)] for i, (x, y) in enumerate(xy): point[i][0] = i point[i][1] = y_rank[y] seg = Seg_sum([0] * (n + 10)) cnt = [[0, 0, 0, 0] for _ in range(n)] for x, y in point: cnt[x][2] = seg.query(0, y) cnt[x][1] = seg.query(y, n) cnt[x][0] = n - y - 1 - cnt[x][1] cnt[x][3] = y - cnt[x][2] seg.update(y, 1) ex2 = [1] * (n) for i in range(1, n): ex2[i] = (ex2[i - 1] * 2) % mod ans = (ex2[n - 1] * n) % mod for n1, n2, n3, n4 in cnt: ans += (ex2[n1] - 1) * (ex2[n3] - 1) * ex2[n2 + n4] ans %= mod ans += (ex2[n2] - 1) * (ex2[n4] - 1) * ex2[n1 + n3] ans %= mod ans -= (ex2[n1] - 1) * (ex2[n2] - 1) * (ex2[n3] - 1) * (ex2[n4] - 1) ans %= mod print(ans)
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s697679366
Wrong Answer
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
import sys import numpy as np import numba from numba import njit i8 = numba.int64 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 @njit((i8[:],), cache=True) def build(raw_data): bit = raw_data.copy() for i in range(len(bit)): j = i + (i & (-i)) if j < len(bit): bit[j] += bit[i] return bit @njit((i8[:], i8), cache=True) def get_sum(bit, i): s = 0 while i: s += bit[i] i -= i & -i return s @njit((i8[:], i8, i8), cache=True) def add(bit, i, x): while i < len(bit): bit[i] += x i += i & -i @njit((i8[:], i8), cache=True) def find_kth_element(bit, k): N = len(bit) x, sx = 0, 0 dx = 1 while 2 * dx < N: dx *= 2 while dx: y = x + dx if y < N: sy = sx + bit[y] if sy < k: x, sx = y, sy dx //= 2 return x + 1 @njit((i8[:],), cache=True) def main(XY): X, Y = XY[::2], XY[1::2] N = len(Y) ind = X.argsort() X, Y = X[ind], Y[ind] # 座圧 Y_sort = Y.copy() Y_sort.sort() Y = np.searchsorted(Y_sort, Y, "right") bit = np.zeros(N + 10, np.int64) pow2 = np.ones(N + 10, np.int64) for n in range(1, N + 10): pow2[n] = 2 * pow2[n - 1] % MOD ret = 0 for i in range(N): y = Y[i] L = i R = N - 1 - i LD = get_sum(bit, y) add(bit, y, 1) LU = L - LD D = y - 1 U = N - 1 - D RD = D - LD RU = R - RD x = pow2[N] - 1 x -= pow2[L] + pow2[R] + pow2[D] + pow2[U] x += pow2[LD] + pow2[LU] + pow2[RD] + pow2[RU] ret += x return ret % MOD N = int(readline()) XY = np.array(read().split(), np.int64) print(main(XY))
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s960454105
Wrong Answer
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
mod = 998244353 N = int(input()) x = [0 for i in range(N)] y = [0 for i in range(N)] for i in range(N): x[i], y[i] = map(int, input().split()) # f(T)を求めて各f(T)の値に対してその値を取りうるTの状態数を求める # |f^-1(k)|を各1<=k<=Nで求める # f(T)>0 # f^-1(1)={{1},{2},...,{N}} # f^-1(2)=x座標またはy座標の順番が連続していればOK 高々2(N-1) # f^-1(3)=xmin~xmaxとymin~ymaxの間に共通部分が存在しなければOK # f(T)=kのときTの要素数はk以下 # dpとか? # Tがf^-1(k)の元であるとき,p not in Tにおいて # T cup {p}がf^-1(T)の元であるようなものはどれだけ存在するのか? # どこまで削られるかを測定するとか? # x座標かy座標が連続であるものに辺を結べばグラフになる # でも木にはならない # 連結性をうまい感じに判断すればいけるのでは? # サンプルの2つめは(1,4)と(1,2,4)の部分だけ余計に点が入ってしまう # その点は3 # |T|=2のときはグラフにしたときの最短パスの長さになりそう # (1,2,4)のときは、連結なのにうまくいってない # 1,4の2を経由しないルートが必要なのだろうか? print((N * pow(2, N - 1, mod)) % mod) #   終 # お わ り # 制作・著作 # ----- # N H K
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s816903030
Wrong Answer
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
N = int(input()) S = str(input()) ans = 0 a = 0 for i in range(1, N): X = S[:i] Y = S[i:] lis = list(set(X)) for j in range(len(lis)): if Y.count(X[j]) != 0: a += 1 if a > ans: ans = a a = 0 print(ans)
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s380840597
Wrong Answer
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
import random MOD = 998244353 print(int(random.random() * MOD))
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s021680068
Wrong Answer
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
N = int(input()) point = [list(map(int, input().split())) for i in range(N)] x = [] y = [] for p in point: x.append(p[0]) y.append(p[1]) x.sort() y.sort() x_dict = {} y_dict = {} for i in range(len(x)): x_dict[x[i]] = i for i in range(len(y)): y_dict[y[i]] = i
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s402469436
Accepted
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
MOD = 998244353 import bisect import sys input = sys.stdin.readline N = int(input()) P = [list(map(int, input().split())) for i in [0] * N] class SegmentTree: def __init__(self, data): N = len(data) self.l = 2 ** ((N - 1).bit_length()) self.data = [0] * self.l + data + [0] * (self.l - N) for i in range(self.l - 1, 0, -1): self.data[i] = self.data[2 * i] + self.data[2 * i + 1] def set(self, i, val): i += self.l self.data[i] = val i = i // 2 while i > 0: self.data[i] = self.data[2 * i] + self.data[2 * i + 1] i = i // 2 def get(self, i, j): i += self.l j += self.l s = 0 while j - i > 0: if i & 1: s += self.data[i] i += 1 if j & 1: s += self.data[j - 1] j -= 1 i = i // 2 j = j // 2 return s X, Y = map(list, zip(*P)) X.sort() Y.sort() compY = {y: cy for cy, y in enumerate(Y)} Psorted = sorted(P) compP = [[n, compY[y]] for n, (_, y) in enumerate(Psorted)] n1s = [] seg = SegmentTree([0] * N) for _, y in compP[::-1]: n1s.append(seg.get(y, N)) seg.set(y, 1) n1s = n1s[::-1] pows = [1] for i in range(1, N): pows.append((pows[-1] * 2) % MOD) ans = (-4 * sum(pows) - N + N * pow(2, N, MOD)) % MOD for n, (x, y) in enumerate(Psorted): lower = bisect.bisect_left(Y, y) upper = N - 1 - lower left = n right = N - n - 1 n1 = n1s[n] n2 = upper - n1 n3 = left - n2 n4 = right - n1 ans += pows[n1] + pows[n2] + pows[n3] + pows[n4] ans %= MOD print(ans)
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s772609199
Wrong Answer
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) """ f(T)=iなるTの通り数を数えるか, f(T)=1がN通り,f(T)=Nはいっぱい.上下左右それぞれのmaxを選び,中のものがm個であるとき2^m通り x座標,y座標が全て相異なるのが嬉しいかも,でも,これめんどくさすぎる ある1つの点が与える寄与を考える, その頂点をTに含む場合=>必ず+1 * 2^(N-1)通り その頂点をTに含まない場合 (右上から1つ以上,左下から1つ以上),(右下から1つ以上,左上から1つ以上)の組なら加算 これらの組みは重複しそうなので,うまく被らないように選ぶ必要あり (右上,左下,左上0,右下0),(右上,左下,左上,右下0),(右上,左下,左上0,右下)みたいに分けて考える. でも,各頂点ごとに4つの方向それぞれの頂点数を持つのがまず難しい. 頂点を左から順に走査.左にある頂点の個数を上下別に見ていく. (左上,左下)を考える. 一番左なら(0,0),次のものは(0,1) or (1,0)みたいな.見た頂点のy座標(座圧したもの)をsegTreeで管理すれば,上下の個数がそれぞれわかる. 終わったら右からもやれば4方向それぞれの個数が分かりそう. """ def main(): mod = 10**9 + 7 class SegTree: def __init__(self, N, ide, segfunc=min): self.ide_ele = ide """ ex) 最小値のセグ木 → +inf 和のセグ木 → 0 積のセグ木 → 1 gcdのセグ木 → 0 """ self.segfunc = segfunc # num:N以上の最小の2のべき乗 self.num = 2 ** (N - 1).bit_length() self.seg = [self.ide_ele] * 2 * self.num # リストで初期化する def setL(self, init_val): # init_valは操作する数列 for i in range(self.num): self.seg[i + self.num - 1] = init_val[i] # built for i in range(self.num - 2, -1, -1): self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) # k番目の値をxに更新 def update(self, k, x): k += self.num - 1 self.seg[k] = x while k: k = (k - 1) // 2 self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) # [p,q)の区間に対するクエリへの応答 def query(self, p, q): if q <= p: return self.ide_ele p += self.num - 1 q += self.num - 2 res = self.ide_ele while q - p > 1: if p & 1 == 0: res = self.segfunc(res, self.seg[p]) if q & 1 == 1: res = self.segfunc(res, self.seg[q]) q -= 1 p = p // 2 q = (q - 1) // 2 if p == q: res = self.segfunc(res, self.seg[p]) else: res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q]) return res N = I() Y = [0] * N from collections import defaultdict ddy = defaultdict(int) L = [[0, 0, 0] for _ in range(N)] # x,y,i for i in range(N): x, y = MI() Y[i] = y L[i] = [x, y, i] # 座圧 Y.sort() for i in range(N): ddy[Y[i]] = i # 2べき持っておく POW = [1] for i in range(N + 5): p = (POW[-1] * 2) % mod POW.append(p) cnt = [[0, 0, 0, 0] for _ in range(N)] # lu,ld,ru,rd # 左から見る L.sort() # print(L) seg = SegTree(N, 0, lambda a, b: a + b) for j in range(N): # j個すでに見た i = L[j][2] # 番号iの頂点 y = L[j][1] yy = ddy[y] temp = seg.query(yy, N) # 上側の個数 cnt[i][0] = temp cnt[i][1] = j - temp # print(j,i,yy,temp) seg.update(yy, 1) # 右から見る seg = SegTree(N, 0, lambda a, b: a + b) for j in range(N): # j個すでに見た i = L[-1 - j][2] # 番号iの頂点 y = L[-1 - j][1] yy = ddy[y] temp = seg.query(yy, N) # 上側の個数 cnt[i][2] = temp cnt[i][3] = j - temp seg.update(yy, 1) def calc(cnt_item): # 引数:lu,ld,ru,rdの個数 lu, ld, ru, rd = cnt_item temp = POW[N - 1] # 自身がTにある場合,周りはなんでもOK # 自身がTにない場合 # oxxx temp += ((POW[lu] - 1) * (POW[rd] - 1)) % mod # xoox temp += ((POW[ld] - 1) * (POW[ru] - 1)) % mod # ooox temp += ((POW[lu] - 1) * (POW[ld] - 1) * (POW[ru] - 1)) % mod # ooxo temp += ((POW[lu] - 1) * (POW[ld] - 1) * (POW[rd] - 1)) % mod # oxoo temp += ((POW[lu] - 1) * (POW[ru] - 1) * (POW[rd] - 1)) % mod # xooo temp += ((POW[ld] - 1) * (POW[ru] - 1) * (POW[rd] - 1)) % mod # oooo temp += ((POW[lu] - 1) * (POW[ld] - 1) * (POW[ru] - 1) * (POW[rd] - 1)) % mod temp %= mod # print(cnt_item,temp) return temp ans = 0 for i in range(N): # print(i) ans = (ans + calc(cnt[i])) % mod print(ans) main()
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s050162988
Accepted
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
def f_encolsed_points(MOD=998244353): # 参考: https://atcoder.jp/contests/abc136/submissions/6696160 import sys input = sys.stdin.readline class BIT(object): """Binary Indexed Tree (1-indexed)""" def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, index): """tree[1]からtree[index]までの和を計算""" ret = 0 while index > 0: ret += self.tree[index] index -= index & (-index) return ret def add(self, index, value=1): """tree[index]にvalueを加算""" while index <= self.size: self.tree[index] += value index += index & (-index) N = int(input()) Pos = [[int(i) for i in input().split()] for j in range(N)] Pos.sort() # x座標でソートする _, pos_y = zip(*Pos) y_comp = {y: i for i, y in enumerate(sorted(pos_y), 1)} # y座標を圧縮 pow_2 = [1] for _ in range(N): pow_2.append(pow_2[-1] * 2 % MOD) ans = 0 tree = BIT(N) # x座標が小さな点から順に考える for left, (_x, _y) in enumerate(Pos): y = y_comp[_y] # それぞれ、注目している点の 右|下|上 にいくつ点が存在するか right = N - 1 - left down = y - 1 up = N - 1 - down lower_left = tree.sum(y) tree.add(y, 1) upper_left = left - lower_left lower_right = down - lower_left upper_right = right - lower_right # 包除原理(全体 - 上下左右 + 左上左下右上右下 - それ自体) count = ( pow_2[N] - (pow_2[up] + pow_2[down] + pow_2[left] + pow_2[right]) + ( pow_2[upper_left] + pow_2[lower_left] + pow_2[upper_right] + pow_2[lower_right] ) - 1 ) ans += count ans %= MOD return ans print(f_encolsed_points())
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. * * *
s153401106
Accepted
p02956
Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N
import sys from operator import itemgetter input = sys.stdin.readline def compress_coordinate(x: list, key=None, reverse=False): zipped = {} unzipped = {} for i, xi in enumerate(sorted(set(x), key=None, reverse=reverse)): zipped[xi] = i + 1 unzipped[i + 1] = xi return zipped, unzipped class BIT1: """ Binary Indexed Tree (1-indexed) """ def __init__(self, n): self.n = n self.bit = [0] * (self.n + 1) def add(self, idx, x): # add x to idx-th element # idx: 1-indexed while idx <= self.n: self.bit[idx] += x idx += idx & (-idx) def sum(self, idx): # get sum of [1, idx] # idx: 1-indexed s = 0 while idx: s += self.bit[idx] idx -= idx & (-idx) return s def bisect_left(self, w): # condition : always all element is not minus # return minimum idx where bit.sum(idx) >= w if w <= 0: return 0 idx = 0 # self.bit[idx] < w k = 1 << ((self.n).bit_length() - 1) while k > 0: if idx + k <= self.n and self.bit[idx + k] < w: w -= self.bit[idx + k] idx += k k = k >> 1 return idx + 1 MOD = 998244353 n = int(input()) x_list = [] y_list = [] for i in range(n): x, y = map(int, input().split()) x_list.append(x) y_list.append(y) x_zipped, x_unzipped = compress_coordinate(x_list) y_zipped, y_unzipped = compress_coordinate(y_list) p = [] for i, (x, y) in enumerate(zip(x_list, y_list)): p.append((x_zipped[x], y_zipped[y], i)) info = [[0] * 5 for _ in range(n)] p.sort(key=itemgetter(0)) # print(*p) bit1 = BIT1(n) for m, (px, py, idx) in enumerate(p): bit1.add(py, 1) s_left = bit1.sum(py) - 1 s_right = (m + 1) - s_left - 1 info[idx][2] = s_right info[idx][3] = s_left p.sort(key=itemgetter(0), reverse=True) # print(*p) bit2 = BIT1(n) for m, (px, py, idx) in enumerate(p): bit2.add(py, 1) s_left = bit2.sum(py) - 1 s_right = (m + 1) - s_left - 1 info[idx][1] = s_right info[idx][4] = s_left ans = 0 for _, c1, c2, c3, c4 in info: c1 = pow(2, c1, MOD) - 1 c2 = pow(2, c2, MOD) - 1 c3 = pow(2, c3, MOD) - 1 c4 = pow(2, c4, MOD) - 1 ans += 1 ans += c1 + c2 + c3 + c4 ans += c1 * c3 * 2 + c2 * c4 * 2 ans += c1 * c2 + c2 * c3 + c3 * c4 + c4 * c1 ans += (c2 * c3 * c4 + c1 * c3 * c4 + c1 * c2 * c4 + c1 * c2 * c3) * 2 ans += c1 * c2 * c3 * c4 * 2 ans %= MOD # print(*info, sep='\n') print(ans)
Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.
[{"input": "3\n -1 3\n 2 1\n 3 -2", "output": "13\n \n\nLet the first, second, and third points be P_1, P_2, and P_3, respectively. S\n= \\\\{P_1, P_2, P_3\\\\} has seven non-empty subsets, and f has the following\nvalues for each of them:\n\n * f(\\\\{P_1\\\\}) = 1\n * f(\\\\{P_2\\\\}) = 1\n * f(\\\\{P_3\\\\}) = 1\n * f(\\\\{P_1, P_2\\\\}) = 2\n * f(\\\\{P_2, P_3\\\\}) = 2\n * f(\\\\{P_3, P_1\\\\}) = 3\n * f(\\\\{P_1, P_2, P_3\\\\}) = 3\n\nThe sum of these is 13.\n\n* * *"}, {"input": "4\n 1 4\n 2 1\n 3 3\n 4 2", "output": "34\n \n\n* * *"}, {"input": "10\n 19 -11\n -3 -12\n 5 3\n 3 -15\n 8 -14\n -9 -20\n 10 -9\n 0 2\n -7 17\n 6 -6", "output": "7222\n \n\nBe sure to print the sum modulo 998244353."}]
Print the answer. * * *
s747896517
Runtime Error
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
N = int(input()) mean = 0 frames = [] for i range(N): frames.append(int(input())) mean += frames[i] mean = mean / N sa = 100 ind = 0 for i in range(N): if sa > abs(frames[i] - mean): sa = abs(frames[i] - mean) ind = i print(ind)
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
Print the answer. * * *
s719043477
Accepted
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations, groupby import sys import bisect import string import math import time import random def S_(): return input() def LS(): return [i for i in input().split()] def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i) - 1 for i in input().split()] def NI(n): return [int(input()) for i in range(n)] def NI_(n): return [int(input()) - 1 for i in range(n)] def StoI(): return [ord(i) - 97 for i in input()] def ItoS(nn): return chr(nn + 97) def LtoS(ls): return "".join([chr(i + 97) for i in ls]) def GI(V, E, Directed=False, index=0): org_inp = [] g = [[] for i in range(n)] for i in range(E): inp = LI() org_inp.append(inp) if index == 0: inp[0] -= 1 inp[1] -= 1 if len(inp) == 2: a, b = inp g[a].append(b) if not Directed: g[b].append(a) elif len(inp) == 3: a, b, c = inp aa = (inp[0], inp[2]) bb = (inp[1], inp[2]) g[a].append(bb) if not Directed: g[b].append(aa) return g, org_inp def bit_combination(k, n=2): rt = [] for tb in range(n**k): s = [tb // (n**bt) % n for bt in range(k)] rt += [s] return rt def show(*inp, end="\n"): if show_flg: print(*inp, end=end) YN = ["Yes", "No"] mo = 10**9 + 7 inf = float("inf") l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() # sys.setrecursionlimit(10**5) input = lambda: sys.stdin.readline().rstrip() import fractions # gcd=fractions.gcd def ran_input(): import random n = random.randint(4, 16) rmin, rmax = 1, 10 a = [random.randint(rmin, rmax) for _ in range(n)] return n, a class Comb: def __init__(self, n, mo=10**9 + 7): self.fac = [0] * (n + 1) self.inv = [1] * (n + 1) self.fac[0] = 1 self.fact(n) for i in range(1, n + 1): self.fac[i] = i * self.fac[i - 1] % mo self.inv[n] *= i self.inv[n] %= mo self.inv[n] = pow(self.inv[n], mo - 2, mo) for i in range(1, n): self.inv[n - i] = self.inv[n - i + 1] * (n - i + 1) % mo return def fact(self, n): return self.fac[n] def invf(self, n): return self.inv[n] def comb(self, x, y): if y < 0 or y > x: return 0 return self.fac[x] * self.inv[x - y] * self.inv[y] % mo show_flg = False show_flg = True def gcd(x, y): while y != 0: x, y = y, x % y return x ans = 0 n = I() a = LI() av = sum(a) / n m = min([abs(i - av) for i in a]) for i in range(n): if m == abs(a[i] - av): print(i) exit() # print(ans)
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
Print the answer. * * *
s004282329
Accepted
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
def examA(): N = I() A = LI() sumnale = sum(A) / N cur = 10**9 curL = 0 for i in range(N): if cur > abs(A[i] - sumnale): cur = abs(A[i] - sumnale) curL = i ans = curL print(ans) return import sys, copy, bisect, itertools, heapq, math from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() mod = 10**9 + 7 inf = float("inf") if __name__ == "__main__": examA()
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
Print the answer. * * *
s133736015
Accepted
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
import sys import heapq import re from heapq import heapify, heappop, heappush from itertools import permutations from bisect import bisect_left, bisect_right from collections import Counter, deque from fractions import gcd from math import factorial, sqrt, ceil from functools import lru_cache, reduce INF = 1 << 60 MOD = 1000000007 sys.setrecursionlimit(10**7) # UnionFind class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) # ダイクストラ def dijkstra_heap(s, edge, n): # 始点sから各頂点への最短距離 d = [10**20] * n used = [True] * n # True:未確定 d[s] = 0 used[s] = False edgelist = [] for a, b in edge[s]: heapq.heappush(edgelist, a * (10**6) + b) while len(edgelist): minedge = heapq.heappop(edgelist) # まだ使われてない頂点の中から最小の距離のものを探す if not used[minedge % (10**6)]: continue v = minedge % (10**6) d[v] = minedge // (10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1]) return d # 素因数分解 def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr # 2数の最小公倍数 def lcm(x, y): return (x * y) // gcd(x, y) # リストの要素の最小公倍数 def lcm_list(numbers): return reduce(lcm, numbers, 1) # リストの要素の最大公約数 def gcd_list(numbers): return reduce(gcd, numbers) # 素数判定 def is_prime(n): if n <= 1: return False p = 2 while True: if p**2 > n: break if n % p == 0: return False p += 1 return True # limit以下の素数を列挙 def eratosthenes(limit): A = [i for i in range(2, limit + 1)] P = [] while True: prime = min(A) if prime > sqrt(limit): break P.append(prime) i = 0 while i < len(A): if A[i] % prime == 0: A.pop(i) continue i += 1 for a in A: P.append(a) return P # 同じものを含む順列 def permutation_with_duplicates(L): if L == []: return [[]] else: ret = [] # set(集合)型で重複を削除、ソート S = sorted(set(L)) for i in S: data = L[:] data.remove(i) for j in permutation_with_duplicates(data): ret.append([i] + j) return ret # ここから書き始める n = int(input()) a = list(map(int, input().split())) average = sum(a) / n b = [abs(i - average) for i in a] # print("b =", b) diff = INF ans = 0 for i in range(n): if b[i] < diff: diff = b[i] ans = i print(ans)
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
Print the answer. * * *
s224691723
Accepted
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
# coding: utf-8 import re import math from collections import defaultdict import itertools from copy import deepcopy import random from heapq import heappop, heappush import time import os import queue import sys import datetime from functools import lru_cache readline = sys.stdin.readline sys.setrecursionlimit(2000) # import numpy as np alphabet = "abcdefghijklmnopqrstuvwxyz" mod = int(10**9 + 7) inf = int(10**20) def yn(b): if b: print("yes") else: print("no") def Yn(b): if b: print("Yes") else: print("No") def YN(b): if b: print("YES") else: print("NO") class union_find: def __init__(self, n): self.n = n self.P = [a for a in range(N)] self.rank = [0] * n def find(self, x): if x != self.P[x]: self.P[x] = self.find(self.P[x]) return self.P[x] def same(self, x, y): return self.find(x) == self.find(y) def link(self, x, y): if self.rank[x] < self.rank[y]: self.P[x] = y elif self.rank[y] < self.rank[x]: self.P[y] = x else: self.P[x] = y self.rank[y] += 1 def unite(self, x, y): self.link(self.find(x), self.find(y)) def size(self): S = set() for a in range(self.n): S.add(self.find(a)) return len(S) def is_power(a, b): # aはbの累乗数か now = b while now < a: now *= b if now == a: return True else: return False def bin_(num, size): A = [0] * size for a in range(size): if (num >> (size - a - 1)) & 1 == 1: A[a] = 1 else: A[a] = 0 return A def get_facs(n, mod_=0): A = [1] * (n + 1) for a in range(2, len(A)): A[a] = A[a - 1] * a if mod > 0: A[a] %= mod_ return A def comb(n, r, mod, fac): if n - r < 0: return 0 return (fac[n] * pow(fac[n - r], mod - 2, mod) * pow(fac[r], mod - 2, mod)) % mod def next_comb(num, size): x = num & (-num) y = num + x z = num & (~y) z //= x z = z >> 1 num = y | z if num >= (1 << size): return False else: return num def get_primes(n, type="int"): A = [True] * (n + 1) A[0] = False A[1] = False for a in range(2, n + 1): if A[a]: for b in range(a * 2, n + 1, a): A[b] = False if type == "bool": return A B = [] for a in range(n + 1): if A[a]: B.append(a) return B def is_prime(num): if num <= 2: return False i = 2 while i * i <= num: if num % i == 0: return False i += 1 return True def ifelse(a, b, c): if a: return b else: return c def join(A, c=" "): n = len(A) A = list(map(str, A)) s = "" for a in range(n): s += A[a] if a < n - 1: s += c return s def factorize(n, type_="dict"): b = 2 list_ = [] while b * b <= n: while n % b == 0: n //= b list_.append(b) b += 1 if n > 1: list_.append(n) if type_ == "dict": dic = {} for a in list_: if a in dic: dic[a] += 1 else: dic[a] = 1 return dic elif type_ == "list": return list_ else: return None def floor_(n, x=1): return x * (n // x) def ceil_(n, x=1): return x * ((n + x - 1) // x) ################################################### def main(): n = int(input()) A = list(map(int, input().split())) s = sum(A) mi = inf ans = inf for a in range(len(A) - 1, -1, -1): if abs(A[a] * len(A) - s) <= mi: mi = abs(A[a] * len(A) - s) ans = a print(ans) main()
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
Print the answer. * * *
s611080642
Accepted
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
n = int(input()) a = list(int(i) for i in input().split()) average = sum(a) query = [] for i in a: query.append(abs(n * i - average)) print(query.index(min(query)))
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
Print the answer. * * *
s891857985
Wrong Answer
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
print(int((int(input()) + 1) / 2))
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
Print the answer. * * *
s729648586
Accepted
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
n = int(input()) p = input() o = p.split() k = [] for i in range(n): k.append(int(o[i])) a = sum(k) / n l = 99999 m = None for i in range(n): w = k[i] if abs(w - a) < l: m = i l = abs(w - a) print(m)
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
Print the answer. * * *
s218852794
Runtime Error
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
N = int(input()) li = list(map(int, input()split())) s = sum(li) N = len(li) mean = s / N li_div = [] for i in range(N): div = abs(li[i] - mean) li_div.append(div) min_div = min(li_div) for i in range(N): if li_div == min_div: print(i) break
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
Print the answer. * * *
s980566160
Accepted
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
def main(): n = input() data = input().split() data = list(map(lambda x: int(x), data)) mid_val = calculate_mean(data) if int(n) < 1 or 101 < int(n): return -1 current_pos = -1 current_distance = 101 if int(n) == len(data): for key, value in enumerate(data): if int(value) < 1 or 101 < int(value): return -1 new_distance = abs(mid_val - value) if current_distance > new_distance: current_pos = key current_distance = new_distance return current_pos def calculate_mean(data): s = sum(data) N = len(data) mean = s / N return mean r = main() print(r)
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
Print the answer. * * *
s976745132
Runtime Error
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
from sys import stdin n, k = [int(x) for x in stdin.readline().rstrip().split()] data = [int(x) for x in stdin.readline().rstrip().split()] tmp = [] cnt = 0 for i in range(len(data)): for j in range(len(data) - i): tmp.append(((sum(data[i : 1 + i + j])))) cnt += 1 beat_v = sorted(tmp) tmp2 = list(map(lambda x: len(bin(x)), beat_v)) # 同じ桁のbit列がK個以上あるか探索 cnt2 = 0 maxbit = tmp2[-1] res = 0 for l in reversed(tmp2): if maxbit == l: cnt2 += 1 maxbit = l if cnt2 == k: res = maxbit break cnt3 = 0 for m in reversed(tmp2): if m != res: cnt3 += 1 else: break res_ = list(reversed(beat_v))[cnt3 : cnt3 + k] result = res_[0] for g in res_: result = result & g print(result)
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
Print the answer. * * *
s109617963
Runtime Error
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
import sys N = int(sys.stdin.readline()) S = list(sys.stdin.readline()) Q = int(sys.stdin.readline()) k = list(map(int, sys.stdin.readline().split(" "))) # chache = [] oms = [(i, S[i]) for i in range(N) if S[i] == "D" or S[i] == "M" or S[i] == "C"] oml = len(oms) def process(ki, index, selected="n"): global cache if index == oml: return [] if cache[index][selected] is not None: # print('use cache') return cache[index][selected] rets = [] # char = oms[index][1] if selected == "b": for ind in range(index, oml): char = oms[ind][1] if char == "C": rets.append(oms[ind][0]) elif selected == "a": for ind in range(index, oml): char = oms[ind][1] if char == "M": rets += process(ki, ind + 1, "b") else: for ind in range(index, oml): char = oms[ind][1] if char == "D": cind = process(ki, ind + 1, "a") ret = [] for v in cind: if v != False and ((v - oms[ind][0]) < ki): ret.append(True) rets += ret cache[index][selected] = rets return rets for ki in k: cache = [{"a": None, "b": None, "c": None, "n": None} for i in range(oml)] ret = process(ki, 0) print(len(ret))
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
Print the answer. * * *
s451529533
Runtime Error
p03214
Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1}
N = int(input()) a = sorted([(i, int(x)) for i, x in enumerate(input().split())], key=lambda x: x[1]) avg = sum([l[1] for l in a]) / N d = 999999999999 t = -1 pre = -1 for i, n in a: if n == pre: continue p = n - avg if n >= avg else avg - n if p == 0: t = i break elif p < d: d = p t = i elif: break print(t)
Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
[{"input": "3\n 1 2 3", "output": "1\n \n\nSince the average of frame representations is 2, Niwango-kun needs to select\nthe index 1, whose representation is 2, that is, the nearest value to the\naverage.\n\n* * *"}, {"input": "4\n 2 5 2 5", "output": "0\n \n\nThe average of frame representations is 3.5. \nIn this case, every frame has the same distance from its representation to the\naverage. \nTherefore, Niwango-kun should select index 0, the smallest index among them."}]
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
s660279965
Accepted
p00711
The input consists of multiple data sets. A data set starts with a line containing two positive integers _W_ and _H_ ; _W_ and _H_ are the numbers of tiles in the _x_ \- and _y_ \- directions, respectively. _W_ and _H_ are not more than 20. There are _H_ more lines in the data set, each of which includes _W_ characters. Each character represents the color of a tile as follows. * '.' - a black tile * '#' - a red tile * '@' - a man on a black tile(appears exactly once in a data set) The end of the input is indicated by a line consisting of two zeros.
import collections dx = [-1, 0, 1, 0] dy = [0, -1, 0, 1] def movable(dst): if dst[0] < 0 or dst[0] > b - 1: return False elif dst[1] < 0 or dst[1] > a - 1: return False elif MM[dst[0]][dst[1]] == "#": return False else: return True while True: c = 1 a, b = map(int, input().split()) if a == 0 and b == 0: exit() else: MM = [] for i in range(b): q = list(input()) MM.append(q) if "@" in q: st = [i, q.index("@")] D = [[-1 for _ in range(a)] for _ in range(b)] D[st[0]][st[1]] = 0 # 始点への距離は 0, 他の距離は-1 Q = collections.deque() Q.append(st) # 始点 while len(Q) > 0: # print("bfs", Q) # 各ステップでの Q の動作を確認 cur = Q.popleft() for dir in range(4): # curからdstに移動可能かつ、dstが未訪問だったら dst = [cur[0] + dx[dir], cur[1] + dy[dir]] # print(dst) if movable(dst) and D[dst[0]][dst[1]] == -1: D[dst[0]][dst[1]] = D[cur[0]][cur[1]] + 1 c += 1 Q.append(dst) # Qにdstを詰める print(c)
B: Red and Black There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. Write a program to count the number of black tiles which he can reach by repeating the moves described above.
[{"input": "9\n ....#.\n .....#\n ......\n ......\n ......\n ......\n ......\n #@...#\n .#..#.\n 11 9\n .#.........\n .#.#######.\n .#.#.....#.\n .#.#.###.#.\n .#.#..@#.#.\n .#.#####.#.\n .#.......#.\n .#########.\n ...........\n 11 6\n ..#..#..#..\n ..#..#..#..\n ..#..#..###\n ..#..#..#@.\n ..#..#..#..\n ..#..#..#..\n 7 7\n ..#.#..\n ..#.#..\n ###.###\n ...@...\n ###.###\n ..#.#..\n ..#.#..\n 0 0", "output": "59\n 6\n 13"}]
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
s424202397
Wrong Answer
p00711
The input consists of multiple data sets. A data set starts with a line containing two positive integers _W_ and _H_ ; _W_ and _H_ are the numbers of tiles in the _x_ \- and _y_ \- directions, respectively. _W_ and _H_ are not more than 20. There are _H_ more lines in the data set, each of which includes _W_ characters. Each character represents the color of a tile as follows. * '.' - a black tile * '#' - a red tile * '@' - a man on a black tile(appears exactly once in a data set) The end of the input is indicated by a line consisting of two zeros.
if __name__ == "__main__": while 1: w, h = list(map(int, input().strip().split())) if w == h == 0: break data = [] data = [] for _ in range(h): data.append(list(input())) visited = [] for i in range(h): if "@" in data[i]: stack = [(i, data[i].index("@"))] count = 0 while len(stack) != 0: y, x = stack.pop() count += 1 if y - 1 >= 0 and not (y - 1, x) in visited and data[y - 1][x] == ".": visited.append((y - 1, x)) stack.append((y - 1, x)) if x - 1 >= 0 and not (y, x - 1) in visited and data[y][x - 1] == ".": visited.append((y, x - 1)) stack.append((y, x - 1)) if y + 1 < h and not (y + 1, x) in visited and data[y + 1][x] == ".": visited.append((y + 1, x)) stack.append((y + 1, x)) if x + 1 < w and not (y, x + 1) in visited and data[y][x + 1] == ".": visited.append((y, x + 1)) stack.append((y, x + 1))
B: Red and Black There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. Write a program to count the number of black tiles which he can reach by repeating the moves described above.
[{"input": "9\n ....#.\n .....#\n ......\n ......\n ......\n ......\n ......\n #@...#\n .#..#.\n 11 9\n .#.........\n .#.#######.\n .#.#.....#.\n .#.#.###.#.\n .#.#..@#.#.\n .#.#####.#.\n .#.......#.\n .#########.\n ...........\n 11 6\n ..#..#..#..\n ..#..#..#..\n ..#..#..###\n ..#..#..#@.\n ..#..#..#..\n ..#..#..#..\n 7 7\n ..#.#..\n ..#.#..\n ###.###\n ...@...\n ###.###\n ..#.#..\n ..#.#..\n 0 0", "output": "59\n 6\n 13"}]
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
s518034133
Accepted
p00711
The input consists of multiple data sets. A data set starts with a line containing two positive integers _W_ and _H_ ; _W_ and _H_ are the numbers of tiles in the _x_ \- and _y_ \- directions, respectively. _W_ and _H_ are not more than 20. There are _H_ more lines in the data set, each of which includes _W_ characters. Each character represents the color of a tile as follows. * '.' - a black tile * '#' - a red tile * '@' - a man on a black tile(appears exactly once in a data set) The end of the input is indicated by a line consisting of two zeros.
from queue import Queue while True: w, h = map(int, input().split()) if w == h == 0: break tile = [input() for i in range(h)] for x, col in enumerate(tile): if "@" in col: y = col.index("@") s = (x, y) break visit = [[False for i in range(w)] for j in range(h)] dx = (0, -1, 1, 0) dy = (1, 0, 0, -1) que = Queue() que.put(s) while not que.empty(): x, y = que.get() if visit[x][y]: continue visit[x][y] = True for j in range(4): sx = x + dx[j] sy = y + dy[j] if sx < 0 or sx >= h or sy < 0 or sy >= w: continue if tile[sx][sy] != "#": que.put((sx, sy)) ans = 0 for col in visit: ans += col.count(True) print(ans)
B: Red and Black There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. Write a program to count the number of black tiles which he can reach by repeating the moves described above.
[{"input": "9\n ....#.\n .....#\n ......\n ......\n ......\n ......\n ......\n #@...#\n .#..#.\n 11 9\n .#.........\n .#.#######.\n .#.#.....#.\n .#.#.###.#.\n .#.#..@#.#.\n .#.#####.#.\n .#.......#.\n .#########.\n ...........\n 11 6\n ..#..#..#..\n ..#..#..#..\n ..#..#..###\n ..#..#..#@.\n ..#..#..#..\n ..#..#..#..\n 7 7\n ..#.#..\n ..#.#..\n ###.###\n ...@...\n ###.###\n ..#.#..\n ..#.#..\n 0 0", "output": "59\n 6\n 13"}]
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
s669243932
Accepted
p00711
The input consists of multiple data sets. A data set starts with a line containing two positive integers _W_ and _H_ ; _W_ and _H_ are the numbers of tiles in the _x_ \- and _y_ \- directions, respectively. _W_ and _H_ are not more than 20. There are _H_ more lines in the data set, each of which includes _W_ characters. Each character represents the color of a tile as follows. * '.' - a black tile * '#' - a red tile * '@' - a man on a black tile(appears exactly once in a data set) The end of the input is indicated by a line consisting of two zeros.
def dfs(graph, sx, sy): stack = [[sx, sy]] visited = [] cnt = 0 while stack: label = stack.pop(0) try: g = graph[label[1]][label[0]] if (label[0] < 0) or (label[0] > graph[0].__len__() - 1): continue if (label[1] < 0) or (label[1] > graph.__len__() - 1): continue if g == "#": continue if [label[0], label[1]] not in visited: # graph[label[1], label[0]] = '#' cnt += 1 visited = [[label[0], label[1]]] + visited stack = [ [label[0] + 1, label[1]], [label[0] - 1, label[1]], [label[0], label[1] + 1], [label[0], label[1] - 1], ] + stack except IndexError: pass return cnt if __name__ == "__main__": STR = [] W, H = [int(i) for i in input().split()] while W != 0: for j in range(H): STR.append(list(input())) if "@" in STR[j]: sx, sy = STR[j].index("@"), j print(dfs(STR, sx, sy)) STR = [] W, H = [int(i) for i in input().split()]
B: Red and Black There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. Write a program to count the number of black tiles which he can reach by repeating the moves described above.
[{"input": "9\n ....#.\n .....#\n ......\n ......\n ......\n ......\n ......\n #@...#\n .#..#.\n 11 9\n .#.........\n .#.#######.\n .#.#.....#.\n .#.#.###.#.\n .#.#..@#.#.\n .#.#####.#.\n .#.......#.\n .#########.\n ...........\n 11 6\n ..#..#..#..\n ..#..#..#..\n ..#..#..###\n ..#..#..#@.\n ..#..#..#..\n ..#..#..#..\n 7 7\n ..#.#..\n ..#.#..\n ###.###\n ...@...\n ###.###\n ..#.#..\n ..#.#..\n 0 0", "output": "59\n 6\n 13"}]
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
s035382557
Accepted
p00711
The input consists of multiple data sets. A data set starts with a line containing two positive integers _W_ and _H_ ; _W_ and _H_ are the numbers of tiles in the _x_ \- and _y_ \- directions, respectively. _W_ and _H_ are not more than 20. There are _H_ more lines in the data set, each of which includes _W_ characters. Each character represents the color of a tile as follows. * '.' - a black tile * '#' - a red tile * '@' - a man on a black tile(appears exactly once in a data set) The end of the input is indicated by a line consisting of two zeros.
import collections while True: w, h = map(int, input().split()) if w == h == 0: break else: ans = 1 L = [] q = collections.deque() for i in range(h): s = input() T = [] for j in range(w): if s[j] == "@": T.append(0) q.append([i, j]) else: T.append(s[j]) L.append(T) dy_dx = [[1, 0], [0, 1], [-1, 0], [0, -1]] while len(q) > 0: cur = q.popleft() for i in range(4): y = cur[0] + dy_dx[i][0] x = cur[1] + dy_dx[i][1] if 0 <= x < w and 0 <= y < h: if L[y][x] == ".": L[y][x] = L[cur[0]][cur[1]] + 1 ans += 1 q.append([y, x]) print(ans)
B: Red and Black There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. Write a program to count the number of black tiles which he can reach by repeating the moves described above.
[{"input": "9\n ....#.\n .....#\n ......\n ......\n ......\n ......\n ......\n #@...#\n .#..#.\n 11 9\n .#.........\n .#.#######.\n .#.#.....#.\n .#.#.###.#.\n .#.#..@#.#.\n .#.#####.#.\n .#.......#.\n .#########.\n ...........\n 11 6\n ..#..#..#..\n ..#..#..#..\n ..#..#..###\n ..#..#..#@.\n ..#..#..#..\n ..#..#..#..\n 7 7\n ..#.#..\n ..#.#..\n ###.###\n ...@...\n ###.###\n ..#.#..\n ..#.#..\n 0 0", "output": "59\n 6\n 13"}]
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
s022383468
Accepted
p00711
The input consists of multiple data sets. A data set starts with a line containing two positive integers _W_ and _H_ ; _W_ and _H_ are the numbers of tiles in the _x_ \- and _y_ \- directions, respectively. _W_ and _H_ are not more than 20. There are _H_ more lines in the data set, each of which includes _W_ characters. Each character represents the color of a tile as follows. * '.' - a black tile * '#' - a red tile * '@' - a man on a black tile(appears exactly once in a data set) The end of the input is indicated by a line consisting of two zeros.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import array import collections import itertools class DepthFirstSearchWithStack(object): def __init__(self, width, height, tiles): self.width = width self.height = height self.tiles = tiles self.reached = [ array.array("B", (False for y in range(height))) for x in range(width) ] for x, y in itertools.product(range(width), range(height)): if tiles[x][y] == "@": self.start_tile = (x, y) break def search(self, x0, y0): stack = collections.deque() self.reached[x0][y0] = True stack.append((x0, y0)) while stack: (x, y) = stack.pop() for i, j in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]: if i < 0 or self.width <= i or j < 0 or self.height <= j: pass elif self.tiles[i][j] == "#": pass elif not self.reached[i][j]: self.reached[i][j] = True stack.append((i, j)) def count_reachable_tiles(self): self.search(*self.start_tile) reachable_tiles = sum( [ self.reached[x][y] for x, y in itertools.product(range(self.width), range(self.height)) ] ) return reachable_tiles if __name__ == "__main__": while True: width, height = map(int, input().split()) if width == 0 and height == 0: break else: tiles = [x for x in zip(*[input() for y in range(height)])] dfs = DepthFirstSearchWithStack(width, height, tiles) print(dfs.count_reachable_tiles())
B: Red and Black There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. Write a program to count the number of black tiles which he can reach by repeating the moves described above.
[{"input": "9\n ....#.\n .....#\n ......\n ......\n ......\n ......\n ......\n #@...#\n .#..#.\n 11 9\n .#.........\n .#.#######.\n .#.#.....#.\n .#.#.###.#.\n .#.#..@#.#.\n .#.#####.#.\n .#.......#.\n .#########.\n ...........\n 11 6\n ..#..#..#..\n ..#..#..#..\n ..#..#..###\n ..#..#..#@.\n ..#..#..#..\n ..#..#..#..\n 7 7\n ..#.#..\n ..#.#..\n ###.###\n ...@...\n ###.###\n ..#.#..\n ..#.#..\n 0 0", "output": "59\n 6\n 13"}]
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
s464988959
Runtime Error
p00711
The input consists of multiple data sets. A data set starts with a line containing two positive integers _W_ and _H_ ; _W_ and _H_ are the numbers of tiles in the _x_ \- and _y_ \- directions, respectively. _W_ and _H_ are not more than 20. There are _H_ more lines in the data set, each of which includes _W_ characters. Each character represents the color of a tile as follows. * '.' - a black tile * '#' - a red tile * '@' - a man on a black tile(appears exactly once in a data set) The end of the input is indicated by a line consisting of two zeros.
while True: W, H = [int(x) for x in input().split()] if W == 0 and H == 0: exit() tiles = [] X = 0 Y = 0 for i in range(H): tiles.append(input()) if "@" in tiles[i]: Y = i X = tiles[i].index("@") d = [[9999 for j in range(H * W)] for i in range(H * W)] for i in range(H * W): d[i][i] = 0 for i in range(H): for j in range(W): if j > 0: if tiles[i][j] in ".@" and tiles[i][j - 1] in ".@": d[W * i + j][W * i + j - 1] = 1 if j < W - 1: if tiles[i][j] in ".@" and tiles[i][j + 1] in ".@": d[W * i + j][W * i + j + 1] = 1 if i > 0: if tiles[i][j] in ".@" and tiles[i - 1][j] in ".@": d[W * i + j][W * i + j - W] = 1 if j < H - 1: if tiles[i][j] in ".@" and tiles[i + 1][j] in ".@": d[W * i + j][W * i + j + W] = 1 for k in range(H * W): for i in range(H * W): for j in range(H * W): if d[i][j] > d[i][k] + d[k][j]: d[i][j] = d[i][k] + d[k][j] cnt = 0 for i in range(H * W): if d[X + Y * H][i] < 9999: cnt += 1 print(cnt)
B: Red and Black There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. Write a program to count the number of black tiles which he can reach by repeating the moves described above.
[{"input": "9\n ....#.\n .....#\n ......\n ......\n ......\n ......\n ......\n #@...#\n .#..#.\n 11 9\n .#.........\n .#.#######.\n .#.#.....#.\n .#.#.###.#.\n .#.#..@#.#.\n .#.#####.#.\n .#.......#.\n .#########.\n ...........\n 11 6\n ..#..#..#..\n ..#..#..#..\n ..#..#..###\n ..#..#..#@.\n ..#..#..#..\n ..#..#..#..\n 7 7\n ..#.#..\n ..#.#..\n ###.###\n ...@...\n ###.###\n ..#.#..\n ..#.#..\n 0 0", "output": "59\n 6\n 13"}]
Print the lexicographically smallest string after performing exactly K operations on s. * * *
s252274679
Runtime Error
p03994
The input is given from Standard Input in the following format: s K
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> // Acknowledgement: Special thanks to kyomukyomupurin, who developed this // template. template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '(' << p.first << ", " << p.second << ')'; } template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { int n = 0; for (auto e : vec) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { int n = 0; for (auto e : st) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { int n = 0; for (auto e : mp) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& e : vec) is >> e; return is; } #ifdef LOCAL #define debug(...) \ std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << '\n'; } template <class Head, class... Tail> void debug_out(Head&& head, Tail&&... tail) { std::cerr << head; if (sizeof...(Tail) != 0) std::cerr << ", "; debug_out(std::forward<Tail>(tail)...); } using namespace std; using int64 = long long; int main() { string s; int64 K; cin >> s >> K; int N = s.size(); for (int i = 0; i < N; i++) { int idx = s[i] - 'a'; if (K >= 26 - idx) { K -= 26 - idx; s[i] = 'a'; } } if (K != 0) { int tmp = s[N - 1] - 'a' + K; s[N - 1] = tmp + 'a'; } cout << s << endl; return 0; }
Statement Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string.
[{"input": "xyz\n 4", "output": "aya\n \n\nFor example, you can perform the following operations: `xyz`, `yyz`, `zyz`,\n`ayz`, `aya`.\n\n* * *"}, {"input": "a\n 25", "output": "z\n \n\nYou have to perform exactly K operations.\n\n* * *"}, {"input": "codefestival\n 100", "output": "aaaafeaaivap"}]
Print the lexicographically smallest string after performing exactly K operations on s. * * *
s870227256
Runtime Error
p03994
The input is given from Standard Input in the following format: s K
#C-Next Letter str = input() K = int(input()) tempK = K result = "" for i in range(len(str)-1): changeNum = 122-ord(str[i])+1 if (changeNum <= tempK): result += "a" tempK -= changeNum if (tempK == 0): result += str[i+:] print(result) break else: result += str[i] tempK %= 26 if (tempK > 0): changeNum = ord(str[-1]) + tempK if (changeNum > 122): changeNum = changeNum -122 + 97 -1 else: changeNum = changeNum result += chr(changeNum) else: result += str[-1] print(result)
Statement Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string.
[{"input": "xyz\n 4", "output": "aya\n \n\nFor example, you can perform the following operations: `xyz`, `yyz`, `zyz`,\n`ayz`, `aya`.\n\n* * *"}, {"input": "a\n 25", "output": "z\n \n\nYou have to perform exactly K operations.\n\n* * *"}, {"input": "codefestival\n 100", "output": "aaaafeaaivap"}]
Print the lexicographically smallest string after performing exactly K operations on s. * * *
s079106991
Runtime Error
p03994
The input is given from Standard Input in the following format: s K
alphabet = 'abcdefghijklmnopqrstuvwxyz' s = input() K = int(input()) ans = '' for i in range(len(s) - 1): s_i = alphabet.index(s[i]) elif (26 - s_i < K) & (s_i != 0): K -= 26 - s_i s_i = 0 ans += alphabet[s_i] s_i = (alphabet.index(s[-1]) + K) % 26 ans += alphabet[s_i] print(ans)
Statement Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string.
[{"input": "xyz\n 4", "output": "aya\n \n\nFor example, you can perform the following operations: `xyz`, `yyz`, `zyz`,\n`ayz`, `aya`.\n\n* * *"}, {"input": "a\n 25", "output": "z\n \n\nYou have to perform exactly K operations.\n\n* * *"}, {"input": "codefestival\n 100", "output": "aaaafeaaivap"}]