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 we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s844979850
Accepted
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
(n,), a, b = [[*map(int, i.split())] for i in open(0)] print("YNeos"[sum(j - i if i > j else (j - i) // 2 for i, j in zip(a, b)) < 0 :: 2])
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s314480049
Wrong Answer
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
n, *a = map(int, open(0).read().split()) u = d = z = 0 for i, j in zip(a[:n], a[n:]): if j - i > 0: u += j - i elif j - i == 0: z += 1 else: d += j - i print("Yes" if u + 2 * d >= 0 else "No")
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s724665942
Runtime Error
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
N = int(input()) A = list(int(input())) B = list(int(input())) diff = [] for i in range(N): diff.append(A[i] - B[i]) if abs(sum(diff)) == N: print("Yes"): else: print("No")
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s006817785
Wrong Answer
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
# https://atcoder.jp/contests/apc001/tasks/apc001_b # greedyに前からシミュレーションかな # 都合が悪いものはすべて一番後ろの要素に追いやる # いやそれよりも、上段で何回操作が必要だったのか下段で何回操作が必要なのかメモしておけばよいのでは?(最小手順でね) # 最小で一致箚せられるときに、+になる分を計算して、さらに操作でそれらを一致させられるならばOK import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline rr = range enu = enumerate def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) N = read_a_int() A = read_ints() B = read_ints() n1 = 0 # bに+1する回数 n2 = 0 # aに+2する回数 for a, b in zip(A, B): # print(n1, n2) if b > a: sa = b - a n1 += sa % 2 n2 += n1 + sa // 2 elif b < a: n1 += a - b # 各回数に対して、余分にたさなければ行けないのだからそれを計算する # print(n1, n2) print("Yes" if n2 >= n1 * 2 else "No")
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s518218859
Wrong Answer
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
N = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) an, bn = 0, 0 i = 0 while True: # print(a) # print(b) # print() temp = [] for i in range(len(a)): if a[i] == b[i]: temp.append(i) for i in temp[::-1]: del a[i] del b[i] if a == b: print("Yes") quit() flag = 0 for an in range(len(a)): for bn in range(len(b)): if a[an] < b[an] and a[bn] > b[bn]: a[an] += 2 b[bn] += 1 flag = 1 if flag == 0: a[0] += 2 b[0] += 1 if sum(a) > sum(b): print("NO") quit()
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s802596922
Accepted
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
n, *L = map(int, open(0).read().split()) s = sum(j - i - max(0, i - j) - max(0, j - i) % 2 for i, j in zip(L, L[n:])) print("NYoe s"[s >= 0 == s % 2 :: 2])
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s477407002
Wrong Answer
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
s = input() if (len(s) + 1) // 2 == s.count("hi"): print("Yes") else: print("No")
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s967654176
Runtime Error
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
import sys read = sys.stdin.read readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ba = 0 bb = 0 for i in range(N): if a[i] > b[i]: ba += a[i] - b[i] if b[i] > a[i]: bb += (b[i] - a[i]) // 2 if bb = ba: print("Yes") else: print("No") if __name__ == '__main__': main()
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s251753351
Runtime Error
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
N = int(input()) a = list(map(int, input.split())) b = list(map(int, input.split())) ba = 0, bb = 0 for i in range(N): if a[i] > b[i]: ba += a[i] - b[i] if b[i] > a[i]: bb += (b[i] - a[i]) // 2 if bb >= ba: print("Yes") else: print("No")
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s032212015
Runtime Error
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) cou = 0 for j,k in zip(a,b): if j<k: cou += (k-j)//2 elif j>k: cou -= (j-k) if cou=>0: print("Yes") else: print("No")
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s723361812
Wrong Answer
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
N, *A = map(int, open(0).read().split()) print("YNeos"[any(a - b - A[0] + A[N] for a, b in zip(A, A[N:])) :: 2])
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s766337354
Runtime Error
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
def main(): import sys def input(): return sys.stdin.readline().rstrip() n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) s = 0 sm = 0 for x, y in zip(a,b): tmp = x-y sm += tmp if tmp == -1 tmp = 0 if tmp > 0: tmp *= 2 s += tmp if s > 0 or sm > 0: print('No') else: print('Yes') if __name__ == '__main__': main()
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s122894125
Runtime Error
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
N = int(input()) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] print('Yes' sum([max(A[i] - B[i], 0) for i in range(N)]) <= sum(B) - sum(A) if else 'No')
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s201878090
Runtime Error
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
N = int(input()) al = list(map(int, input().split())) bl = list(map(int, input().split())) cl = [0 for n in range(N)] res = False for n in range(N): cl[n] = al[n] - bl[n] # if sum(cl) > 0: # res = False # else: cl = sorted(cl) cp = 0 cm = 0 for c in cl: if c > 0: cp += c if c < 0: cm += c res = cp <= abs(cm/2) if res: print("Yes") else: print("No")
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s428080116
Runtime Error
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
N = int(input()) A = input() ai = A.split() B = input() bi = B.split() i = 0 a = [] b = [] for i in range(N): a.append(int(ai[i])) b.append(int(bi[i])) i = 0 asum = 0 bsum = 0 for i in range(N): asum += a[i] bsum += b[i] c = True j = 0 if asum > bsum: print("No") c = False elif asum == bsum: for j in range(N): if a[j] != b[j]: print("No") c = False break if c: print("Yes") c = False else: k = 0 Da = 0 Db = 0 d = bsum - asum while Da < d and Db < d: if a[k] < b[k]: Da += (b[k] - a[k]) // 2 a[k] += ((b[k] - a[k]) // 2) * 2 elif a[k] == b[k]: k += 1 else: Db += a[k] - b[k] b[k] += a[k] - b[k] if k == N: break if c: for j in range(N): if a[j] != b[j]: print("No") c = False break if c: if (N - Da) * 2 == (N - Db) * 1: print("Yes") else: print("No")N = int(input()) A = input() ai = A.split() B = input() bi = B.split() i = 0 a = [] b = [] for i in range(N): a.append(int(ai[i])) b.append(int(bi[i])) i = 0 asum = 0 bsum = 0 for i in range(N): asum += a[i] bsum += b[i] c = True j = 0 if asum > bsum: print("No") c = False elif asum == bsum: for j in range(N): if a[j] != b[j]: print("No") c = False break if c: print("Yes") c = False else: k = 0 Da = 0 Db = 0 d = bsum - asum while Da < d and Db < d: if a[k] < b[k]: Da += (b[k] - a[k]) // 2 a[k] += ((b[k] - a[k]) // 2) * 2 elif a[k] == b[k]: k += 1 else: Db += a[k] - b[k] b[k] += a[k] - b[k] if k == N: break if c: for j in range(N): if a[j] != b[j]: print("No") c = False break if c: if (N - Da) * 2 == (N - Db) * 1: print("Yes") else: print("No")
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`. * * *
s567325597
Runtime Error
p03438
Input is given from Standard Input in the following format: N a_1 a_2 .. a_N b_1 b_2 .. b_N
def main(): n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) Flag = False biga = 0 lessa = 0 for i in range(3): if a[i] > b[i]: biga += a[i] - b[i] else: lessa += b[i] - a[i] tmp = lessa -(biga*2) if tmp >=0: print("Yes") else: print("No") if __name__ == "__main__": main()
Statement You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
[{"input": "3\n 1 2 3\n 5 2 2", "output": "Yes\n \n\nFor example, we can perform three operations as follows to do our job:\n\n * First operation: i=1 and j=2. Now we have a = \\\\{3,2,3\\\\}, b = \\\\{5,3,2\\\\}.\n * Second operation: i=1 and j=2. Now we have a = \\\\{5,2,3\\\\}, b = \\\\{5,4,2\\\\}.\n * Third operation: i=2 and j=3. Now we have a = \\\\{5,4,3\\\\}, b = \\\\{5,4,3\\\\}.\n\n* * *"}, {"input": "5\n 3 1 4 1 5\n 2 7 1 8 2", "output": "No\n \n\n* * *"}, {"input": "5\n 2 7 1 8 2\n 3 1 4 1 5", "output": "No"}]
If Takahashi can have exactly K black squares in the grid, print `Yes`; otherwise, print `No`. * * *
s306323965
Accepted
p03592
Input is given from Standard Input in the following format: N M K
import sys from sys import exit from collections import deque from bisect import ( bisect_left, bisect_right, insort_left, insort_right, ) # func(リスト,値) from heapq import heapify, heappop, heappush from itertools import product, permutations, combinations, combinations_with_replacement from functools import reduce from math import sin, cos, tan, asin, acos, atan, degrees, radians sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9 + 7 def lcm(x, y): return x * y // gcd(x, y) def lgcd(l): return reduce(gcd, l) def llcm(l): return reduce(lcm, l) def powmod(n, i, mod): return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod) def div2(x): return x.bit_length() def div10(x): return len(str(x)) - (x == 0) def perm(n, mod=None): ans = 1 for i in range(1, n + 1): ans *= i if mod != None: ans %= mod return ans def intput(): return int(input()) def mint(): return map(int, input().split()) def lint(): return list(map(int, input().split())) def ilint(): return int(input()), list(map(int, input().split())) def judge(x, l=["Yes", "No"]): print(l[0] if x else l[1]) def lprint(l, sep="\n"): for x in l: print(x, end=sep) def ston(c, c0="a"): return ord(c) - ord(c0) def ntos(x, c0="a"): return chr(x + ord(c0)) class counter(dict): def __init__(self, *args): super().__init__(args) def add(self, x, d=1): self.setdefault(x, 0) self[x] += d class comb: def __init__(self, n, mod=None): self.l = [1] self.n = n self.mod = mod def get(self, k): l, n, mod = self.l, self.n, self.mod k = n - k if k > n // 2 else k while len(l) <= k: i = len(l) l.append( l[i - 1] * (n + 1 - i) // i if mod == None else (l[i - 1] * (n + 1 - i) * powmod(i, -1, mod)) % mod ) return l[k] N, M, K = mint() ans = False for i in range(N + 1): for j in range(M + 1): if i * (M - j) + (N - i) * j == K: ans = True break judge(ans)
Statement We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
[{"input": "2 2 2", "output": "Yes\n \n\nPress the buttons in the order of the first row, the first column.\n\n* * *"}, {"input": "2 2 1", "output": "No\n \n\n* * *"}, {"input": "3 5 8", "output": "Yes\n \n\nPress the buttons in the order of the first column, third column, second row,\nfifth column.\n\n* * *"}, {"input": "7 9 20", "output": "No"}]
If Takahashi can have exactly K black squares in the grid, print `Yes`; otherwise, print `No`. * * *
s844575855
Wrong Answer
p03592
Input is given from Standard Input in the following format: N M K
print("Yes")
Statement We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
[{"input": "2 2 2", "output": "Yes\n \n\nPress the buttons in the order of the first row, the first column.\n\n* * *"}, {"input": "2 2 1", "output": "No\n \n\n* * *"}, {"input": "3 5 8", "output": "Yes\n \n\nPress the buttons in the order of the first column, third column, second row,\nfifth column.\n\n* * *"}, {"input": "7 9 20", "output": "No"}]
If Takahashi can have exactly K black squares in the grid, print `Yes`; otherwise, print `No`. * * *
s894514161
Accepted
p03592
Input is given from Standard Input in the following format: N M K
#!/usr/bin/env pypy import sys from typing import ( Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union, ) # import time # import math # import numpy as np # import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall # import random # random, uniform, randint, randrange, shuffle, sample # import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj # from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj # from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available. # from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from fractions import Fraction # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10) def main(): Num = Union[int, float] mod = 1000000007 # 10^9+7 inf = float("inf") # sys.float_info.max = 1.79e+308 # inf = 2 ** 63 - 1 # (for fast JIT compile in PyPy) 9.22e+18 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def isp(): return input().split() def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x) - 1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x) - 1, input().split())) def li(): return list(input()) def check(n, m, k): for i in range(n + 1): for j in range(m + 1): if i * j + (n - i) * (m - j) == k: return True return False n, m, k = mi() print("Yes") if check(n, m, k) else print("No") if __name__ == "__main__": main()
Statement We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
[{"input": "2 2 2", "output": "Yes\n \n\nPress the buttons in the order of the first row, the first column.\n\n* * *"}, {"input": "2 2 1", "output": "No\n \n\n* * *"}, {"input": "3 5 8", "output": "Yes\n \n\nPress the buttons in the order of the first column, third column, second row,\nfifth column.\n\n* * *"}, {"input": "7 9 20", "output": "No"}]
If Takahashi can have exactly K black squares in the grid, print `Yes`; otherwise, print `No`. * * *
s076397919
Runtime Error
p03592
Input is given from Standard Input in the following format: N M K
n,m,k=map(int,input().split()) x='No' for i in range(m+1) t=n*i if t==k: x='Yes' break for j in range(n): t+=m-2*i if t==k: x='Yes' break print(x)
Statement We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
[{"input": "2 2 2", "output": "Yes\n \n\nPress the buttons in the order of the first row, the first column.\n\n* * *"}, {"input": "2 2 1", "output": "No\n \n\n* * *"}, {"input": "3 5 8", "output": "Yes\n \n\nPress the buttons in the order of the first column, third column, second row,\nfifth column.\n\n* * *"}, {"input": "7 9 20", "output": "No"}]
If Takahashi can have exactly K black squares in the grid, print `Yes`; otherwise, print `No`. * * *
s155966484
Runtime Error
p03592
Input is given from Standard Input in the following format: N M K
n,m,k=map(int,input().split()) n,m=min(n,m),max(n,m) for i in range(n//2+n%2): num,dem=k-i*m,n-2*i if num%dem or not(0<=num///dem<=m):continue print("Yes");exit() print("No")
Statement We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
[{"input": "2 2 2", "output": "Yes\n \n\nPress the buttons in the order of the first row, the first column.\n\n* * *"}, {"input": "2 2 1", "output": "No\n \n\n* * *"}, {"input": "3 5 8", "output": "Yes\n \n\nPress the buttons in the order of the first column, third column, second row,\nfifth column.\n\n* * *"}, {"input": "7 9 20", "output": "No"}]
If Takahashi can have exactly K black squares in the grid, print `Yes`; otherwise, print `No`. * * *
s466909643
Runtime Error
p03592
Input is given from Standard Input in the following format: N M K
n,m,k= input().split() n = int(n) m = int(m) k = int(k) for i in range(n+1): for j in range(m+1): if i*(m-j) + (n-i)j == k: print("Yes") exit() print("No")
Statement We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
[{"input": "2 2 2", "output": "Yes\n \n\nPress the buttons in the order of the first row, the first column.\n\n* * *"}, {"input": "2 2 1", "output": "No\n \n\n* * *"}, {"input": "3 5 8", "output": "Yes\n \n\nPress the buttons in the order of the first column, third column, second row,\nfifth column.\n\n* * *"}, {"input": "7 9 20", "output": "No"}]
If Takahashi can have exactly K black squares in the grid, print `Yes`; otherwise, print `No`. * * *
s606932104
Runtime Error
p03592
Input is given from Standard Input in the following format: N M K
N,M,K = map(int,input().strip().split()) def judge(N,M,K): if K > N * M or K < 0: return False for n in range(0, N + 1): for m in range(0, M + 1): if n * M + m * N - m * n == K or: return True return False if judge(N, M, K): print("Yes") else: print("No")
Statement We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
[{"input": "2 2 2", "output": "Yes\n \n\nPress the buttons in the order of the first row, the first column.\n\n* * *"}, {"input": "2 2 1", "output": "No\n \n\n* * *"}, {"input": "3 5 8", "output": "Yes\n \n\nPress the buttons in the order of the first column, third column, second row,\nfifth column.\n\n* * *"}, {"input": "7 9 20", "output": "No"}]
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`. * * *
s739527061
Accepted
p03068
Input is given from Standard Input in the following format: N S K
# 入力が10**5とかになったときに100ms程度早い import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) def read_matrix(H): """ H is number of rows """ return [list(map(int, read().split())) for _ in range(H)] def read_map(H): """ H is number of rows 文字列で与えられた盤面を読み取る用 """ return [read() for _ in range(H)] def read_col(H, n_cols): """ H is number of rows n_cols is number of cols A列、B列が与えられるようなとき """ ret = [[] for _ in range(n_cols)] for _ in range(H): tmp = list(map(int, read().split())) for col in range(n_cols): ret[col].append(tmp[col]) return ret N = read_a_int() S = input() K = read_a_int() target = S[K - 1] ans = [] for i in range(N): if S[i] != target: ans.append("*") else: ans.append(target) print(*ans, sep="")
Statement You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
[{"input": "5\n error\n 2", "output": "*rr*r\n \n\nThe second character of S is `r`. When we replace every character in `error`\nthat differs from `r` with `*`, we get the string `*rr*r`.\n\n* * *"}, {"input": "6\n eleven\n 5", "output": "e*e*e*\n \n\n* * *"}, {"input": "9\n education\n 7", "output": "******i**"}]
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`. * * *
s055559991
Accepted
p03068
Input is given from Standard Input in the following format: N S K
# -*- coding: utf-8 -*- from sys import stdin ############################################ # read data for n sequences. n = stdin.readline() N = int(n) n = stdin.readline() S = str(n) n = stdin.readline() K = int(n) # data = [int(stdin.readline().rstrip()) for _ in range(n)] key = S[K - 1] out = [] for i, l in enumerate(S): if i < N: if l != key: out.append("*") elif l == "\n": x = 1 else: out.append(l) out1 = "" for o in out: out1 += o print(out1)
Statement You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
[{"input": "5\n error\n 2", "output": "*rr*r\n \n\nThe second character of S is `r`. When we replace every character in `error`\nthat differs from `r` with `*`, we get the string `*rr*r`.\n\n* * *"}, {"input": "6\n eleven\n 5", "output": "e*e*e*\n \n\n* * *"}, {"input": "9\n education\n 7", "output": "******i**"}]
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`. * * *
s095467848
Accepted
p03068
Input is given from Standard Input in the following format: N S K
def getInt(): return int(input()) def getIntList(): return [int(x) for x in input().split()] def zeros(n): return [0] * n class Debug: def __init__(self): self.debug = True def off(self): self.debug = False def dmp(self, x, cmt=""): if self.debug: if cmt != "": w = cmt + ": " + str(x) else: w = str(x) print(w) return x def prob(): d = Debug() d.off() N = getInt() S = input() K = getInt() d.dmp((N, S, K), "N, S, K") keep = S[K - 1] newS = "" for c in S: if c == keep: newS += c else: newS += "*" return newS ans = prob() print(ans)
Statement You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
[{"input": "5\n error\n 2", "output": "*rr*r\n \n\nThe second character of S is `r`. When we replace every character in `error`\nthat differs from `r` with `*`, we get the string `*rr*r`.\n\n* * *"}, {"input": "6\n eleven\n 5", "output": "e*e*e*\n \n\n* * *"}, {"input": "9\n education\n 7", "output": "******i**"}]
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`. * * *
s806924252
Accepted
p03068
Input is given from Standard Input in the following format: N S K
N = int(input()) S = input() K = int(input()) O = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] if S.islower(): if len(S) == N: if 1 <= K <= N <= 10: W = str(S[K - 1]) O.remove(W) for i in range(24): S = S.replace(O[i], "*") print(S)
Statement You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
[{"input": "5\n error\n 2", "output": "*rr*r\n \n\nThe second character of S is `r`. When we replace every character in `error`\nthat differs from `r` with `*`, we get the string `*rr*r`.\n\n* * *"}, {"input": "6\n eleven\n 5", "output": "e*e*e*\n \n\n* * *"}, {"input": "9\n education\n 7", "output": "******i**"}]
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`. * * *
s350607892
Accepted
p03068
Input is given from Standard Input in the following format: N S K
wordSize = int(input()) word = str(input()) removePosition = int(input()) reword = "" for i in range(wordSize): if word[i] != word[removePosition - 1]: reword += str("*") else: reword += word[i] print(reword)
Statement You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
[{"input": "5\n error\n 2", "output": "*rr*r\n \n\nThe second character of S is `r`. When we replace every character in `error`\nthat differs from `r` with `*`, we get the string `*rr*r`.\n\n* * *"}, {"input": "6\n eleven\n 5", "output": "e*e*e*\n \n\n* * *"}, {"input": "9\n education\n 7", "output": "******i**"}]
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`. * * *
s942142021
Runtime Error
p03068
Input is given from Standard Input in the following format: N S K
n, s, k = input().split() s_list = list(s) k = int(k) - 1 print(n) print(s) print(k) answer_list = [] if len(s_list) == int(n): for s in s_list: if not s == s_list[k]: s = "*" answer_list.append(s) answer_list = "".join(answer_list) print(answer_list)
Statement You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
[{"input": "5\n error\n 2", "output": "*rr*r\n \n\nThe second character of S is `r`. When we replace every character in `error`\nthat differs from `r` with `*`, we get the string `*rr*r`.\n\n* * *"}, {"input": "6\n eleven\n 5", "output": "e*e*e*\n \n\n* * *"}, {"input": "9\n education\n 7", "output": "******i**"}]
Print the integer which appears on the top face after the simulation.
s423841475
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
class dice: def __init__(self, a, b, c, d, e, f): self.A = [a, b, c, d, e, f] self.temp = [] def N_method(self): for i in self.A: self.temp.append(i) self.A[0] = self.temp[1] self.A[1] = self.temp[5] self.A[4] = self.temp[0] self.A[5] = self.temp[4] self.A[2] = self.temp[2] self.A[3] = self.temp[3] self.temp = [] # print(self.A[0]) def S_method(self): for i in self.A: self.temp.append(i) self.A[0] = self.temp[4] self.A[1] = self.temp[0] self.A[2] = self.temp[2] self.A[3] = self.temp[3] self.A[4] = self.temp[5] self.A[5] = self.temp[1] self.temp = [] # print(self.A[0]) def W_method(self): for i in self.A: self.temp.append(i) self.A[0] = self.temp[2] self.A[1] = self.temp[1] self.A[2] = self.temp[5] self.A[3] = self.temp[0] self.A[4] = self.temp[4] self.A[5] = self.temp[3] self.temp = [] # print(self.A[0]) def E_method(self): for i in self.A: self.temp.append(i) self.A[0] = self.temp[3] self.A[1] = self.temp[1] self.A[2] = self.temp[0] self.A[3] = self.temp[5] self.A[4] = self.temp[4] self.A[5] = self.temp[2] self.temp = [] # print(self.A[0]) def printout(self): print(self.A[0]) if __name__ == "__main__": input_text = "" input_text = input() array = [] array = input_text.split() ob1 = dice(array[0], array[1], array[2], array[3], array[4], array[5]) input_order = input() order_array = [] order_array = list(input_order) for i in range(0, len(order_array)): if order_array[i] == "E": ob1.E_method() elif order_array[i] == "S": ob1.S_method() elif order_array[i] == "W": ob1.W_method() elif order_array[i] == "N": ob1.N_method() ob1.printout()
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s476147710
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
class Dice(object): def __init__(self, listnum): self.a = listnum[0] self.b = listnum[1] self.c = listnum[2] self.d = listnum[3] self.e = listnum[4] self.f = listnum[5] def moveS(self): listnew = [] listnew.append(self.e) listnew.append(self.a) listnew.append(self.c) listnew.append(self.d) listnew.append(self.f) listnew.append(self.b) return Dice(listnew) def moveN(self): listnew = [] listnew.append(self.b) listnew.append(self.f) listnew.append(self.c) listnew.append(self.d) listnew.append(self.a) listnew.append(self.e) return Dice(listnew) def moveE(self): listnew = [] listnew.append(self.d) listnew.append(self.b) listnew.append(self.a) listnew.append(self.f) listnew.append(self.e) listnew.append(self.c) return Dice(listnew) def moveW(self): listnew = [] listnew.append(self.c) listnew.append(self.b) listnew.append(self.f) listnew.append(self.a) listnew.append(self.e) listnew.append(self.d) return Dice(listnew) No1 = Dice(input().split()) listmove = list(input()) for i in range(len(listmove)): if listmove[i] == "S": No1 = No1.moveS() elif listmove[i] == "N": No1 = No1.moveN() elif listmove[i] == "E": No1 = No1.moveE() elif listmove[i] == "W": No1 = No1.moveW() print(No1.a)
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s198379218
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
class Dice(): def __init__(self, dice_labels): self.top = dice_labels[0] self.south = dice_labels[1] self.east = dice_labels[2] self.west = dice_labels[3] self.north = dice_labels[4] self.bottom = dice_labels[5] def roll(self, str_direction): if str_direction == 'E': self.__rot_to_east() elif str_direction == 'W': self.__rot_to_west() elif str_direction == 'S': self.__rot_to_south() elif str_direction == 'N': self.__rot_to_north() def __rot_to_east(self): self.top, self.east, self.west, self.bottom = (self.west, self.top, self.bottom, self.east) def __rot_to_west(self): self.top, self.east, self.west, self.bottom = (self.east, self.bottom, self.top, self.west) def __rot_to_south(self): self.top, self.south, self.north, self.bottom = (self.north, self.top, self.bottom, self.south) def __rot_to_north(self): self.top, self.south, self.north, self.bottom = (self.south, self.bottom, self.top, self.north) dice_labels = input().split(' ') rot_operations = list(input()) dice = Dice(dice_labels) for roll_direction in rot_operations: dice.roll(roll_direction) print(dice.top)
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s215178484
Runtime Error
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
class Dice(object): def __init__(self, d): self.rows = [d[0], d[4], d[5], d[1]] self.cols = [d[0], d[2], d[5], d[3]] def move_next_rows(self): temp = self.rows.pop(0) self.rows.append(temp) self.__update(self.cols, self.rows) def move_prev_rows(self): temp = self.rows.pop(3) self.rows.insert(0, temp) self.__update(self.cols, self.rows) def move_next_cols(self): temp = self.cols.pop(0) self.cols.append(temp) self.__update(self.rows, self.cols) def move_prev_cols(self): temp = self.cols.pop(3) self.cols.insert(0, temp) self.__update(self.rows, self.cols) def __update(self, x, y): x[0] = y[0] x[2] = y[2] class DiceChecker(object): def __init__(self, dice1, dice2): self.dice1 = dice1 self.dice2 = dice2 self.dice1_top = self.dice1.rows[0] self.dice1_front = self.dice1.rows[3] def check_same_dice(self): is_same = False for _ in range(4): for _ in range(4): is_same_element = ( self.dice1.rows == self.dice2.rows and self.dice1.cols == self.dice2.cols ) if is_same_element: is_same = True break self.dice2.move_next_cols() else: self.dice2.move_next_rows() continue break if is_same: print("Yes") else: print("No") def __find_num(self, x, dice): i = 0 while x != dice.rows[0]: dice.move_next_rows() if i > 3: dice.move_next_cols() i = 0 i += 1 def __rot(self, dice): temp = dice.rows[1] dice.rows[1] = dice.rows[3] dice.rows[3] = temp temp = dice.cols[1] dice.cols[1] = dice.cols[3] dice.cols[3] = temp d1 = list(map(int, input().split(" "))) d2 = list(map(int, input().split(" "))) dice1 = Dice(d1) dice2 = Dice(d2) dice_checker = DiceChecker(dice1, dice2) dice_checker.check_same_dice()
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s378146594
Runtime Error
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
class dice: def __init__(self, label): self.d = label def roll(self, op): d = self.d if op == "N": self.d = [d[1], d[5], d[2], d[3], d[0], d[4]] elif op == "E": self.d = [d[3], d[1], d[0], d[5], d[4], d[2]] elif op == "W": self.d = [d[2], d[1], d[5], d[0], d[4], d[3]] elif op == "S": self.d = [d[4], d[0], d[2], d[3], d[5], d[1]] def print(self): print(self.d[0]) def print_r_side(self, t, f): d = self.d if (t, f) == (d[0], d[1]): print(d[2]) elif (t, f) == (d[0], d[2]): print(d[4]) elif (t, f) == (d[0], d[3]): print(d[1]) elif (t, f) == (d[0], d[4]): print(d[3]) elif (t, f) == (d[1], d[0]): print(d[3]) elif (t, f) == (d[1], d[2]): print(d[0]) elif (t, f) == (d[1], d[3]): print(d[5]) elif (t, f) == (d[1], d[5]): print(d[2]) elif (t, f) == (d[2], d[0]): print(d[1]) elif (t, f) == (d[2], d[1]): print(d[5]) elif (t, f) == (d[2], d[4]): print(d[0]) elif (t, f) == (d[2], d[5]): print(d[4]) elif (t, f) == (d[3], d[0]): print(d[4]) elif (t, f) == (d[3], d[1]): print(d[0]) elif (t, f) == (d[3], d[4]): print(d[5]) elif (t, f) == (d[3], d[5]): print(d[1]) elif (t, f) == (d[4], d[0]): print(d[2]) elif (t, f) == (d[4], d[2]): print(d[5]) elif (t, f) == (d[4], d[3]): print(d[0]) elif (t, f) == (d[4], d[5]): print(d[3]) elif (t, f) == (d[5], d[1]): print(d[3]) elif (t, f) == (d[5], d[2]): print(d[1]) elif (t, f) == (d[5], d[3]): print(d[4]) elif (t, f) == (d[5], d[4]): print(d[2]) label = list(map(int, input().split())) q = int(input()) d0 = dice(label) for _ in range(q): t, f = list(map(int, input().split())) d0.print_r_side(t, f)
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s502339716
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
def roll(l, command): """ return rolled list l : string list command: string """ res = [] i = -1 if command == "N": res = [l[i + 2], l[i + 6], l[i + 3], l[i + 4], l[i + 1], l[i + 5]] if command == "S": res = [l[i + 5], l[i + 1], l[i + 3], l[i + 4], l[i + 6], l[i + 2]] if command == "E": res = [l[i + 4], l[i + 2], l[i + 1], l[i + 6], l[i + 5], l[i + 3]] if command == "W": res = [l[i + 3], l[i + 2], l[i + 6], l[i + 1], l[i + 5], l[i + 4]] return res faces = input().split() commands = list(input()) for command in commands: faces = roll(faces, command) print(faces[0])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s031284330
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
# Problem - サイコロ # input t, s, e, w, n, b = map(int, input().split()) process = list(input()) # initialization for p in process: tmp_t = t tmp_s = s tmp_e = e tmp_w = w tmp_n = n tmp_b = b if p == "S": s = tmp_t t = tmp_n n = tmp_b b = tmp_s elif p == "N": s = tmp_b n = tmp_t t = tmp_s b = tmp_n elif p == "W": w = tmp_t e = tmp_b t = tmp_e b = tmp_w elif p == "E": w = tmp_b e = tmp_t t = tmp_w b = tmp_e # output print(t)
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s115197101
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
a, b, c, d, e, f = list(map(int, input().split())) for g in input(): if g == "N": a, e, f, b = b, a, e, f if g == "E": a, c, f, d = d, a, c, f if g == "W": a, c, f, d = c, f, d, a if g == "S": a, e, f, b = e, f, b, a print(a)
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s945029571
Wrong Answer
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
def dice(): dice = list(map(str, input().split())) direction = input() for i in range(len(direction)): if direction[i] == "N": dice[0], dice[1], dice[4], dice[5] = dice[1], dice[5], dice[0], dice[4] elif direction[i] == "S": dice[0], dice[1], dice[4], dice[5] = dice[4], dice[0], dice[5], dice[1] elif direction[i] == "W": dice[0], dice[2], dice[3], dice[5] = dice[2], dice[5], dice[0], dice[3] else: dice[0], dice[2], dice[3], dice[5] = dice[3], dice[0], dice[5], dice[2] print(dice[0])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s676567322
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
face = [0]*6 class Dice(): def __init__(self): self.one = inp[0] self.two = inp[1] self.three = inp[2] self.four = inp[3] self.five = inp[4] self.six = inp[5] def setnumbers(self, n0, n1, n2, n3, n4, n5): self.one = n0 self.two = n1 self.three = n2 self.four = n3 self.five = n4 self.six = n5 def spin(self, command): face[0] = self.one face[1] = self.two face[2] = self.three face[3] = self.four face[4] = self.five face[5] = self.six if command == 'S': self.setnumbers(face[4], face[0], face[2], face[3], face[5], face[1]) # print('command is S') elif command == 'N': self.setnumbers(face[1], face[5], face[2], face[3], face[0], face[4]) # print('command is N') elif command == 'E': self.setnumbers(face[3], face[1], face[0], face[5], face[4], face[2]) # print('command is E') elif command == 'W': self.setnumbers(face[2], face[1], face[5], face[0], face[4], face[3]) # print('command is W') inp = list(map(int, input().split())) command = list(input()) dice = Dice() dice.setnumbers(inp[0], inp[1], inp[2], inp[3], inp[4], inp[5]) face = inp for i in range(len(command)): dice.spin(command[i]) print(dice.one)
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s722706102
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
class Sai: def __init__(self, m1, m2, m3, m4, m5, m6): self.t = m1 self.s = m2 self.e = m3 self.w = m4 self.n = m5 self.b = m6 def furu(self, arg): if arg == "N": tmp = self.s self.s = self.b self.b = self.n self.n = self.t self.t = tmp elif arg == "S": tmp = self.n self.n = self.b self.b = self.s self.s = self.t self.t = tmp elif arg == "W": tmp = self.e self.e = self.b self.b = self.w self.w = self.t self.t = tmp else: tmp = self.w self.w = self.b self.b = self.e self.e = self.t self.t = tmp s = list(map(int, input().split())) c = input() sai = Sai(s[0], s[1], s[2], s[3], s[4], s[5]) for i in c: sai.furu(i) print(sai.t)
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s466454115
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
class Dice: arr = [] tmpArr = [] def __init__(self, arr): self.arr = arr def move(self, pos): if pos == "E": self.eastMove() elif pos == "N": self.northMove() elif pos == "S": self.sorthMove() elif pos == "W": self.westMove() def out(self): return self.arr[0] def eastMove(self): self.changeArr(3, 6) self.changeArr(3, 4) self.changeArr(3, 1) def northMove(self): self.changeArr(5, 6) self.changeArr(5, 2) self.changeArr(5, 1) def sorthMove(self): self.changeArr(2, 6) self.changeArr(2, 5) self.changeArr(2, 1) def westMove(self): self.changeArr(4, 6) self.changeArr(4, 3) self.changeArr(4, 1) def changeArr(self, f, t): tmp = self.arr[f - 1] self.arr[f - 1] = self.arr[t - 1] self.arr[t - 1] = tmp diceNum = list(map(int, input().split(" "))) dice = Dice(diceNum) posAction = input() for pos in posAction: dice.move(pos) print(dice.out())
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s017568146
Wrong Answer
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
def north(list): List = [] List.append(list[1]) List.append(list[5]) List.append(list[2]) List.append(list[3]) List.append(list[0]) return List def west(list): List = [] List.append(list[2]) List.append(list[1]) List.append(list[5]) List.append(list[0]) List.append(list[4]) List.append(list[3]) return List def south(list): List = [] List.append(list[4]) List.append(list[0]) List.append(list[2]) List.append(list[3]) List.append(list[5]) List.append(list[1]) return List def east(list): List = [] List.append(list[3]) List.append(list[1]) List.append(list[0]) List.append(list[5]) List.append(list[4]) List.append(list[2]) return List dice = list(map(int, input().split())) x = str(input()) y = list(x) for i in range(len(x)): if y[i] == "N": dice[0:5] = north(dice) elif y[i] == "W": dice[0:5] = west(dice) elif y[i] == "S": dice[0:5] = south(dice) elif y[i] == "E": dice[0:5] = east(dice) print(dice[0])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s468755949
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
SN = [5, 1, 2, 6] WE = [4, 1, 3, 6] def EWSN(d): global SN, WE if d == "S": SN = SN[3:4] + SN[0:3] WE[3] = SN[3] WE[1] = SN[1] elif d == "N": SN = SN[1:4] + SN[0:1] WE[3] = SN[3] WE[1] = SN[1] elif d == "E": WE = WE[3:4] + WE[0:3] SN[3] = WE[3] SN[1] = WE[1] elif d == "W": WE = WE[1:4] + WE[0:1] SN[3] = WE[3] SN[1] = WE[1] dice = list(map(int, input().split(" "))) op = input() for i in op: EWSN(i) print(dice[SN[1] - 1])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s855204126
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
daise = list(map(int, input().split())) a = input() A = list(a) n = len(A) for m in range(n): if A[m] == "S": x = daise[0] daise[0] = daise[4] daise[4] = daise[5] daise[5] = daise[1] daise[1] = x elif A[m] == "E": x = daise[0] daise[0] = daise[3] daise[3] = daise[5] daise[5] = daise[2] daise[2] = x elif A[m] == "W": x = daise[0] daise[0] = daise[2] daise[2] = daise[5] daise[5] = daise[3] daise[3] = x pass elif A[m] == "N": x = daise[0] daise[0] = daise[1] daise[1] = daise[5] daise[5] = daise[4] daise[4] = x pass print(daise[0])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s287252349
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
u,s,e,w,n,d=map(int,input().split()) a=[i for i in input()] for i in a: if i=='N': n,d,s,u=u,n,d,s elif i=='S': s,d,n,u=u,s,d,n elif i=='E': e,d,w,u=u,e,d,w elif i=='W': w,d,e,u=u,w,d,e print(u)
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s615740351
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
class Dice: def __init__(self, nums): self.__indexTop__ = 1 self.__indexFront__ = 2 self.__indexRight__ = 3 self.__indexLeft__ = 4 self.__indexBack__ = 5 self.__indexBottom__ = 6 self.__sides__ = { 1: nums[0], 2: nums[1], 3: nums[2], 4: nums[3], 5: nums[4], 6: nums[5], } def getTopSideNum(self): return self.__sides__[self.__indexTop__] def getTopsideIndex(self): return self.__indexTop__ def roll(self, direction): initTop = self.__indexTop__ initFront = self.__indexFront__ initRight = self.__indexRight__ initLeft = self.__indexLeft__ initBack = self.__indexBack__ initBottom = self.__indexBottom__ if direction == "N": self.__indexTop__ = initFront self.__indexFront__ = initBottom self.__indexRight__ = initRight self.__indexLeft__ = initLeft self.__indexBack__ = initTop self.__indexBottom__ = initBack elif direction == "E": self.__indexTop__ = initLeft self.__indexFront__ = initFront self.__indexRight__ = initTop self.__indexLeft__ = initBottom self.__indexBack__ = initBack self.__indexBottom__ = initRight elif direction == "S": self.__indexTop__ = initBack self.__indexFront__ = initTop self.__indexRight__ = initRight self.__indexLeft__ = initLeft self.__indexBack__ = initBottom self.__indexBottom__ = initFront elif direction == "W": self.__indexTop__ = initRight self.__indexFront__ = initFront self.__indexRight__ = initBottom self.__indexLeft__ = initTop self.__indexBack__ = initBack self.__indexBottom__ = initLeft die = Dice([int(i) for i in input().split()]) for direction in input(): die.roll(direction) print(die.getTopSideNum())
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s406356878
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
def dice(u, f, o): if u == 1: if f == 2: if o == "E": u = 4 if o == "N": u = 2 f = 6 if o == "S": u = 5 f = 1 if o == "W": u = 3 elif f == 3: if o == "E": u = 2 if o == "N": u = 3 f = 6 if o == "S": u = 4 f = 1 if o == "W": u = 5 elif f == 5: if o == "E": u = 3 if o == "N": u = 5 f = 6 if o == "S": u = 2 f = 1 if o == "W": u = 4 elif f == 4: if o == "E": u = 5 if o == "N": u = 4 f = 6 if o == "S": u = 3 f = 1 if o == "W": u = 2 elif u == 2: if f == 1: if o == "E": u = 3 if o == "N": u = 1 f = 5 if o == "S": u = 6 f = 2 if o == "W": u = 4 elif f == 3: if o == "E": u = 6 if o == "N": u = 3 f = 5 if o == "S": u = 4 f = 2 if o == "W": u = 1 elif f == 4: if o == "E": u = 1 if o == "N": u = 4 f = 5 if o == "S": u = 3 f = 2 if o == "W": u = 6 elif f == 6: if o == "E": u = 4 if o == "N": u = 6 f = 5 if o == "S": u = 1 f = 2 if o == "W": u = 3 elif u == 3: if f == 2: if o == "E": u = 1 if o == "N": u = 2 f = 4 if o == "S": u = 5 f = 3 if o == "W": u = 6 elif f == 1: if o == "E": u = 5 if o == "N": u = 1 f = 4 if o == "S": u = 6 f = 3 if o == "W": u = 2 elif f == 5: if o == "E": u = 6 if o == "N": u = 5 f = 4 if o == "S": u = 2 f = 3 if o == "W": u = 1 elif f == 6: if o == "E": u = 2 if o == "N": u = 6 f = 4 if o == "S": u = 1 f = 3 if o == "W": u = 5 elif u == 4: if f == 1: if o == "E": u = 2 if o == "N": u = 1 f = 3 if o == "S": u = 6 f = 4 if o == "W": u = 5 elif f == 2: if o == "E": u = 6 if o == "N": u = 2 f = 3 if o == "S": u = 5 f = 4 if o == "W": u = 1 elif f == 5: if o == "E": u = 1 if o == "N": u = 5 f = 3 if o == "S": u = 2 f = 4 if o == "W": u = 6 elif f == 6: if o == "E": u = 5 if o == "N": u = 6 f = 3 if o == "S": u = 1 f = 4 if o == "W": u = 2 elif u == 5: if f == 1: if o == "E": u = 4 if o == "N": u = 1 f = 2 if o == "S": u = 6 f = 5 if o == "W": u = 3 elif f == 3: if o == "E": u = 1 if o == "N": u = 3 f = 2 if o == "S": u = 4 f = 5 if o == "W": u = 6 elif f == 4: if o == "E": u = 6 if o == "N": u = 4 f = 2 if o == "S": u = 3 f = 5 if o == "W": u = 1 elif f == 6: if o == "E": u = 3 if o == "N": u = 6 f = 2 if o == "S": u = 1 f = 5 if o == "W": u = 4 elif u == 6: if f == 2: if o == "E": u = 3 if o == "N": u = 2 f = 1 if o == "S": u = 5 f = 6 if o == "W": u = 4 elif f == 3: if o == "E": u = 5 if o == "N": u = 3 f = 1 if o == "S": u = 4 f = 6 if o == "W": u = 2 elif f == 4: if o == "E": u = 2 if o == "N": u = 4 f = 1 if o == "S": u = 3 f = 6 if o == "W": u = 5 elif f == 5: if o == "E": u = 4 if o == "N": u = 5 f = 1 if o == "S": u = 2 f = 6 if o == "W": u = 3 return [u, f] n = list(map(int, input().split())) o_list = list(input()) o_length = len(o_list) u = 1 f = 2 for i in range(o_length): a = dice(u, f, o_list[i]) u = a[0] f = a[1] print(n[u - 1])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s774476077
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
progression = list(map(int, input().split())) order = input() dice = progression order_list = list(order) direction = [0, "S", "E", "W", "N", 0] up_down_0 = [0, 0] up_down_1 = [0, 0] up_down_2 = [0, 0] up_down_0[0], up_down_0[1] = progression[0], progression[5] up_down_1[0], up_down_1[1] = progression[2], progression[3] up_down_2[0], up_down_2[1] = progression[1], progression[4] num_under = 0 num_upper = 0 for i in order_list: if i == "N": num_under = direction.index("N") elif i == "E": num_under = direction.index("E") elif i == "S": num_under = direction.index("S") elif i == "W": num_under = direction.index("W") dice[num_under], dice[5] = dice[5], dice[num_under] if dice[5] == up_down_0[0]: num_upper = dice.index(up_down_0[1]) dice[num_upper], dice[0] = dice[0], dice[num_upper] elif dice[5] == up_down_0[1]: num_upper = dice.index(up_down_0[0]) dice[num_upper], dice[0] = dice[0], dice[num_upper] elif dice[5] == up_down_1[0]: num_upper = dice.index(up_down_1[1]) dice[num_upper], dice[0] = dice[0], dice[num_upper] elif dice[5] == up_down_1[1]: num_upper = dice.index(up_down_1[0]) dice[num_upper], dice[0] = dice[0], dice[num_upper] elif dice[5] == up_down_2[0]: num_upper = dice.index(up_down_2[1]) dice[num_upper], dice[0] = dice[0], dice[num_upper] elif dice[5] == up_down_2[1]: num_upper = dice.index(up_down_2[0]) dice[num_upper], dice[0] = dice[0], dice[num_upper] direction[num_under], direction[num_upper] = ( direction[num_upper], direction[num_under], ) print(dice[0])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s589042499
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
# -*- coding:utf-8 -*- class Dice(object): def __init__(self, one, two, thr, fou, fiv, six): self._one = one self._two = two self._thr = thr self._fou = fou self._fiv = fiv self._six = six def roll(self, direction): if direction == "W": dice = self._roll_west() elif direction == "N": dice = self._roll_noth() elif direction == "E": dice = self._roll_east() elif direction == "S": dice = self._roll_south() else: raise ValueError return dice def _roll_west(self): return Dice(self._thr, self._two, self._six, self._one, self._fiv, self._fou) def _roll_noth(self): return Dice(self._two, self._six, self._thr, self._fou, self._one, self._fiv) def _roll_east(self): return Dice(self._fou, self._two, self._one, self._six, self._fiv, self._thr) def _roll_south(self): return Dice(self._fiv, self._one, self._thr, self._fou, self._six, self._two) def get_sides(self): return [self._one, self._two, self._thr, self._fou, self._fiv, self._six] if __name__ == "__main__": args = [int(n) for n in input().split()] dice = Dice(*args) for dire in input(): dice = dice.roll(dire) print(dice.get_sides()[0])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s569084967
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
def roll_positive(list_a: list, list_b: list) -> list: list_a = list_a[1:] + list_a[0:1] # Roll one unit in the positive direction. list_b[0] = list_a[0] # Change the bottom face. list_b[2] = list_a[2] # Change the top face. return [list_a, list_b] def roll_negative(list_a: list, list_b: list) -> list: list_a = list_a[3:] + list_a[0:3] list_b[0] = list_a[0] # Change the bottom face. list_b[2] = list_a[2] # Change the top face. return [list_a, list_b] if __name__ == "__main__": faces_int = list(map(lambda x: int(x), input().split())) # 1,2,3,4,5,6 SN_direction = [faces_int[5], faces_int[4], faces_int[0], faces_int[1]] # 6,5,1,2 WE_direction = [faces_int[5], faces_int[2], faces_int[0], faces_int[3]] # 6,3,1,4 commands = input() for command in commands: if "N" == command: SN_direction, WE_direction = roll_positive(SN_direction, WE_direction) elif "S" == command: SN_direction, WE_direction = roll_negative(SN_direction, WE_direction) elif "E" == command: WE_direction, SN_direction = roll_positive(WE_direction, SN_direction) else: WE_direction, SN_direction = roll_negative(WE_direction, SN_direction) print(f"{SN_direction[2]}") # Print the opposite face of the bottom.
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s788596239
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
class dice: def __init__(self, f0, f1, f2, f3, f4, f5): self.dice_num = [f0, f1, f2, f3, f4, f5] def roll_dice(self, command): for i in command: if i == "N": tmp = self.dice_num[0] self.dice_num[0] = self.dice_num[1] self.dice_num[1] = self.dice_num[5] self.dice_num[5] = self.dice_num[4] self.dice_num[4] = tmp if i == "S": tmp = self.dice_num[0] self.dice_num[0] = self.dice_num[4] self.dice_num[4] = self.dice_num[5] self.dice_num[5] = self.dice_num[1] self.dice_num[1] = tmp if i == "E": tmp = self.dice_num[0] self.dice_num[0] = self.dice_num[3] self.dice_num[3] = self.dice_num[5] self.dice_num[5] = self.dice_num[2] self.dice_num[2] = tmp if i == "W": tmp = self.dice_num[0] self.dice_num[0] = self.dice_num[2] self.dice_num[2] = self.dice_num[5] self.dice_num[5] = self.dice_num[3] self.dice_num[3] = tmp def print_topface(self): print(self.dice_num[0]) if __name__ == "__main__": num_list = list(map(int, input().split())) command_str = input() mydice = dice(*num_list) mydice.roll_dice(command_str) mydice.print_topface()
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s380726783
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
def rotateDice(direction: str, dice: dict) -> dict: if direction == 'S': dice['S'], dice['F'], dice['N'], dice['B'] = dice['F'], dice['N'], dice['B'], dice['S'] elif direction == 'E': dice['E'], dice['F'], dice['W'], dice['B'] = dice['F'], dice['W'], dice['B'], dice['E'] elif direction == 'W': dice['W'], dice['F'], dice['E'], dice['B'] = dice['F'], dice['E'], dice['B'], dice['W'] elif direction == 'N': dice['N'], dice['F'], dice['S'], dice['B'] = dice['F'], dice['S'], dice['B'], dice['N'] return dice dice_list = list(map(int, input().split())) dice = {'FSEWNB'[i]: dice_list[i] for i in range(6)} for c in input(): dice = rotateDice(c, dice) print(dice['F'])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s449455592
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
dice_ = [int(i) for i in input().split()] com = list(input()) dice = { "t": dice_[0], "d": dice_[1], "r": dice_[2], "l": dice_[3], "u": dice_[4], "b": dice_[5], } for i in com: # u # ltr b # d if i == "N": temp = dice["t"] dice["t"] = dice["d"] dice["d"] = dice["b"] dice["b"] = dice["u"] dice["u"] = temp elif i == "S": temp = dice["u"] dice["u"] = dice["b"] dice["b"] = dice["d"] dice["d"] = dice["t"] dice["t"] = temp elif i == "W": temp = dice["t"] dice["t"] = dice["r"] dice["r"] = dice["b"] dice["b"] = dice["l"] dice["l"] = temp elif i == "E": temp = dice["l"] dice["l"] = dice["b"] dice["b"] = dice["r"] dice["r"] = dice["t"] dice["t"] = temp print(dice["t"])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s373128540
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
def rot_func_list(rot, dice): if rot == "N": keys = ["T", "S", "B", "N"] items = dice["S"], dice["B"], dice["N"], dice["T"] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "S": keys = ["T", "S", "B", "N"] items = dice["N"], dice["T"], dice["S"], dice["B"] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "E": keys = ["T", "E", "B", "W"] items = dice["W"], dice["T"], dice["E"], dice["B"] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "W": keys = ["T", "E", "B", "W"] items = dice["E"], dice["B"], dice["W"], dice["T"] new_dice = dict(zip(keys, items)) dice.update(new_dice) input_data = input().split(" ") items = [int(cont) for cont in input_data] keys = ["T", "S", "E", "W", "N", "B"] controls = list(input()) dice = dict(zip(keys, items)) for i in controls: rot_func_list(i, dice) print(dice["T"])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s526460792
Wrong Answer
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
n = [int(i) for i in input().split()] s = input() class Dice(object): def __init__(self, num): self.one = num[0] self.two = num[1] self.three = num[2] self.four = num[3] self.five = num[4] self.six = num[5] def move(self, str, state): if state == 0: if str == "N": return 1 elif str == "E": return 3 elif str == "W": return 2 elif str == "S": return 4 elif state == 1: if str == "N": return 5 elif str == "E": return 3 elif str == "W": return 2 elif str == "S": return 0 elif state == 2: if str == "N": return 1 elif str == "E": return 0 elif str == "W": return 5 elif str == "S": return 4 elif state == 3: if str == "N": return 1 elif str == "E": return 5 elif str == "W": return 0 elif str == "S": return 4 elif state == 4: if str == "N": return 0 elif str == "E": return 3 elif str == "W": return 2 elif str == "S": return 5 elif state == 5: if str == "N": return 4 elif str == "E": return 3 elif str == "W": return 2 elif str == "S": return 1 dice = Dice(n) status = 0 for i in range(len(s)): status = dice.move(s[i], status) print(n[status])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s426602680
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
#!/usr/bin/env python flips = [] die = input().split() for i in range(6): die[i] = [i + 1, die[i]] text = input() for x in text: flips.append(x) for x in flips: if x == "S": for y in die: if 5 in y: y[0] = 1 elif 1 in y: y[0] = 2 elif 2 in y: y[0] = 6 elif 6 in y: y[0] = 5 elif x == "N": for y in die: if 5 in y: y[0] = 6 elif 1 in y: y[0] = 5 elif 2 in y: y[0] = 1 elif 6 in y: y[0] = 2 elif x == "E": for y in die: if 4 in y: y[0] = 1 elif 1 in y: y[0] = 3 elif 3 in y: y[0] = 6 elif 6 in y: y[0] = 4 else: for y in die: if 4 in y: y[0] = 6 elif 1 in y: y[0] = 4 elif 3 in y: y[0] = 1 elif 6 in y: y[0] = 3 for x in die: if x[0] == 1: print(x[1])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s595975290
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
def roll(die, d): if d == "E": return [die[3], die[1], die[0], die[5], die[4], die[2]] if d == "N": return [die[1], die[5], die[2], die[3], die[0], die[4]] if d == "S": return [die[4], die[0], die[2], die[3], die[5], die[1]] if d == "W": return [die[2], die[1], die[5], die[0], die[4], die[3]] die = list(map(int, input().split())) queue = input() for i in range(len(queue)): die = roll(die, queue[i]) print(die[0])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s599967145
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
def North(dice): w = dice[0] dice[0] = dice[1] dice[1] = dice[5] dice[5] = dice[4] dice[4] = w return dice def East(dice): w = Dice[0] dice[0] = dice[3] dice[3] = dice[5] dice[5] = dice[2] dice[2] = w return dice def South(dice): w = dice[0] dice[0] = dice[4] dice[4] = dice[5] dice[5] = dice[1] dice[1] = w return dice def West(dice): w = dice[0] dice[0] = dice[2] dice[2] = dice[5] dice[5] = dice[3] dice[3] = w return dice Dice = input().split() Roll = list(input()) for roll in Roll: if roll == "N": Dice = North(Dice) continue if roll == "E": Dice = East(Dice) continue if roll == "S": Dice = South(Dice) continue if roll == "W": Dice = West(Dice) continue print(Dice[0])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
Print the integer which appears on the top face after the simulation.
s892473849
Accepted
p02383
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
diceface = {"TOP": 0, "FRONT": 1, "RIGHT": 2, "LEFT": 3, "BACK": 4, "BOTTOM": 5} dice = [int(i) for i in input().split(" ")] roll = input() for i in range(len(roll)): if "E" == roll[i]: t = dice[diceface["TOP"]] dice[diceface["TOP"]] = dice[diceface["LEFT"]] dice[diceface["LEFT"]] = dice[diceface["BOTTOM"]] dice[diceface["BOTTOM"]] = dice[diceface["RIGHT"]] dice[diceface["RIGHT"]] = t elif "N" == roll[i]: t = dice[diceface["TOP"]] dice[diceface["TOP"]] = dice[diceface["FRONT"]] dice[diceface["FRONT"]] = dice[diceface["BOTTOM"]] dice[diceface["BOTTOM"]] = dice[diceface["BACK"]] dice[diceface["BACK"]] = t elif "S" == roll[i]: t = dice[diceface["TOP"]] dice[diceface["TOP"]] = dice[diceface["BACK"]] dice[diceface["BACK"]] = dice[diceface["BOTTOM"]] dice[diceface["BOTTOM"]] = dice[diceface["FRONT"]] dice[diceface["FRONT"]] = t elif "W" == roll[i]: t = dice[diceface["TOP"]] dice[diceface["TOP"]] = dice[diceface["RIGHT"]] dice[diceface["RIGHT"]] = dice[diceface["BOTTOM"]] dice[diceface["BOTTOM"]] = dice[diceface["LEFT"]] dice[diceface["LEFT"]] = t print(dice[diceface["TOP"]])
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1) ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2) As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
[{"input": "1 2 4 8 16 32\n SE", "output": "8\n \n\nYou are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face\nlabeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction\nS and then to the direction E, you can see 8 on the top face."}, {"input": "1 2 4 8 16 32\n EESWN", "output": "32"}]
For each dataset, output _p_ decimal values in same order as input. Write a blank line after that. You may output any number of digit and may contain an error less than 1.0e-6.
s814649395
Wrong Answer
p00644
Input consists of several datasets. The first line of each dataset contains three integers _n_ , _m_ , _p_ , which means the number of nodes and edges of the graph, and the number of the children. Each node are numbered 0 to _n_ -1. Following _m_ lines contains information about edges. Each line has three integers. The first two integers means nodes on two endpoints of the edge. The third one is weight of the edge. Next _p_ lines represent _c_[_i_] respectively. Input terminates when _n_ = _m_ = _p_ = 0.
vertex, edge, children = (int(n) for n in input().split(" ")) graph = [] child = [] for e in range(edge): graph.append([int(n) for n in input().split(" ")]) for c in range(children): child.append(int(input())) print(1)
H: Winter Bells The best night ever in the world has come! It's 8 p.m. of December 24th, yes, the night of Cristmas Eve. Santa Clause comes to a silent city with ringing bells. Overtaking north wind, from a sleigh a reindeer pulls she shoot presents to soxes hanged near windows for children. The sleigh she is on departs from a big christmas tree on the fringe of the city. Miracle power that the christmas tree spread over the sky like a web and form a paths that the sleigh can go on. Since the paths with thicker miracle power is easier to go, these paths can be expressed as undirected weighted graph. Derivering the present is very strict about time. When it begins dawning the miracle power rapidly weakens and Santa Clause can not continue derivering any more. Her pride as a Santa Clause never excuses such a thing, so she have to finish derivering before dawning. The sleigh a reindeer pulls departs from christmas tree (which corresponds to 0th node), and go across the city to the opposite fringe (_n_ -1 th node) along the shortest path. Santa Clause create presents from the miracle power and shoot them from the sleigh the reindeer pulls at his full power. If there are two or more shortest paths, the reindeer selects one of all shortest paths with equal probability and go along it. By the way, in this city there are _p_ children that wish to see Santa Clause and are looking up the starlit sky from their home. Above the _i_ -th child's home there is a cross point of the miracle power that corresponds to _c_[_i_]-th node of the graph. The child can see Santa Clause if (and only if) Santa Clause go through the node. Please find the probability that each child can see Santa Clause.
[{"input": "2 1\n 0 1 2\n 1 2 3\n 1\n 4 5 2\n 0 1 1\n 0 2 1\n 1 2 1\n 1 3 1\n 2 3 1\n 1\n 2\n 0 0 0", "output": ".00000000\n \n 0.50000000\n 0.50000000"}]
Print the count modulo 1000000007. * * *
s677871133
Runtime Error
p02679
Input is given from Standard Input in the following format: N A_1 B_1 : A_N B_N
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda: sys.stdin.readline().rstrip() from cmath import phase from math import gcd from collections import Counter def resolve(): n = int(input()) zero = 0 counter = Counter() for _ in range(n): x, y = map(int, input().split()) # eliminate 0 vector if x == 0 and y == 0: zero += 1 continue # standardize (0 <= arg(z) < pi) g = gcd(x, y) x //= g y //= g if y < 0: x *= -1 y *= -1 elif y == 0: x, y = 1, 0 counter[complex(x, y)] += 1 k = len(counter) C = list(counter.items()) C.sort(key=lambda tup: phase(tup[0])) vector = [tup[0] for tup in C] count = [tup[1] for tup in C] res = 0 dp = [0] * (k + 1) dp[0] = 1 for i in range(k): z = vector[i] vert = z.imag - z.real * 1j dp[i + 1] += dp[i] dp[i + 1] += ( (pow(2, count[i], MOD) - 1) * dp[i] * pow(2, -counter[vert] % (MOD - 1), MOD) ) dp[i + 1] %= MOD res = dp[k] res -= 1 res += zero assert zero > 0 print(res % MOD) resolve()
Statement We have caught N sardines. The _deliciousness_ and _fragrantness_ of the i-th sardine is A_i and B_i, respectively. We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time. The i-th and j-th sardines (i \neq j) are on bad terms if and only if A_i \cdot A_j + B_i \cdot B_j = 0. In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.
[{"input": "3\n 1 2\n -1 1\n 2 -1", "output": "5\n \n\nThere are five ways to choose the set of sardines, as follows:\n\n * The 1-st\n * The 1-st and 2-nd\n * The 2-nd\n * The 2-nd and 3-rd\n * The 3-rd\n\n* * *"}, {"input": "10\n 3 2\n 3 2\n -1 1\n 2 -1\n -3 -9\n -8 12\n 7 7\n 8 1\n 8 2\n 8 4", "output": "479"}]
Print the count modulo 1000000007. * * *
s152855605
Runtime Error
p02679
Input is given from Standard Input in the following format: N A_1 B_1 : A_N B_N
import sys sys.setrecursionlimit(2147483647) n = int(input()) mod = 10**9 + 7 pp = {} pp_k = set([]) pm = {} pm_k = set([]) from fractions import gcd for _ in range(n): a, b = map(int, input().split()) tmp = gcd(a, b) a = a // tmp b = b // tmp if a * b > 0: if (a, b) in pp_k: pp[(a, b)] += 1 else: pp[(a, b)] = 1 pp_k.add((a, b)) else: if (a, b) in pm_k: pm[(a, b)] += 1 else: pm[(a, b)] = 1 pm_k.add((a, b)) result = pow(2, n, mod) - 1 def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n - r] % p p = mod # 割る数 N = 10**6 # N は必要分だけ用意する fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) # print(pp_k,pm_k) for item in pp_k: tmp = 0 a, b = item[0], item[1] cnt_pp = pp[item] aa = -1 * a bb = b cnt_pm = 0 hoge = (bb, aa) # print(hoge) if hoge in pm_k: # print("Yes") cnt_pm += pm[hoge] aa = a bb = -1 * b hoge = (bb, aa) if hoge in pm_k: cnt_pm += pm[hoge] # print(item,cnt_pm) if cnt_pm > 0: tmp += ( pow(2, max(0, n - cnt_pm - cnt_pp), mod) * (pow(2, cnt_pp, mod) - 1) * (pow(2, cnt_pp, mod) - 1) ) # print(pow(2,max(0,n-cnt_pm-cnt_pp),mod),(pow(2,cnt_pp,mod)-1),(pow(2,cnt_pp,mod)-1)) result -= tmp print(result % mod)
Statement We have caught N sardines. The _deliciousness_ and _fragrantness_ of the i-th sardine is A_i and B_i, respectively. We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time. The i-th and j-th sardines (i \neq j) are on bad terms if and only if A_i \cdot A_j + B_i \cdot B_j = 0. In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.
[{"input": "3\n 1 2\n -1 1\n 2 -1", "output": "5\n \n\nThere are five ways to choose the set of sardines, as follows:\n\n * The 1-st\n * The 1-st and 2-nd\n * The 2-nd\n * The 2-nd and 3-rd\n * The 3-rd\n\n* * *"}, {"input": "10\n 3 2\n 3 2\n -1 1\n 2 -1\n -3 -9\n -8 12\n 7 7\n 8 1\n 8 2\n 8 4", "output": "479"}]
Print the count modulo 1000000007. * * *
s153784174
Wrong Answer
p02679
Input is given from Standard Input in the following format: N A_1 B_1 : A_N B_N
mod = 1000000007 N = int(input()) p_p = [] p_m = [] m_p = [] m_m = [] z_z = [] z_p = [] z_m = [] p_z = [] m_z = [] if N == 1: print(1) else: for _ in range(N): tmp = list(map(int, input().split())) if tmp[0] > 0: if tmp[1] > 0: p_p.append(tmp) elif tmp[0] == 0: p_z.append(tmp) else: p_m.append(tmp) if tmp[0] == 0: if tmp[1] > 0: z_p.append(tmp) elif tmp[0] == 0: z_z.append(tmp) else: z_m.append(tmp) if tmp[0] < 0: if tmp[1] > 0: m_p.append(tmp) elif tmp[0] == 0: m_z.append(tmp) else: m_m.append(tmp) counter = 0 counter += len(z_z) * (N - len(z_z)) counter = counter % mod counter += (len(z_p) + len(z_m)) * (len(p_z) + len(m_z)) counter = counter % mod for a in p_p: for b in p_m + m_p: if a[0] * b[0] + a[1] * b[1] == 0: counter += 1 counter = counter % mod for a in m_m: for b in p_m + m_p: if a[0] * b[0] + a[1] * b[1] == 0: counter += 1 counter = counter % mod all_num = (2**N - 1) % mod answer = (all_num - counter * (2 ** (N - 2))) % mod print(answer)
Statement We have caught N sardines. The _deliciousness_ and _fragrantness_ of the i-th sardine is A_i and B_i, respectively. We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time. The i-th and j-th sardines (i \neq j) are on bad terms if and only if A_i \cdot A_j + B_i \cdot B_j = 0. In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.
[{"input": "3\n 1 2\n -1 1\n 2 -1", "output": "5\n \n\nThere are five ways to choose the set of sardines, as follows:\n\n * The 1-st\n * The 1-st and 2-nd\n * The 2-nd\n * The 2-nd and 3-rd\n * The 3-rd\n\n* * *"}, {"input": "10\n 3 2\n 3 2\n -1 1\n 2 -1\n -3 -9\n -8 12\n 7 7\n 8 1\n 8 2\n 8 4", "output": "479"}]
Print the count modulo 1000000007. * * *
s114028934
Runtime Error
p02679
Input is given from Standard Input in the following format: N A_1 B_1 : A_N B_N
import math def m(L): (a, b) = L g = math.gcd(a, b) if b == 0: return (1, 0) elif b > 0: return (a // g, b // g) else: return (-a // g, -b // g) def w(x, y): if x == 0: return 2**y elif y == 0: return 2**x else: return 2**x + 2**y - 1 N = int(input()) D = [] for i in range(N): (A, B) = map(int, input().split()) D.append((A, B)) O = 0 for u in range(N): if D[u] == (0, 0): D.remove((0, 0)) O = 1 M = list(map(m, D)) J = {} for m in M: if m in J: J[m] += 1 else: J[m] = 1 K = {} for u in J: (a, b) = u p = J[u] if a >= 0: (c, d) = (-b, a) else: (c, d) = (b, -a) f = True if (a, b) in K: (x, y) = K[(a, b)] if a >= 0: x += p else: y += p K[(a, b)] = (x, y) f = False elif f and ((c, d) in K): (x, y) = K[(c, d)] if c <= 0: x += p else: y += p K[(c, d)] = (x, y) f = False elif f: if a >= 0: K[(a, b)] = (p, 0) else: K[(a, b)] = (0, p) G = [w(x, y) for (x, y) in K.values()] r = 1 V = 1000000007 for g in G: r = (r * g) % V print(r - 1 + O)
Statement We have caught N sardines. The _deliciousness_ and _fragrantness_ of the i-th sardine is A_i and B_i, respectively. We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time. The i-th and j-th sardines (i \neq j) are on bad terms if and only if A_i \cdot A_j + B_i \cdot B_j = 0. In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.
[{"input": "3\n 1 2\n -1 1\n 2 -1", "output": "5\n \n\nThere are five ways to choose the set of sardines, as follows:\n\n * The 1-st\n * The 1-st and 2-nd\n * The 2-nd\n * The 2-nd and 3-rd\n * The 3-rd\n\n* * *"}, {"input": "10\n 3 2\n 3 2\n -1 1\n 2 -1\n -3 -9\n -8 12\n 7 7\n 8 1\n 8 2\n 8 4", "output": "479"}]
Print the plural form of the given Taknese word. * * *
s278314201
Accepted
p02546
Input is given from Standard Input in the following format: S
s=input() if s[len(s)-1]=="s": s+="es" else: s+="s" print(s)
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s569056143
Wrong Answer
p02546
Input is given from Standard Input in the following format: S
z = input() if z[-1] in ["s", "x", "z", "ch", "sh"]: print(z + "es") elif z[-1] == "y" and z[-2] not in ["a", "e", "i", "o", "u"]: print(z[:-1] + "ies") elif z[-2:] == "fe": print(z[:-2] + "ves") elif z[-1] == "f": print(z[:-1] + "ves") elif z[-1] == "o" and z[-2] not in ["a", "e", "i", "o", "u"]: print(z[:-1] + "oes") else: print(z + "s")
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s070869098
Runtime Error
p02546
Input is given from Standard Input in the following format: S
N = int(input()) A = 1 B = 1 C = 1 answer = 0 while C < N: B = 1 while B < N: A = 1 while A < N: if (A * B) + C == N: answer += 1 A += 1 B += 1 C += 1 print(answer)
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s731246078
Runtime Error
p02546
Input is given from Standard Input in the following format: S
n, x, m = map(int, input().split()) a = x s = 0 h = [] h.append(a) i = 0 fl = 0 while i < n: s += a a = (a * a) % m if a == 0: break i += 1 if fl == 0 and a in h: fl = 1 po = h.index(a) ss = 0 for j in range(po): ss += h[j] s2 = s - ss f = (n - po) // (i - po) s2 *= f s = s2 + ss i2 = i - po i2 *= f i = i2 + po else: h.append(a) print(s)
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s260237616
Wrong Answer
p02546
Input is given from Standard Input in the following format: S
print((input() + "s").replace("ss", "ses"))
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s375503948
Accepted
p02546
Input is given from Standard Input in the following format: S
words = input() if words[-1] != "s": words += "s" else: words += "es" print(words)
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s858188836
Runtime Error
p02546
Input is given from Standard Input in the following format: S
N = int(input()) cnt = 0 for a in range(1, N // 2 + 1): for b in range(a, N): if N - a * b > 0: if a == b: cnt += 1 else: cnt += 2 print(cnt)
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s606679188
Runtime Error
p02546
Input is given from Standard Input in the following format: S
nk = input().split() n = int(nk[0]) k = int(nk[1]) a = [] for i in range(k): lr = input().split() l = int(lr[0]) r = int(lr[1]) for i in range(l, r + 1): a.append(i) a = list(set(a)) dp = [0] * n dp[0] = 1 for i in range(1, n): for j in a: if i >= j: dp[i] += dp[i - j] print(dp[-1])
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s226252955
Accepted
p02546
Input is given from Standard Input in the following format: S
a = list(input()) if a[len(a) - 1] == "s": for i in range(len(a)): print(a[i], end="") print("es", end="") else: for i in range(len(a)): print(a[i], end="") print("s", end="")
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s506763093
Wrong Answer
p02546
Input is given from Standard Input in the following format: S
for y in range(10**3): for z in range(10**3): if 1 + y * y == 2 * z: print("x=1,y=" + str(y) + ",z=" + str(z))
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s751027881
Wrong Answer
p02546
Input is given from Standard Input in the following format: S
print(input() + "s")
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s802543888
Runtime Error
p02546
Input is given from Standard Input in the following format: S
def main(): N, X, M = map(int, input().split()) NN = N li = [] while X not in li and N != 0: li = li + [X] X = X**2 % M N -= 1 if N == 0: print(sum(x for x in li)) elif N != 0 and X in li: l = len(li) s = li.index(X) T = l - s q = (NN - s) // T r = (NN - s) % T print( sum(li[i] for i in range(s)) + sum(li[i] for i in range(s, len(li))) * q + sum(li[i] for i in range(s, s + r)) ) main()
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s044669759
Runtime Error
p02546
Input is given from Standard Input in the following format: S
import sys readline = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9 + 7 # mod = 998244353 INF = 10**18 eps = 10**-7 n, x, m = map(int, input().split()) s = set() l = [] flag = False cnt = 1 ans = 0 l.append(x) for i in range(m): if x not in s: s.add(x) x = (x**2) % m l.append(x) else: break h = len(l) cnt = 1 num = 0 for i in range(h): if l[i] == l[h - 1]: while l[i + cnt] != l[h - 1]: cnt += 1 flag = True break else: num += 1 ans += l[i] n -= num if num != 0: del l[h - 1] del l[0:num] if n >= len(l): mod = n % len(l) ans += sum(l) * (n // len(l)) for i in range(1, mod): ans += l[i - 1] print(ans) else: for i in range(n): ans += l[i] print(ans)
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
Print the plural form of the given Taknese word. * * *
s943166418
Accepted
p02546
Input is given from Standard Input in the following format: S
x = str(input("")) lists = [] lists.append(x) y = x[-1] if y != "s": addd = x + "s" else: addd = x + "es" print(addd)
Statement In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: * If a noun's singular form does not end with `s`, append `s` to the end of the singular form. * If a noun's singular form ends with `s`, append `es` to the end of the singular form. You are given the singular form S of a Taknese noun. Output its plural form.
[{"input": "apple", "output": "apples\n \n\n`apple` ends with `e`, so its plural form is `apples`.\n\n* * *"}, {"input": "bus", "output": "buses\n \n\n`bus` ends with `s`, so its plural form is `buses`.\n\n* * *"}, {"input": "box", "output": "boxs"}]
For each query, print the number of the connected components consisting of blue squares in the region. * * *
s956679277
Runtime Error
p03707
The input is given from Standard Input in the following format: N M Q S_{1,1}..S_{1,M} : S_{N,1}..S_{N,M} x_{1,1} y_{i,1} x_{i,2} y_{i,2} : x_{Q,1} y_{Q,1} x_{Q,2} y_{Q,2}
import sys input = sys.stdin.readline N, M, Q = map(int, input().split()) S = [list(map(int, list(input())[:-1])) for _ in range(N)] e = [[0] * M for _ in range(N + 1)] for i in range(1, N + 1): for j in range(M - 1): e[i][j + 1] = e[i][j] + ((S[i - 1][j] == 1) and (S[i - 1][j + 1] == 1)) for i in range(1, N): for j in range(M): e[i + 1][j] += e[i][j] T = [[0] * N for _ in range(M)] for i in range(N): for j in range(M): T[j][i] = S[i][j] N, M = M, N ee = [[0] * M for _ in range(N + 1)] for i in range(1, N + 1): for j in range(M - 1): ee[i][j + 1] = ee[i][j] + ((T[i - 1][j] == 1) and (T[i - 1][j + 1] == 1)) for i in range(1, N): for j in range(M): ee[i + 1][j] += ee[i][j] cs = [[0] * (M + 1) for _ in range(N + 1)] for i in range(1, N + 1): for j in range(M): cs[i][j + 1] = cs[i][j] + (S[i - 1][j] == 1) for i in range(1, N): for j in range(M + 1): cs[i + 1][j] += cs[i][j] # print(cs) for i in range(Q): u, l, d, r = map(lambda x: int(x) - 1, input().split()) rese = e[d + 1][r] - e[d + 1][l] - e[u][r] + e[u][l] resee = ee[r + 1][d] - ee[r + 1][u] - ee[l][d] + ee[l][u] res = cs[d + 1][r + 1] - cs[d + 1][l] - cs[u][r + 1] + cs[u][l] print(res - rese - resee)
Statement Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white. For every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once. Phantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region? Process all the queries.
[{"input": "3 4 4\n 1101\n 0110\n 1101\n 1 1 3 4\n 1 1 3 1\n 2 2 3 4\n 1 2 2 4", "output": "3\n 2\n 2\n 2\n \n\n![](https://atcoder.jp/img/agc015/7aa4a2252f50a19fc18e0cec01368a2a.png)\n\nIn the first query, the whole grid is specified. There are three components\nconsisting of blue squares, and thus 3 should be printed.\n\nIn the second query, the region within the red frame is specified. There are\ntwo components consisting of blue squares, and thus 2 should be printed. Note\nthat squares that belong to the same component in the original grid may belong\nto different components.\n\n* * *"}, {"input": "5 5 6\n 11010\n 01110\n 10101\n 11101\n 01010\n 1 1 5 5\n 1 2 4 5\n 2 3 3 4\n 3 3 3 3\n 3 1 3 5\n 1 1 3 4", "output": "3\n 2\n 1\n 1\n 3\n 2"}]
For each query, print the number of the connected components consisting of blue squares in the region. * * *
s802071026
Accepted
p03707
The input is given from Standard Input in the following format: N M Q S_{1,1}..S_{1,M} : S_{N,1}..S_{N,M} x_{1,1} y_{i,1} x_{i,2} y_{i,2} : x_{Q,1} y_{Q,1} x_{Q,2} y_{Q,2}
import sys n, m, q = map(int, input().split()) dp1 = [[0] * (m + 1) for _ in range(n + 1)] dpv = [[0] * (m + 1) for _ in range(n + 1)] dph = [[0] * (m + 1) for _ in range(n + 1)] prev_s = "0" * m for i in range(n): s = input() for j in range(m): is1 = s[j] == "1" additional = 0 if is1: dp1[i + 1][j + 1] = 1 if i > 0 and prev_s[j] == "1": dpv[i + 1][j + 1] = 1 if j > 0 and s[j - 1] == "1": dph[i + 1][j + 1] = 1 prev_s = s for i in range(1, n + 1): for j in range(1, m + 1): dp1[i][j] += dp1[i][j - 1] dpv[i][j] += dpv[i][j - 1] dph[i][j] += dph[i][j - 1] for j in range(1, m + 1): for i in range(1, n + 1): dp1[i][j] += dp1[i - 1][j] dpv[i][j] += dpv[i - 1][j] dph[i][j] += dph[i - 1][j] mp = map(int, sys.stdin.read().split()) buf = [] for x1, y1, x2, y2 in zip(mp, mp, mp, mp): cnt1 = dp1[x2][y2] - dp1[x1 - 1][y2] - dp1[x2][y1 - 1] + dp1[x1 - 1][y1 - 1] ver1 = dpv[x2][y2] - dpv[x1][y2] - dpv[x2][y1 - 1] + dpv[x1][y1 - 1] hor1 = dph[x2][y2] - dph[x1 - 1][y2] - dph[x2][y1] + dph[x1 - 1][y1] buf.append(cnt1 - ver1 - hor1) print("\n".join(map(str, buf)))
Statement Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white. For every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once. Phantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region? Process all the queries.
[{"input": "3 4 4\n 1101\n 0110\n 1101\n 1 1 3 4\n 1 1 3 1\n 2 2 3 4\n 1 2 2 4", "output": "3\n 2\n 2\n 2\n \n\n![](https://atcoder.jp/img/agc015/7aa4a2252f50a19fc18e0cec01368a2a.png)\n\nIn the first query, the whole grid is specified. There are three components\nconsisting of blue squares, and thus 3 should be printed.\n\nIn the second query, the region within the red frame is specified. There are\ntwo components consisting of blue squares, and thus 2 should be printed. Note\nthat squares that belong to the same component in the original grid may belong\nto different components.\n\n* * *"}, {"input": "5 5 6\n 11010\n 01110\n 10101\n 11101\n 01010\n 1 1 5 5\n 1 2 4 5\n 2 3 3 4\n 3 3 3 3\n 3 1 3 5\n 1 1 3 4", "output": "3\n 2\n 1\n 1\n 3\n 2"}]
For each query, print the number of the connected components consisting of blue squares in the region. * * *
s433080132
Wrong Answer
p03707
The input is given from Standard Input in the following format: N M Q S_{1,1}..S_{1,M} : S_{N,1}..S_{N,M} x_{1,1} y_{i,1} x_{i,2} y_{i,2} : x_{Q,1} y_{Q,1} x_{Q,2} y_{Q,2}
def input_test(): import sys input = sys.stdin.readline H, W, Q = map(int, input().split()) S = [list(map(lambda x: x == "1", input())) for _ in range(H)] for _ in range(Q): x1, y1, x2, y2 = map(int, input().split()) input_test()
Statement Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white. For every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once. Phantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region? Process all the queries.
[{"input": "3 4 4\n 1101\n 0110\n 1101\n 1 1 3 4\n 1 1 3 1\n 2 2 3 4\n 1 2 2 4", "output": "3\n 2\n 2\n 2\n \n\n![](https://atcoder.jp/img/agc015/7aa4a2252f50a19fc18e0cec01368a2a.png)\n\nIn the first query, the whole grid is specified. There are three components\nconsisting of blue squares, and thus 3 should be printed.\n\nIn the second query, the region within the red frame is specified. There are\ntwo components consisting of blue squares, and thus 2 should be printed. Note\nthat squares that belong to the same component in the original grid may belong\nto different components.\n\n* * *"}, {"input": "5 5 6\n 11010\n 01110\n 10101\n 11101\n 01010\n 1 1 5 5\n 1 2 4 5\n 2 3 3 4\n 3 3 3 3\n 3 1 3 5\n 1 1 3 4", "output": "3\n 2\n 1\n 1\n 3\n 2"}]
For each query, print the number of the connected components consisting of blue squares in the region. * * *
s527802583
Runtime Error
p03707
The input is given from Standard Input in the following format: N M Q S_{1,1}..S_{1,M} : S_{N,1}..S_{N,M} x_{1,1} y_{i,1} x_{i,2} y_{i,2} : x_{Q,1} y_{Q,1} x_{Q,2} y_{Q,2}
import numpy as np N, M, Q = map(int, input().split()) S = np.zeros((N + 1, M + 1), dtype="int") for n in range(1, N + 1): S[n, 1:] = list(map(int, list(input()))) # count nodes N_cum = np.cumsum(np.cumsum(S, axis=0), axis=1) # count edges(row) ER_cum = np.cumsum(np.cumsum(S[:N, :] * S[1:, :], axis=0), axis=1) # count edges(col) EC_cum = np.cumsum(np.cumsum(S[:, :M] * S[:, 1:], axis=0), axis=1) sol_list = [] for _ in range(Q): x1, y1, x2, y2 = map(int, input().split()) # nodes N_nodes = ( N_cum[x2, y2] - N_cum[x1 - 1, y2] - N_cum[x2, y1 - 1] + N_cum[x1 - 1, y1 - 1] ) # edges(row) N_edges1 = ( ER_cum[x2 - 1, y2] - ER_cum[x1 - 1, y2] - ER_cum[x2 - 1, y1 - 1] + ER_cum[x1 - 1, y1 - 1] ) # edges(col) N_edges2 = ( EC_cum[x2, y2 - 1] - EC_cum[x1 - 1, y2 - 1] - EC_cum[x2, y1 - 1] + EC_cum[x1 - 1, y1 - 1] ) N_nodes - N_edges1 - N_edges2 for q in range(Q): print(sol_list[q])
Statement Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white. For every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once. Phantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region? Process all the queries.
[{"input": "3 4 4\n 1101\n 0110\n 1101\n 1 1 3 4\n 1 1 3 1\n 2 2 3 4\n 1 2 2 4", "output": "3\n 2\n 2\n 2\n \n\n![](https://atcoder.jp/img/agc015/7aa4a2252f50a19fc18e0cec01368a2a.png)\n\nIn the first query, the whole grid is specified. There are three components\nconsisting of blue squares, and thus 3 should be printed.\n\nIn the second query, the region within the red frame is specified. There are\ntwo components consisting of blue squares, and thus 2 should be printed. Note\nthat squares that belong to the same component in the original grid may belong\nto different components.\n\n* * *"}, {"input": "5 5 6\n 11010\n 01110\n 10101\n 11101\n 01010\n 1 1 5 5\n 1 2 4 5\n 2 3 3 4\n 3 3 3 3\n 3 1 3 5\n 1 1 3 4", "output": "3\n 2\n 1\n 1\n 3\n 2"}]
For each query, print the number of the connected components consisting of blue squares in the region. * * *
s977082224
Wrong Answer
p03707
The input is given from Standard Input in the following format: N M Q S_{1,1}..S_{1,M} : S_{N,1}..S_{N,M} x_{1,1} y_{i,1} x_{i,2} y_{i,2} : x_{Q,1} y_{Q,1} x_{Q,2} y_{Q,2}
import os import sys import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10**9) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # MOD = 998244353 N, M, Q = list(map(int, sys.stdin.buffer.readline().split())) S = [list(sys.stdin.buffer.readline().decode().rstrip()) for _ in range(N)] XY = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)] def count_v(x1, y1, x2, y2): return ( counts_cum[x2][y2] - counts_cum[x1 - 1][y2] - counts_cum[x2][y1 - 1] + counts_cum[x1 - 1][y1 - 1] ) def count_ev(x1, y1, x2, y2): return ( edges_v_cum[x2][y2] - edges_v_cum[x1][y2] - edges_v_cum[x2][y1 - 1] + edges_v_cum[x1][y1 - 1] ) def count_eh(x1, y1, x2, y2): return ( edges_h_cum[x2][y2] - edges_h_cum[x1 - 1][y2] - edges_h_cum[x2][y1] + edges_h_cum[x1 - 1][y1] ) S = np.array(S, dtype=int) == 1 vs = [] e1 = [] e2 = [] counts_cum = np.zeros((N + 1, M + 1), dtype=np.int32) counts_cum[1:, 1:] = S.cumsum(axis=0).cumsum(axis=1) counts_cum = counts_cum.tolist() for x1, y1, x2, y2 in XY: vs.append(count_v(x1, y1, x2, y2)) del counts_cum edges_v_cum = np.zeros((N + 1, M + 1), dtype=np.int16) edges_v_cum[2:, 1:] = (S[1:] & S[:-1]).cumsum(axis=0).cumsum(axis=1) edges_v_cum = edges_v_cum.tolist() for x1, y1, x2, y2 in XY: e1.append(count_ev(x1, y1, x2, y2)) del edges_v_cum edges_h_cum = np.zeros((N + 1, M + 1), dtype=np.int16) edges_h_cum[1:, 2:] = (S[:, 1:] & S[:, :-1]).cumsum(axis=0).cumsum(axis=1) edges_h_cum = edges_h_cum.tolist() for x1, y1, x2, y2 in XY: e2.append(count_eh(x1, y1, x2, y2)) del edges_h_cum del S ans = (np.array(vs) - np.array(e1) - np.array(e2)).astype(int) print(*ans, sep="\n")
Statement Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white. For every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once. Phantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region? Process all the queries.
[{"input": "3 4 4\n 1101\n 0110\n 1101\n 1 1 3 4\n 1 1 3 1\n 2 2 3 4\n 1 2 2 4", "output": "3\n 2\n 2\n 2\n \n\n![](https://atcoder.jp/img/agc015/7aa4a2252f50a19fc18e0cec01368a2a.png)\n\nIn the first query, the whole grid is specified. There are three components\nconsisting of blue squares, and thus 3 should be printed.\n\nIn the second query, the region within the red frame is specified. There are\ntwo components consisting of blue squares, and thus 2 should be printed. Note\nthat squares that belong to the same component in the original grid may belong\nto different components.\n\n* * *"}, {"input": "5 5 6\n 11010\n 01110\n 10101\n 11101\n 01010\n 1 1 5 5\n 1 2 4 5\n 2 3 3 4\n 3 3 3 3\n 3 1 3 5\n 1 1 3 4", "output": "3\n 2\n 1\n 1\n 3\n 2"}]
For each query, print the number of the connected components consisting of blue squares in the region. * * *
s955768885
Accepted
p03707
The input is given from Standard Input in the following format: N M Q S_{1,1}..S_{1,M} : S_{N,1}..S_{N,M} x_{1,1} y_{i,1} x_{i,2} y_{i,2} : x_{Q,1} y_{Q,1} x_{Q,2} y_{Q,2}
N, M, Q = map(int, input().split()) G = [input() for i in range(N)] node = [[0] * (M + 1)] edge_x = [[0] * M] edge_y = [[0] * (M + 1)] for i in range(1, N + 1): n, e_x, e_y = [0], [0], [0] for j in range(1, M + 1): if G[i - 1][j - 1] == "1": n.append(n[-1] + node[i - 1][j] - node[i - 1][j - 1] + 1) else: n.append(n[-1] + node[i - 1][j] - node[i - 1][j - 1]) if j < M: if G[i - 1][j - 1] == "1" and G[i - 1][j] == "1": e_x.append(e_x[-1] + edge_x[i - 1][j] - edge_x[i - 1][j - 1] + 1) else: e_x.append(e_x[-1] + edge_x[i - 1][j] - edge_x[i - 1][j - 1]) if i < N: if G[i - 1][j - 1] == "1" and G[i][j - 1] == "1": e_y.append(e_y[-1] + edge_y[i - 1][j] - edge_y[i - 1][j - 1] + 1) else: e_y.append(e_y[-1] + edge_y[i - 1][j] - edge_y[i - 1][j - 1]) node.append(n) edge_x.append(e_x) if i < N: edge_y.append(e_y) for q in range(Q): x1, y1, x2, y2 = map(int, input().split()) n = node[x2][y2] - node[x1 - 1][y2] - node[x2][y1 - 1] + node[x1 - 1][y1 - 1] e_y = ( edge_y[x2 - 1][y2] - edge_y[x1 - 1][y2] - edge_y[x2 - 1][y1 - 1] + edge_y[x1 - 1][y1 - 1] ) e_x = ( edge_x[x2][y2 - 1] - edge_x[x1 - 1][y2 - 1] - edge_x[x2][y1 - 1] + edge_x[x1 - 1][y1 - 1] ) e = e_x + e_y print(n - e)
Statement Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white. For every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once. Phantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region? Process all the queries.
[{"input": "3 4 4\n 1101\n 0110\n 1101\n 1 1 3 4\n 1 1 3 1\n 2 2 3 4\n 1 2 2 4", "output": "3\n 2\n 2\n 2\n \n\n![](https://atcoder.jp/img/agc015/7aa4a2252f50a19fc18e0cec01368a2a.png)\n\nIn the first query, the whole grid is specified. There are three components\nconsisting of blue squares, and thus 3 should be printed.\n\nIn the second query, the region within the red frame is specified. There are\ntwo components consisting of blue squares, and thus 2 should be printed. Note\nthat squares that belong to the same component in the original grid may belong\nto different components.\n\n* * *"}, {"input": "5 5 6\n 11010\n 01110\n 10101\n 11101\n 01010\n 1 1 5 5\n 1 2 4 5\n 2 3 3 4\n 3 3 3 3\n 3 1 3 5\n 1 1 3 4", "output": "3\n 2\n 1\n 1\n 3\n 2"}]
For each query, print the number of the connected components consisting of blue squares in the region. * * *
s654345202
Accepted
p03707
The input is given from Standard Input in the following format: N M Q S_{1,1}..S_{1,M} : S_{N,1}..S_{N,M} x_{1,1} y_{i,1} x_{i,2} y_{i,2} : x_{Q,1} y_{Q,1} x_{Q,2} y_{Q,2}
n, m, q = map(int, input().split()) s, v, el, eu = ([[0] * (m + 2) for _ in range(n + 2)] for _ in range(4)) for i in range(1, n + 1): s[i][1 : m + 1] = map(int, input()) for j in range(1, m + 1): v[i][j] = v[i][j - 1] + s[i][j] el[i][j] = el[i][j - 1] + s[i][j] * s[i][j - 1] eu[i][j] = eu[i][j - 1] + s[i][j] * s[i - 1][j] for i in range(2, n + 1): for j in range(1, m + 1): v[i][j] += v[i - 1][j] el[i][j] += el[i - 1][j] eu[i][j] += eu[i - 1][j] for _ in range(q): x1, y1, x2, y2 = map(int, input().split()) print( v[x2][y2] - v[x1 - 1][y2] - v[x2][y1 - 1] + v[x1 - 1][y1 - 1] - (el[x2][y2] - el[x1 - 1][y2] - el[x2][y1] + el[x1 - 1][y1]) - (eu[x2][y2] - eu[x1][y2] - eu[x2][y1 - 1] + eu[x1][y1 - 1]) )
Statement Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white. For every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once. Phantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region? Process all the queries.
[{"input": "3 4 4\n 1101\n 0110\n 1101\n 1 1 3 4\n 1 1 3 1\n 2 2 3 4\n 1 2 2 4", "output": "3\n 2\n 2\n 2\n \n\n![](https://atcoder.jp/img/agc015/7aa4a2252f50a19fc18e0cec01368a2a.png)\n\nIn the first query, the whole grid is specified. There are three components\nconsisting of blue squares, and thus 3 should be printed.\n\nIn the second query, the region within the red frame is specified. There are\ntwo components consisting of blue squares, and thus 2 should be printed. Note\nthat squares that belong to the same component in the original grid may belong\nto different components.\n\n* * *"}, {"input": "5 5 6\n 11010\n 01110\n 10101\n 11101\n 01010\n 1 1 5 5\n 1 2 4 5\n 2 3 3 4\n 3 3 3 3\n 3 1 3 5\n 1 1 3 4", "output": "3\n 2\n 1\n 1\n 3\n 2"}]
For each query, print the number of the connected components consisting of blue squares in the region. * * *
s790129666
Runtime Error
p03707
The input is given from Standard Input in the following format: N M Q S_{1,1}..S_{1,M} : S_{N,1}..S_{N,M} x_{1,1} y_{i,1} x_{i,2} y_{i,2} : x_{Q,1} y_{Q,1} x_{Q,2} y_{Q,2}
N, M, Q = list(map(int, input().split())) S = [list(map(int, list(input()))) for i in range(N)] dx = [-1, 0, 1, 0] dy = [0, 1, 0, -1] def dfs(_x, _y): target_map[_x][_y] = 0 for l in range(0, 4): nx = _x + dx[l] ny = _y + dy[l] if 0 <= nx <= tmp_N and 0 <= ny <= tmp_M and target_map[nx][ny] == 1: dfs(nx, ny) for i in range(Q): x1, y1, x2, y2 = list(map(int, input().split())) target_map = [] for j in range(x1 - 1, x2): tmp_list = [] for i in range(y1 - 1, y2): tmp_list.append(S[j][i]) target_map.append(tmp_list) res = 0 tmp_N = x2 - x1 tmp_M = y2 - y1 for j in range(0, tmp_N + 1): for k in range(0, tmp_M + 1): if target_map[j][k] == 1: dfs(j, k) res += 1 print(res)
Statement Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white. For every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once. Phantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region? Process all the queries.
[{"input": "3 4 4\n 1101\n 0110\n 1101\n 1 1 3 4\n 1 1 3 1\n 2 2 3 4\n 1 2 2 4", "output": "3\n 2\n 2\n 2\n \n\n![](https://atcoder.jp/img/agc015/7aa4a2252f50a19fc18e0cec01368a2a.png)\n\nIn the first query, the whole grid is specified. There are three components\nconsisting of blue squares, and thus 3 should be printed.\n\nIn the second query, the region within the red frame is specified. There are\ntwo components consisting of blue squares, and thus 2 should be printed. Note\nthat squares that belong to the same component in the original grid may belong\nto different components.\n\n* * *"}, {"input": "5 5 6\n 11010\n 01110\n 10101\n 11101\n 01010\n 1 1 5 5\n 1 2 4 5\n 2 3 3 4\n 3 3 3 3\n 3 1 3 5\n 1 1 3 4", "output": "3\n 2\n 1\n 1\n 3\n 2"}]
For each query, print the number of the connected components consisting of blue squares in the region. * * *
s137231568
Runtime Error
p03707
The input is given from Standard Input in the following format: N M Q S_{1,1}..S_{1,M} : S_{N,1}..S_{N,M} x_{1,1} y_{i,1} x_{i,2} y_{i,2} : x_{Q,1} y_{Q,1} x_{Q,2} y_{Q,2}
N, M, Q = map(int, input().split()) dirs = [(1, 0), (-1, 0), (0, 1), (0, -1)] def step(x, y, id, ids, xmin, xmax, ymin, ymax): ids[y - ymin][x - xmin] = id for d in dirs: next_x = x + d[0] next_y = y + d[1] if next_x < xmin or next_x > xmax: continue if next_y < ymin or next_y > ymax: continue if grid[next_y][next_x] == 0: continue if ids[next_y - ymin][next_x - xmin] != 0: continue step(next_x, next_y, id, ids, xmin, xmax, ymin, ymax) grid = [] for i in range(N): row = [] s = input() for c in s: row.append(int(c)) grid.append(row) for _ in range(Q): cids = [] x1, y1, x2, y2 = map(int, input().split()) ids = [[0 for _ in range(y2 - y1 + 1)] for _ in range(x2 - x1 + 1)] sid = 1 for ix in range(0, x2 - x1 + 1): for iy in range(0, y2 - y1 + 1): x = x1 + ix - 1 y = y1 + iy - 1 if ids[ix][iy] == 0 and grid[x][y] == 1: step(y, x, sid, ids, y1 - 1, y2 - 1, x1 - 1, x2 - 1) sid += 1 print(sid - 1)
Statement Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white. For every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once. Phantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region? Process all the queries.
[{"input": "3 4 4\n 1101\n 0110\n 1101\n 1 1 3 4\n 1 1 3 1\n 2 2 3 4\n 1 2 2 4", "output": "3\n 2\n 2\n 2\n \n\n![](https://atcoder.jp/img/agc015/7aa4a2252f50a19fc18e0cec01368a2a.png)\n\nIn the first query, the whole grid is specified. There are three components\nconsisting of blue squares, and thus 3 should be printed.\n\nIn the second query, the region within the red frame is specified. There are\ntwo components consisting of blue squares, and thus 2 should be printed. Note\nthat squares that belong to the same component in the original grid may belong\nto different components.\n\n* * *"}, {"input": "5 5 6\n 11010\n 01110\n 10101\n 11101\n 01010\n 1 1 5 5\n 1 2 4 5\n 2 3 3 4\n 3 3 3 3\n 3 1 3 5\n 1 1 3 4", "output": "3\n 2\n 1\n 1\n 3\n 2"}]
Print the sum of f(S, T), modulo (10^9+7). * * *
s827856024
Accepted
p02815
Input is given from Standard Input in the following format: N C_1 C_2 \cdots C_N
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 def fermat(x, y, MOD): return x * pow(y, MOD - 2, MOD) % MOD N = INT() A = LIST() # 大きい数ほど少なく使うのが最適なので降順ソートしておく A.sort(reverse=1) # 各要素が変更のために何回使われるか数える cnts = [0] * N cnts[0] = pow(4, N - 1, MOD) add = fermat(cnts[0], 2, MOD) for i in range(1, N): cnts[i] = cnts[i - 1] + add cnts[i] %= MOD ans = 0 for i in range(N): ans += A[i] * cnts[i] ans %= MOD print(ans * 2 % MOD)
Statement For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows: * Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations. * Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \times C_i, where D is the number of integers j such that S_j \neq T_j (1 \leq j \leq N) just before this change. There are 2^N \times (2^N - 1) pairs (S, T) of different sequences of length N consisting of 0 and 1. Compute the sum of f(S, T) over all of those pairs, modulo (10^9+7).
[{"input": "1\n 1000000000", "output": "999999993\n \n\nThere are two pairs (S, T) of different sequences of length 2 consisting of 0\nand 1, as follows:\n\n * S = (0), T = (1): by changing S_1 to 1, we can have S = T at the cost of 1000000000, so f(S, T) = 1000000000.\n * S = (1), T = (0): by changing S_1 to 0, we can have S = T at the cost of 1000000000, so f(S, T) = 1000000000.\n\nThe sum of these is 2000000000, and we should print it modulo (10^9+7), that\nis, 999999993.\n\n* * *"}, {"input": "2\n 5 8", "output": "124\n \n\nThere are 12 pairs (S, T) of different sequences of length 3 consisting of 0\nand 1, which include:\n\n * S = (0, 1), T = (1, 0)\n\nIn this case, if we first change S_1 to 1 then change S_2 to 0, the total cost\nis 5 \\times 2 + 8 = 18. We cannot have S = T at a smaller cost, so f(S, T) =\n18.\n\n* * *"}, {"input": "5\n 52 67 72 25 79", "output": "269312"}]
Print the sum of f(S, T), modulo (10^9+7). * * *
s685545015
Wrong Answer
p02815
Input is given from Standard Input in the following format: N C_1 C_2 \cdots C_N
# import math # import fractions # import numpy as np # MOD = 10 ** 9 + 7 # ゼロ埋め # list = [0] * N # 二次元配列 # [[inf, inf, inf], [inf, inf, inf]] # dp = [[float('inf')] * (H + 1) for i in range(N + 1)] def solve(N, A): A.sort() two = [0] * (N + 1) for i in range(N + 1): two[i] = 2**i ans = 0 for i in range(N): l = i r = N - i - 1 now = two[r] if r != 0: now += two[r - 1] * r now *= two[l] now *= A[i] ans += now ans *= two[N] return ans return 0 # S = input() N = int(input()) # H, N = map(int, input().split()) A = list(map(int, input().split())) # B = [int(input()) for _ in range(n)] # A = [] # B = [] # for _ in range(N): # a, b = list(map(int, input().split())) # A.append(a) # B.append(b) print(solve(N, A))
Statement For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows: * Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations. * Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \times C_i, where D is the number of integers j such that S_j \neq T_j (1 \leq j \leq N) just before this change. There are 2^N \times (2^N - 1) pairs (S, T) of different sequences of length N consisting of 0 and 1. Compute the sum of f(S, T) over all of those pairs, modulo (10^9+7).
[{"input": "1\n 1000000000", "output": "999999993\n \n\nThere are two pairs (S, T) of different sequences of length 2 consisting of 0\nand 1, as follows:\n\n * S = (0), T = (1): by changing S_1 to 1, we can have S = T at the cost of 1000000000, so f(S, T) = 1000000000.\n * S = (1), T = (0): by changing S_1 to 0, we can have S = T at the cost of 1000000000, so f(S, T) = 1000000000.\n\nThe sum of these is 2000000000, and we should print it modulo (10^9+7), that\nis, 999999993.\n\n* * *"}, {"input": "2\n 5 8", "output": "124\n \n\nThere are 12 pairs (S, T) of different sequences of length 3 consisting of 0\nand 1, which include:\n\n * S = (0, 1), T = (1, 0)\n\nIn this case, if we first change S_1 to 1 then change S_2 to 0, the total cost\nis 5 \\times 2 + 8 = 18. We cannot have S = T at a smaller cost, so f(S, T) =\n18.\n\n* * *"}, {"input": "5\n 52 67 72 25 79", "output": "269312"}]
Print the minimum number of operations required to achieve the objective. * * *
s216104227
Accepted
p03357
Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N}
from bisect import bisect_right, bisect_left # instead of AVLTree class BITbisect: def __init__(self, InputProbNumbers): # 座圧 self.ind_to_co = [-(10**18)] self.co_to_ind = {} for ind, num in enumerate(sorted(list(set(InputProbNumbers)))): self.ind_to_co.append(num) self.co_to_ind[num] = ind + 1 self.max = len(self.co_to_ind) self.data = [0] * (self.max + 1) def __str__(self): retList = [] for i in range(1, self.max + 1): x = self.ind_to_co[i] if self.count(x): c = self.count(x) for _ in range(c): retList.append(x) return "[" + ", ".join([str(a) for a in retList]) + "]" def __getitem__(self, key): key += 1 s = 0 ind = 0 l = self.max.bit_length() for i in reversed(range(l)): if ind + (1 << i) <= self.max: if s + self.data[ind + (1 << i)] < key: s += self.data[ind + (1 << i)] ind += 1 << i if ind == self.max or key < 0: raise IndexError("BIT index out of range") return self.ind_to_co[ind + 1] def __len__(self): return self._query_sum(self.max) def __contains__(self, num): if not num in self.co_to_ind: return False return self.count(num) > 0 # 0からiまでの区間和 # 左に進んでいく def _query_sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s # i番目の要素にxを足す # 上に登っていく def _add(self, i, x): while i <= self.max: self.data[i] += x i += i & -i # 値xを挿入 def push(self, x): if not x in self.co_to_ind: raise KeyError("The pushing number didnt initialized") self._add(self.co_to_ind[x], 1) # 値xを削除 def delete(self, x): if not x in self.co_to_ind: raise KeyError("The deleting number didnt initialized") if self.count(x) <= 0: raise ValueError("The deleting number doesnt exist") self._add(self.co_to_ind[x], -1) # 要素xの個数 def count(self, x): return self._query_sum(self.co_to_ind[x]) - self._query_sum( self.co_to_ind[x] - 1 ) # 値xを超える最低ind def bisect_right(self, x): if x in self.co_to_ind: i = self.co_to_ind[x] else: i = bisect_right(self.ind_to_co, x) - 1 return self._query_sum(i) # 値xを下回る最低ind def bisect_left(self, x): if x in self.co_to_ind: i = self.co_to_ind[x] else: i = bisect_left(self.ind_to_co, x) if i == 1: return 0 return self._query_sum(i - 1) import sys input = sys.stdin.readline INF = 10**14 N = int(input()) white = [None] * N blue = [None] * N for i in range(2 * N): c, n = map(str, input().rstrip().split()) if c == "W": white[int(n) - 1] = i else: blue[int(n) - 1] = i dp1 = [[0] * (N + 1) for _ in range(N + 1)] Indb = BITbisect(list(range(2 * N + 1))) for j in reversed(range(N)): dp1[N][j] = Indb.bisect_left(blue[j]) Indb.push(blue[j]) for i in reversed(range(N)): if white[i] < blue[j]: dp1[i][j] = dp1[i + 1][j] + 1 else: dp1[i][j] = dp1[i + 1][j] dp2 = [[0] * (N + 1) for _ in range(N + 1)] Indw = BITbisect(list(range(2 * N + 1))) for j in reversed(range(N)): dp2[j][N] = Indw.bisect_left(white[j]) Indw.push(white[j]) for i in reversed(range(N)): if blue[i] < white[j]: dp2[j][i] = dp2[j][i + 1] + 1 else: dp2[j][i] = dp2[j][i + 1] dp = [[INF] * (N + 1) for _ in range(N + 1)] dp[N][N] = 0 for i in reversed(range(N + 1)): for j in reversed(range(N + 1)): if i == N: if j != N: dp[i][j] = dp[i][j + 1] + dp1[i][j] elif j == N: dp[i][j] = dp[i + 1][j] + dp2[i][j] else: dp[i][j] = min(dp[i][j + 1] + dp1[i][j], dp[i + 1][j] + dp2[i][j]) print(dp[0][0])
Statement There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective.
[{"input": "3\n B 1\n W 2\n B 3\n W 1\n W 3\n B 2", "output": "4\n \n\nThe objective can be achieved in four operations, for example, as follows:\n\n * Swap the black 3 and white 1.\n * Swap the white 1 and white 2.\n * Swap the black 3 and white 3.\n * Swap the black 3 and black 2.\n\n* * *"}, {"input": "4\n B 4\n W 4\n B 3\n W 3\n B 2\n W 2\n B 1\n W 1", "output": "18\n \n\n* * *"}, {"input": "9\n W 3\n B 1\n B 4\n W 1\n B 5\n W 9\n W 2\n B 6\n W 5\n B 3\n W 8\n B 9\n W 7\n B 2\n B 8\n W 4\n W 6\n B 7", "output": "41"}]
Print the minimum number of operations required to achieve the objective. * * *
s721545990
Runtime Error
p03357
Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N}
N = int(input()) balls = [] for i in range(2 * N): c, a = input().split() balls += [(c, int(a))] # numB[i][b]: 初期状態において、i番目の玉より右にある、1~bが書かれた黒玉の数 numB = [[0] * (N + 1) for i in range(2 * N)] numW = [[0] * (N + 1) for i in range(2 * N)] for i in reversed(range(1, 2 * N)): c, a = balls[i] numB[i - 1] = numB[i].copy() numW[i - 1] = numW[i].copy() if c == "B": for b in range(a, N + 1): numB[i - 1][b] += 1 else: for w in range(a, N + 1): numW[i - 1][w] += 1 # costB[b][w]: 黒玉1~b、白玉1~wのうち、初期状態において、黒玉[b+1]より右にある玉の数 costB = [[0] * (N + 1) for i in range(N + 1)] costW = [[0] * (N + 1) for i in range(N + 1)] for i in reversed(range(2 * N)): c, a = balls[i] if c == "B": cost = numB[i][a - 1] for w in range(N + 1): costB[a - 1][w] = cost + numW[i][w] else: cost = numW[i][a - 1] for b in range(N + 1): costW[b][a - 1] = cost + numB[i][b] dp = [[float("inf")] * (N + 1) for i in range(N + 1)] dp[0][0] = 0 for b in range(N + 1): for w in range(N + 1): if b > 0: dp[b][w] = min(dp[b][w], dp[b - 1][w] + costB[b - 1][w]) if w > 0: dp[b][w] = min(dp[b][w], dp[b][w - 1] + costW[b][w - 1]) print(dp[N][N])
Statement There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective.
[{"input": "3\n B 1\n W 2\n B 3\n W 1\n W 3\n B 2", "output": "4\n \n\nThe objective can be achieved in four operations, for example, as follows:\n\n * Swap the black 3 and white 1.\n * Swap the white 1 and white 2.\n * Swap the black 3 and white 3.\n * Swap the black 3 and black 2.\n\n* * *"}, {"input": "4\n B 4\n W 4\n B 3\n W 3\n B 2\n W 2\n B 1\n W 1", "output": "18\n \n\n* * *"}, {"input": "9\n W 3\n B 1\n B 4\n W 1\n B 5\n W 9\n W 2\n B 6\n W 5\n B 3\n W 8\n B 9\n W 7\n B 2\n B 8\n W 4\n W 6\n B 7", "output": "41"}]
Print the minimum number of operations required to achieve the objective. * * *
s276545794
Wrong Answer
p03357
Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N}
# -*- coding: utf-8 -*- def inpl(): return map(int, input().split()) N = int(input()) balls = [input().replace(" ", "") for _ in range(2 * N)] + ["END"] B = ["END"] + ["B{}".format(i) for i in range(1, N + 1)[::-1]] W = ["END"] + ["W{}".format(i) for i in range(1, N + 1)[::-1]] ans = 0 for i in range(2 * N - 1): b = balls.index(B[-1]) w = balls.index(W[-1]) if b < w: if b != i: ans += b - i del balls[b] balls.insert(i, B[-1]) B.pop() else: if w != i: ans += w - i del balls[w] balls.insert(i, W[-1]) W.pop() print(ans)
Statement There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective.
[{"input": "3\n B 1\n W 2\n B 3\n W 1\n W 3\n B 2", "output": "4\n \n\nThe objective can be achieved in four operations, for example, as follows:\n\n * Swap the black 3 and white 1.\n * Swap the white 1 and white 2.\n * Swap the black 3 and white 3.\n * Swap the black 3 and black 2.\n\n* * *"}, {"input": "4\n B 4\n W 4\n B 3\n W 3\n B 2\n W 2\n B 1\n W 1", "output": "18\n \n\n* * *"}, {"input": "9\n W 3\n B 1\n B 4\n W 1\n B 5\n W 9\n W 2\n B 6\n W 5\n B 3\n W 8\n B 9\n W 7\n B 2\n B 8\n W 4\n W 6\n B 7", "output": "41"}]
Print the minimum number of operations required to achieve the objective. * * *
s779253861
Accepted
p03357
Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N}
import sys input = sys.stdin.readline n = int(input()) INF = 10**9 info = [list(input().split()) for i in range(2 * n)] ind = {} for i in range(2 * n): if info[i][0] == "B": info[i] = (0, int(info[i][1])) else: info[i] = (1, int(info[i][1])) ind[info[i][0] * 10**5 + info[i][1]] = i ru_b = [[0] * (2 * n + 1) for i in range(n + 1)] ru_w = [[0] * (2 * n + 1) for i in range(n + 1)] for i in range(n + 1): for j in range(2 * n): col, num = info[j] if col == 0 and num > i: ru_b[i][j + 1] += 1 elif col == 1 and num > i: ru_w[i][j + 1] += 1 for j in range(2 * n): ru_b[i][j + 1] += ru_b[i][j] ru_w[i][j + 1] += ru_w[i][j] dp = [[INF] * (n + 1) for i in range(n + 1)] dp[0][0] = 0 for i in range(n + 1): for j in range(n + 1): if i + 1 <= n and j <= n: bi = ind[i + 1] dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + ru_b[i][bi] + ru_w[j][bi]) if i <= n and j + 1 <= n: wi = ind[10**5 + j + 1] dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + ru_w[j][wi] + ru_b[i][wi]) print(dp[-1][-1])
Statement There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective.
[{"input": "3\n B 1\n W 2\n B 3\n W 1\n W 3\n B 2", "output": "4\n \n\nThe objective can be achieved in four operations, for example, as follows:\n\n * Swap the black 3 and white 1.\n * Swap the white 1 and white 2.\n * Swap the black 3 and white 3.\n * Swap the black 3 and black 2.\n\n* * *"}, {"input": "4\n B 4\n W 4\n B 3\n W 3\n B 2\n W 2\n B 1\n W 1", "output": "18\n \n\n* * *"}, {"input": "9\n W 3\n B 1\n B 4\n W 1\n B 5\n W 9\n W 2\n B 6\n W 5\n B 3\n W 8\n B 9\n W 7\n B 2\n B 8\n W 4\n W 6\n B 7", "output": "41"}]
Print the minimum number of operations required to achieve the objective. * * *
s579782333
Accepted
p03357
Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N}
import sys input = sys.stdin.readline import itertools N = int(input()) # 各index i と n に対して、左側にn以下のblack/whiteがいくつあるかを数える # とりあえず1を入れて、あとでcumsum B_pos = [0] * (N + 1) W_pos = [0] * (N + 1) B_cnt = [[0] * (N + 1) for _ in range(2 * N)] W_cnt = [[0] * (N + 1) for _ in range(2 * N)] for i in range(2 * N): c, a = input().split() a = int(a) # 0-index化 if c == "B": B_pos[a] = i else: W_pos[a] = i for i in range(1, N + 1): B_cnt[B_pos[i]][i] += 1 W_cnt[W_pos[i]][i] += 1 # cumsum for i in range(1, 2 * N): for j in range(N + 1): B_cnt[i][j] += B_cnt[i - 1][j] W_cnt[i][j] += W_cnt[i - 1][j] for i in range(2 * N): for j in range(1, N + 1): B_cnt[i][j] += B_cnt[i][j - 1] W_cnt[i][j] += W_cnt[i][j - 1] B_cnt W_cnt # Bi,Wj まで並べるためのコスト dp = [[0] * (N + 1) for _ in range(N + 1)] INF = 1 << 50 for b in range(N + 1): rng_w = range(N + 1) if b else range(1, N + 1) for w in rng_w: p = B_pos[b] q = W_pos[w] x1, x2 = INF, INF if b >= 1: x1 = dp[b - 1][w] + (p - B_cnt[p][b - 1] - W_cnt[p][w]) if w >= 1: x2 = dp[b][w - 1] + (q - W_cnt[q][w - 1] - B_cnt[q][b]) dp[b][w] = x1 if x1 < x2 else x2 answer = dp[N][N] print(answer)
Statement There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective.
[{"input": "3\n B 1\n W 2\n B 3\n W 1\n W 3\n B 2", "output": "4\n \n\nThe objective can be achieved in four operations, for example, as follows:\n\n * Swap the black 3 and white 1.\n * Swap the white 1 and white 2.\n * Swap the black 3 and white 3.\n * Swap the black 3 and black 2.\n\n* * *"}, {"input": "4\n B 4\n W 4\n B 3\n W 3\n B 2\n W 2\n B 1\n W 1", "output": "18\n \n\n* * *"}, {"input": "9\n W 3\n B 1\n B 4\n W 1\n B 5\n W 9\n W 2\n B 6\n W 5\n B 3\n W 8\n B 9\n W 7\n B 2\n B 8\n W 4\n W 6\n B 7", "output": "41"}]
Print the minimum number of operations required to achieve the objective. * * *
s299031723
Accepted
p03357
Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N}
def examC(): ans = 0 print(ans) return def examD(): ans = 0 print(ans) return # 解説AC def examE(): N = I() Bnum = [-1] * N Wnum = [-1] * N B = {} W = {} for i in range(2 * N): c, a = LSI() a = int(a) - 1 if c == "W": W[i] = a + 1 Wnum[a] = i else: B[i] = a + 1 Bnum[a] = i SB = [[0] * (N * 2) for _ in range(N + 1)] SW = [[0] * (N * 2) for _ in range(N + 1)] for i in range(2 * N): if not i in B: continue cur = B[i] cnt = 0 SB[cur][i] = 0 for j in range(2 * N): if not j in B: SB[cur][j] = cnt continue if B[j] <= cur: cnt += 1 SB[cur][j] = cnt for i in range(2 * N): if not i in W: continue cur = W[i] cnt = 0 SW[cur][i] = 0 for j in range(2 * N): if not j in W: SW[cur][j] = cnt continue if W[j] <= cur: cnt += 1 SW[cur][j] = cnt # for b in SB: # print(b) # print(SW) # print(SW,len(SW)) dp = [[inf] * (N + 1) for _ in range(N + 1)] dp[0][0] = 0 for i in range(N): dp[0][i + 1] = dp[0][i] + Bnum[i] - SB[i][Bnum[i]] dp[i + 1][0] = dp[i][0] + Wnum[i] - SW[i][Wnum[i]] # print(dp) for i in range(N): w = Wnum[i] for j in range(N): b = Bnum[j] costb = b - (SB[j][b] + SW[i + 1][b]) costw = w - (SB[j + 1][w] + SW[i][w]) # if i==2 and j==4: # print(w,SB[i][w],SW[j+1][w]) # print(b,SB[i][b],SW[j+1][b]) # print(costb,costw,i,j) # input() if costb < 0: costb = 0 # print(i,j) if costw < 0: costw = 0 # print(i,j) dp[i + 1][j + 1] = min( dp[i + 1][j + 1], dp[i + 1][j] + costb, dp[i][j + 1] + costw ) ans = dp[-1][-1] # for v in dp: # print(v) print(ans) return def examF(): ans = 0 print(ans) return from decimal import getcontext, Decimal as dec import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(input()) def LI(): return list(map(int, sys.stdin.readline().split())) def DI(): return dec(input()) def LDI(): return list(map(dec, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = dec("0.000000000001") alphabet = [chr(ord("a") + i) for i in range(26)] alphabet_convert = {chr(ord("a") + i): i for i in range(26)} getcontext().prec = 28 sys.setrecursionlimit(10**7) if __name__ == "__main__": examE() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
Statement There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective.
[{"input": "3\n B 1\n W 2\n B 3\n W 1\n W 3\n B 2", "output": "4\n \n\nThe objective can be achieved in four operations, for example, as follows:\n\n * Swap the black 3 and white 1.\n * Swap the white 1 and white 2.\n * Swap the black 3 and white 3.\n * Swap the black 3 and black 2.\n\n* * *"}, {"input": "4\n B 4\n W 4\n B 3\n W 3\n B 2\n W 2\n B 1\n W 1", "output": "18\n \n\n* * *"}, {"input": "9\n W 3\n B 1\n B 4\n W 1\n B 5\n W 9\n W 2\n B 6\n W 5\n B 3\n W 8\n B 9\n W 7\n B 2\n B 8\n W 4\n W 6\n B 7", "output": "41"}]
Print the minimum number of operations required to achieve the objective. * * *
s776939343
Wrong Answer
p03357
Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N}
import copy N = int(input()) c = [] for i in range(2 * N): a, b = input().split() c.append((a, int(b))) mo = copy.deepcopy(c) ans = 0 for i in range(2, N + 1): d = c.index(("B", i)) e = c.index(("B", i - 1)) if e - d >= 0: ans += e - d c.pop(e) c.insert(d, ("B", i - 1)) for i in range(2, N + 1): d = c.index(("W", i)) e = c.index(("W", i - 1)) if e - d >= 0: ans += e - d c.pop(e) c.insert(d, ("W", i - 1)) gyaku = 0 for i in range(2, N + 1): d = mo.index(("W", i)) e = mo.index(("W", i - 1)) if e - d >= 0: gyaku += e - d mo.pop(e) mo.insert(d, ("W", i - 1)) for i in range(2, N + 1): d = mo.index(("B", i)) e = mo.index(("B", i - 1)) if e - d >= 0: gyaku += e - d mo.pop(e) mo.insert(d, ("B", i - 1)) print(min(ans, gyaku))
Statement There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective.
[{"input": "3\n B 1\n W 2\n B 3\n W 1\n W 3\n B 2", "output": "4\n \n\nThe objective can be achieved in four operations, for example, as follows:\n\n * Swap the black 3 and white 1.\n * Swap the white 1 and white 2.\n * Swap the black 3 and white 3.\n * Swap the black 3 and black 2.\n\n* * *"}, {"input": "4\n B 4\n W 4\n B 3\n W 3\n B 2\n W 2\n B 1\n W 1", "output": "18\n \n\n* * *"}, {"input": "9\n W 3\n B 1\n B 4\n W 1\n B 5\n W 9\n W 2\n B 6\n W 5\n B 3\n W 8\n B 9\n W 7\n B 2\n B 8\n W 4\n W 6\n B 7", "output": "41"}]
Print the minimum number of operations required to achieve the objective. * * *
s833613822
Wrong Answer
p03357
Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N}
N = int(input()) ca = [ [0 if c == "B" else 1 if c == "W" else (int(c) - 1) for c in input().split()] for _ in range(N * 2) ] Bi = [N * 10] * (N + 1) Wi = [N * 10] * (N + 1) BWi = [[N * 10] * (N + 1) for _ in [0] * 2] for i, row in enumerate(ca): c, a = row BWi[c][a] = i ans = 0 BWc = [0, 0] while BWc[0] < N and BWc[1] < N: tmp1b = min(BWi[0][BWc[0] + 1 :] + [N * 10]) tmp1w = min(BWi[1][BWc[1] + 1 :] + [N * 10]) tc = int(tmp1b > tmp1w) tmp1 = min(tmp1b, tmp1w) tmp2 = BWi[tc].index(tmp1) tmp3 = BWi[tc][BWc[tc] : tmp2] tmp0 = min(tmp3) if tmp3 else 0 if tmp0 > tmp1: ans += tmp0 - tmp1 ca[tmp1 : tmp0 + 1] = [ca[tmp0]] + ca[tmp1:tmp0] BWc[tc] -= int(ca[tmp0][1] != BWc[tc]) for j, row in enumerate(ca[tmp1 : tmp0 + 1], tmp1): c, a = row BWi[c][a] = j BWc[tc] += 1 print(ans)
Statement There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective.
[{"input": "3\n B 1\n W 2\n B 3\n W 1\n W 3\n B 2", "output": "4\n \n\nThe objective can be achieved in four operations, for example, as follows:\n\n * Swap the black 3 and white 1.\n * Swap the white 1 and white 2.\n * Swap the black 3 and white 3.\n * Swap the black 3 and black 2.\n\n* * *"}, {"input": "4\n B 4\n W 4\n B 3\n W 3\n B 2\n W 2\n B 1\n W 1", "output": "18\n \n\n* * *"}, {"input": "9\n W 3\n B 1\n B 4\n W 1\n B 5\n W 9\n W 2\n B 6\n W 5\n B 3\n W 8\n B 9\n W 7\n B 2\n B 8\n W 4\n W 6\n B 7", "output": "41"}]
Print the minimum number of operations required to achieve the objective. * * *
s391388346
Wrong Answer
p03357
Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N}
import sys input = sys.stdin.readline N = int(input()) black = [None] * (N + 1) # 数字 -> 場所 white = [None] * (N + 1) for i in range(1, 2 * N + 1): c, a = input().split() a = int(a) if c == "W": white[a] = i else: black[a] = i after = [] b = 1 w = 1 while True: if b <= N and w <= N: ib = black[b] iw = white[w] if ib < iw: after.append(ib) b += 1 else: after.append(iw) w += 1 elif b <= N: after.append(black[b]) b += 1 elif w <= N: after.append(white[w]) w += 1 else: break # あとは転倒数を数えて終わり def BIT_update(tree, x): L = len(tree) while x < L: tree[x] += 1 x += x & (-x) def BIT_sum(tree, x): L = len(tree) s = 0 while x: s += tree[x] x -= x & (-x) return s tree = [0] * (2 * N + 10) answer = 0 for i, x in enumerate(after): answer += i - BIT_sum(tree, x) BIT_update(tree, x) print(answer)
Statement There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective.
[{"input": "3\n B 1\n W 2\n B 3\n W 1\n W 3\n B 2", "output": "4\n \n\nThe objective can be achieved in four operations, for example, as follows:\n\n * Swap the black 3 and white 1.\n * Swap the white 1 and white 2.\n * Swap the black 3 and white 3.\n * Swap the black 3 and black 2.\n\n* * *"}, {"input": "4\n B 4\n W 4\n B 3\n W 3\n B 2\n W 2\n B 1\n W 1", "output": "18\n \n\n* * *"}, {"input": "9\n W 3\n B 1\n B 4\n W 1\n B 5\n W 9\n W 2\n B 6\n W 5\n B 3\n W 8\n B 9\n W 7\n B 2\n B 8\n W 4\n W 6\n B 7", "output": "41"}]
Print the minimum number of operations required to achieve the objective. * * *
s991909481
Wrong Answer
p03357
Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N}
n = int(input()) x = [] for i in range(2 * n): a, b = input().split() if a == "B": x.append(int(b)) else: x.append(int(b) + n) a = 1 b = n + 1 ans = 0 while True: black = x.index(a) white = x.index(b) if black < white: ans += black x.pop(black) a += 1 if a == n + 1: while b < 2 * n + 1: white = x.index(b) ans += white b += 1 break else: ans += white x.pop(white) b += 1 if b == 2 * n + 1: while a < n + 1: white = x.index(a) ans += white a += 1 break print(ans)
Statement There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective.
[{"input": "3\n B 1\n W 2\n B 3\n W 1\n W 3\n B 2", "output": "4\n \n\nThe objective can be achieved in four operations, for example, as follows:\n\n * Swap the black 3 and white 1.\n * Swap the white 1 and white 2.\n * Swap the black 3 and white 3.\n * Swap the black 3 and black 2.\n\n* * *"}, {"input": "4\n B 4\n W 4\n B 3\n W 3\n B 2\n W 2\n B 1\n W 1", "output": "18\n \n\n* * *"}, {"input": "9\n W 3\n B 1\n B 4\n W 1\n B 5\n W 9\n W 2\n B 6\n W 5\n B 3\n W 8\n B 9\n W 7\n B 2\n B 8\n W 4\n W 6\n B 7", "output": "41"}]
Print the minimum number of operations required to achieve the objective. * * *
s502589309
Runtime Error
p03642
Input is given from Standard Input in the following format: N x_1 x_2 ... x_N
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1000100; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; int N; int arr[MAXN]; struct Dinic { struct Edge { int to, rev; ll c, f; }; vi lvl, ptr, q; vector<vector<Edge>> adj; Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {} void addEdge(int a, int b, ll c, int rcap = 0) { adj[a].push_back({b, sz(adj[b]), c, 0}); adj[b].push_back({a, sz(adj[a]) - 1, rcap, 0}); } ll dfs(int v, int t, ll f) { if (v == t || !f) return f; for (int& i = ptr[v]; i < sz(adj[v]); i++) { Edge& e = adj[v][i]; if (lvl[e.to] == lvl[v] + 1) if (ll p = dfs(e.to, t, min(f, e.c - e.f))) { e.f += p, adj[e.to][e.rev].f -= p; return p; } } return 0; } ll calc(int s, int t) { ll flow = 0; q[0] = s; rep(L,0,31) do { // 'int L=30' maybe faster for random data lvl = ptr = vi(sz(q)); int qi = 0, qe = lvl[s] = 1; while (qi < qe && !lvl[t]) { int v = q[qi++]; trav(e, adj[v]) if (!lvl[e.to] && (e.c - e.f) >> (30 - L)) q[qe++] = e.to, lvl[e.to] = lvl[v] + 1; } while (ll p = dfs(s, t, LLONG_MAX)) flow += p; } while (lvl[t]); return flow; } }; bool pr (int x) { for (int i = 2; i * i <= x; i++) if (x % i == 0) return false; return true; } int main() { ios_base::sync_with_stdio(0); cin >> N; for (int i = 0; i < N; i++) cin >> arr[i]; vector <int> v; for (int i = 0; i < N; i++) { if (i == 0 || arr[i-1] + 1 < arr[i]) v.push_back(arr[i]); if (i == N - 1 || arr[i+1] - 1 > arr[i]) v.push_back(arr[i]+1); } int m = v.size(); Dinic d (m + 2); int ne = 0, no = 0; for (int i = 0; i < m; i++) { if (v[i] % 2 == 0) { d.addEdge (m, i, 1); ne++; } else { d.addEdge (i, m + 1, 1); no++; } } for (int i = 0; i < m; i++) for (int j = 0; j < m; j++) { if (v[i] % 2 == 0 && v[j] % 2 == 1) { if (pr (abs (i - j))) d.addEdge (i, j, 1); } } int r = d.calc (m, m + 1); int res = r; ne -= r; no -= r; res += 2 * (ne / 2 + no / 2); res += 3 * (ne % 2 + no % 2); cout << res << "\n"; }
Statement There are infinitely many cards, numbered 1, 2, 3, ... Initially, Cards x_1, x_2, ..., x_N are face up, and the others are face down. Snuke can perform the following operation repeatedly: * Select a prime p greater than or equal to 3. Then, select p consecutive cards and flip all of them. Snuke's objective is to have all the cards face down. Find the minimum number of operations required to achieve the objective.
[{"input": "2\n 4 5", "output": "2\n \n\nBelow is one way to achieve the objective in two operations:\n\n * Select p = 5 and flip Cards 1, 2, 3, 4 and 5.\n * Select p = 3 and flip Cards 1, 2 and 3.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "3\n \n\nBelow is one way to achieve the objective in three operations:\n\n * Select p = 3 and flip Cards 1, 2 and 3.\n * Select p = 3 and flip Cards 4, 5 and 6.\n * Select p = 3 and flip Cards 7, 8 and 9.\n\n* * *"}, {"input": "2\n 1 10000000", "output": "4"}]