text
stringlengths
198
433k
conversation_id
int64
0
109k
Provide a correct Python 3 solution for this coding contest problem. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 "Correct Solution: ``` a,b=map(int,input().split()) c=a+b d=a-b e=a*b print(max(c,d,e)) ```
96,800
Provide a correct Python 3 solution for this coding contest problem. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 "Correct Solution: ``` import math a,b=map(int,input().split()) print(max(a+b,a-b,a*b)) ```
96,801
Provide a correct Python 3 solution for this coding contest problem. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 "Correct Solution: ``` a,b=map(int,input().split()) print(max(a-b,a+b,a*b)) ```
96,802
Provide a correct Python 3 solution for this coding contest problem. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 "Correct Solution: ``` A, B = map(int, input().split()) print(max([A+B, A-B, A*B])) ```
96,803
Provide a correct Python 3 solution for this coding contest problem. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 "Correct Solution: ``` A, B = map(int, input().rstrip().split()) print(max(A+B, A-B, A*B)) ```
96,804
Provide a correct Python 3 solution for this coding contest problem. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 "Correct Solution: ``` #Add Sub Mal A,B = map(int, input().split()) print(max(A+B,A-B,A*B)) ```
96,805
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 Submitted Solution: ``` A,B=map(int,input().split()) x=A+B y=A-B z=A*B C=max(x,y,z) print(C) ``` Yes
96,806
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 Submitted Solution: ``` A,B = map(int,input().split()) print(max((A-B),(A+B),(A*B))) ``` Yes
96,807
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 Submitted Solution: ``` A, B = list(map(int, input().split(' '))) print(max(A+B, A-B, A*B)) ``` Yes
96,808
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 Submitted Solution: ``` #ABC099 a,b = map(int,input().split()) print(max(a+b,a-b,a*b)) ``` Yes
96,809
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 Submitted Solution: ``` N = int(input()) S = list(input()) # print(N, S) ans = N for i, h in enumerate(range(N)): skipflg = False f = S[0: i] l = S[i] s = S[i+1:] print(f, l, s) nw = 0 ne = 0 nw = f.count('W') ne = s.count('E') print(nw, ne) # for r in f: # if r != 'E': # nw += 1 # if nw >= ans: # skipflg = True # break # # print('not e') # if skipflg: # break # for w in s: # if w != 'W': # ne += 1 # if nw+ne >= ans: # skipflg = True # break # # print('not w') # if skipflg: # break ans = min(ans, nw+ne) print(ans) ``` No
96,810
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 Submitted Solution: ``` a,b=map(int,input().split()) d = a+b e = a-b f= a*b if d>e and d>f: print(d) elif e>d and e>f: print(e) else: print(f) ``` No
96,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 Submitted Solution: ``` A,B = map(int,input().split()) maxNum = A + B if maxNum <= A-B: maxNum = A-B elif maxNum <= A*B: maxNum = A*B print(maxNum) ``` No
96,812
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Input 3 1 Output 4 Input 4 -2 Output 6 Input 0 0 Output 0 Submitted Solution: ``` a, b = list(map(int, input().split())) pl = a + b mi = a - b mul = a * b if pl > mi: if mul > pl: print(mul) else: print(pl) else: if mul > pl: print(mul) else: print(mi) ``` No
96,813
Provide a correct Python 3 solution for this coding contest problem. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007. Constraints * 1 \leq N < 2 \times 10^{5} * 0 \leq p_i < i Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Examples Input 2 0 0 Output 8 Input 5 0 1 1 0 4 Output 96 Input 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Output 730395550 "Correct Solution: ``` import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import deque MOD = 10 ** 9 + 7 N = int(input()) graph = [[] for _ in range(N+1)] for i,x in enumerate(input().rstrip().split(),1): x = int(x) graph[i].append(x) graph[x].append(i) # 各深さから来ている (0個、1個、2個以上) の分布を 確率 mod MODで持つ。 half = (MOD + 1) // 2 def merge(dp,dp1): L = len(dp1) for i in range(L): # 0個,1個,2個以上 a,b,c = dp[i] d,e,f = dp1[i] a,b,c = a*d, a*e + b*d, a*f + b*e + b*f + c*d + c*e + c*f a %= MOD b %= MOD c %= MOD dp[i] = (a,b,c) return def dfs(v,parent = None): dp = None L = 0 for u in graph[v]: if u == parent: continue dp1 = dfs(u,v) if dp is None: dp = dp1 else: if len(dp) < len(dp1): dp,dp1 = dp1,dp # 2個以上が入っているインデックス if L < len(dp1): L = len(dp1) merge(dp,dp1) if dp is None: dp = deque() else: # 2個以上あるときに、0個化する for i in range(L): a,b,c = dp[i] dp[i] = (a+c,b,0) dp.appendleft((half,half,0)) return dp dp = dfs(0) answer = sum(b for a,b,c in dp) answer *= pow(2,N+1,MOD) answer %= MOD print(answer) ```
96,814
Provide a correct Python 3 solution for this coding contest problem. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007. Constraints * 1 \leq N < 2 \times 10^{5} * 0 \leq p_i < i Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Examples Input 2 0 0 Output 8 Input 5 0 1 1 0 4 Output 96 Input 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Output 730395550 "Correct Solution: ``` # coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline n, = map(int, readline().split()) p = [-1] + [*map(int, readline().split())] MOD = 10**9+7 child = [[] for i in range(n+1)] tot = [None for i in range(n+1)] one = [None for i in range(n+1)] dep = [0]*(n+1) p2 = [1]*(n+1) for i in range(n): p2[i+1] = p2[i]*2%MOD for v in range(n,-1,-1): if dep[v]==0: tot[v] = [] one[v] = [] else: child[v].sort(key=lambda i: dep[i]) one[v] = one[child[v][-1]] tot[v] = tot[child[v][-1]] #one_sum = [0]*(dep[v]) #zero_sum = [0]*(dep[v]) child[v].pop() if child[v]: zero = [p2[tot[v][j]]-one[v][j] for j in range(-len(one[child[v][-1]]),0)] for c in child[v]: for j in range(-len(one[c]),0): z = p2[tot[c][j]]-one[c][j] one[v][j] = (one[v][j]*z+zero[j]*one[c][j])%MOD zero[j] = zero[j]*z%MOD tot[v][j] += tot[c][j] tot[v].append(1) one[v].append(1) child[p[v]].append(v) dep[p[v]] = max(dep[p[v]],dep[v]+1) #print(v,tot[v],one[v]) #print("tot",tot[0]) #print("one",one[0]) ans = 0 for i,j in zip(tot[0],one[0]): ans += pow(2,n+1-i,MOD)*j%MOD print(ans%MOD) #print(sum(tot[0])) ```
96,815
Provide a correct Python 3 solution for this coding contest problem. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007. Constraints * 1 \leq N < 2 \times 10^{5} * 0 \leq p_i < i Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Examples Input 2 0 0 Output 8 Input 5 0 1 1 0 4 Output 96 Input 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Output 730395550 "Correct Solution: ``` from collections import deque def get_pow(): cache = {} def func(x): if x not in cache: cache[x] = pow(2, x, mod) return cache[x] return func mod = 1000000007 n = int(input()) parents = list(map(int, input().split())) children = [set() for _ in range(n + 1)] for c, p in enumerate(parents): children[p].add(c + 1) levels = [{0}] while True: level = set() for p in levels[-1]: level.update(children[p]) if not level: break levels.append(level) levels.reverse() level_node_count = [] balls = [None] * (n + 1) for i, level in enumerate(levels): level_node_count.append(len(level)) for node in level: cn = children[node] if cn: if len(cn) == 1: bs = balls[cn.pop()] bs.appendleft([1, 1, 0]) balls[node] = bs continue balls_from_children = [balls[c] for c in children[node]] balls_from_children.sort(key=len) bs1 = balls_from_children[0] for bs2 in balls_from_children[1:]: for (b10, b11, b12), b2 in zip(bs1, bs2): b2[2] = ((b11 + b12) * b2[1] + b12 * b2[0]) % mod b2[1] = (b10 * b2[1] + b11 * b2[0]) % mod b2[0] = b2[0] * b10 % mod bs1 = bs2 lim = len(balls_from_children[-2]) for i, b in enumerate(bs1): if i >= lim: break b[0] = (b[0] + b[2]) % mod b[2] = 0 bs1.appendleft([1, 1, 0]) balls[node] = bs1 else: balls[node] = deque([[1, 1, 0]]) level_node_count.reverse() pow2 = get_pow() print(sum(b[1] * pow2(n - l + 1) % mod for l, b in zip(level_node_count, balls[0])) % mod) ```
96,816
Provide a correct Python 3 solution for this coding contest problem. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007. Constraints * 1 \leq N < 2 \times 10^{5} * 0 \leq p_i < i Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Examples Input 2 0 0 Output 8 Input 5 0 1 1 0 4 Output 96 Input 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Output 730395550 "Correct Solution: ``` # seishin.py from collections import deque N = int(input()) *P, = map(int, input().split()) MOD = 10**9 + 7 G = [[] for i in range(N+1)] U = [0]*(N+1) C = [0]*(N+1) for i, p in enumerate(P): G[p].append(i+1) U[i+1] = u = U[p]+1 C[u] += 1 Q = [None]*(N+1) PP = {} def pp(k): if k not in PP: PP[k] = p = pow(2, k, MOD) return p return PP[k] L = [0]*(N+1) ept = [] sz = L.__getitem__ for i in range(N, -1, -1): g = G[i] if not g: continue # 子ノードのdequeを集める g.sort(key=sz, reverse=1) k = len(g) e = [pp(k) - k, k, 0] g0 = g[0] L[i] = L[g0] + 1 if L[g0] == 0: Q[i] = deque([e]) continue Q[i] = R = Q[g0] if k > 1: # a0 <- a2 for s, r in zip(Q[g[1]] or ept, R): r[0] += r[2]; r[2] = 0 for j in g[1:]: S = Q[j] if not S: break # dequeの小さい方から大きい方へマージする処理 for (a0, a1, a2), r in zip(S, R): b0, b1, b2 = r; a0 += a2 r[0] = a0*b0 % MOD r[1] = (a0*b1 + a1*b0) % MOD r[2] = ((a0+a1)*b2 + a1*b1) % MOD R.appendleft(e) print((pp(N) + sum(pp(N+1-c) * a1 % MOD for (a0, a1, a2), c in zip(Q[0], C[1:]))) % MOD) ```
96,817
Provide a correct Python 3 solution for this coding contest problem. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007. Constraints * 1 \leq N < 2 \times 10^{5} * 0 \leq p_i < i Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Examples Input 2 0 0 Output 8 Input 5 0 1 1 0 4 Output 96 Input 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Output 730395550 "Correct Solution: ``` import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def main(): def dfs(u=0): def merge(dpu, dpv): vn = len(dpv) for d in range(-1, -1 - vn, -1): u0, u1, u2 = dpu[d] v0, v1, v2 = dpv[d] n0 = (u0 * v0) % md n1 = (u0 * v1 + u1 * v0) % md n2 = (u2 * (v0 + v1 + v2) + v2 * (u0 + u1) + u1 * v1) % md dpu[d] = (n0, n1, n2) # 葉の場合 if len(to[u]) == 0: return [(inv2, inv2, 0)] # すべての子をマージ dpu = [] mxlen=0 for v in to[u]: dpv = dfs(v) #深さが2段以上あったらu2をu0に if not dpu: dpu = dpv else: if len(dpu) < len(dpv): dpu, dpv = dpv, dpu mxlen=max(mxlen,len(dpv)) merge(dpu, dpv) for d in range(-1,-1-mxlen,-1): u0,u1,u2=dpu[d] dpu[d] = (u0 + u2, u1, 0) dpu.append((inv2, inv2, 0)) return dpu md = 10 ** 9 + 7 # 1/2のmod inv2 = pow(2, md - 2, md) n = int(input()) to = [[] for _ in range(n+1)] pp = list(map(int, input().split())) for i, p in enumerate(pp, 1): to[p].append(i) # print(to) dp0 = dfs() # print(dp0) ans = sum(u1 for _, u1, _ in dp0) print((ans * pow(2, n + 1, md)) % md) main() ```
96,818
Provide a correct Python 3 solution for this coding contest problem. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007. Constraints * 1 \leq N < 2 \times 10^{5} * 0 \leq p_i < i Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Examples Input 2 0 0 Output 8 Input 5 0 1 1 0 4 Output 96 Input 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Output 730395550 "Correct Solution: ``` from collections import deque def get_pow(): cache = {} def func(x): if x not in cache: cache[x] = pow(2, x, mod) return cache[x] return func mod = 1000000007 n = int(input()) parents = list(map(int, input().split())) children = [set() for _ in range(n + 1)] for c, p in enumerate(parents): children[p].add(c + 1) levels = [{0}] while True: level = set() for p in levels[-1]: level.update(children[p]) if not level: break levels.append(level) levels.reverse() level_node_count = [] balls = [None] * (n + 1) for i, level in enumerate(levels): level_node_count.append(len(level)) for node in level: cn = children[node] if cn: if len(cn) == 1: bs = balls[cn.pop()] bs.appendleft([1, 1, 0]) balls[node] = bs continue balls_from_children = [balls[c] for c in children[node]] balls_from_children.sort(key=len) bs1 = balls_from_children[0] for bs2 in balls_from_children[1:]: for (b10, b11, b12), b2 in zip(bs1, bs2): b2[2] = ((b11 + b12) * b2[1] + b12 * b2[0]) % mod b2[1] = (b10 * b2[1] + b11 * b2[0]) % mod b2[0] = b2[0] * b10 % mod bs1 = bs2 for b in bs1: b[0] = (b[0] + b[2]) % mod b[2] = 0 bs1.appendleft([1, 1, 0]) balls[node] = bs1 else: balls[node] = deque([[1, 1, 0]]) level_node_count.reverse() pow2 = get_pow() print(sum(b[1] * pow2(n - l + 1) % mod for l, b in zip(level_node_count, balls[0])) % mod) ```
96,819
Provide a correct Python 3 solution for this coding contest problem. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007. Constraints * 1 \leq N < 2 \times 10^{5} * 0 \leq p_i < i Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Examples Input 2 0 0 Output 8 Input 5 0 1 1 0 4 Output 96 Input 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Output 730395550 "Correct Solution: ``` """ https://atcoder.jp/contests/arc086/tasks/arc086_c 対消滅する可能性があるのは同じ深さの点に置かれたビー玉だけ →1つも残らない or 1つだけ残るである すなわち、ある深さに関して、そのうち1つ残るのがいくつあるかを数えればよい 1つだけ置く場合→絶対のこる 2つ置く場合→絶対消える 3つ置く場合→3つのLCAが等しくなければ残る 木dpみたいにする? dp[0] = 一つも含んでいない場合の通り数 dp[1] = 1つ含んでいる場合の通り数 dp[0] = すべての場合 - dp[1] dp[1] = 1つだけ1を持っている場合 で、子から親に伝播させていく…? マージテクで計算量削減か? 3sだからそうっぽいな… 3つ以上のマージ書くのだるすぎん? またはマージの順番をどっかにメモっておく maxd-d = indexでやる 最長のやつにマージする dp[maxd-d][1] = 1つだけ元深さdが残っている場合の数 c = 子の数 計算量は? サイズは高々1しか増えないので可能っぽい 2倍処理がまずい もっと簡潔に? 単一のdだけで考えよう 2倍処理なんてしない 最後に各dに関してかければいい →するとマージの際に2番目の大きさだけでなんとかなる 必要のないマージをしない 両方に関係ないdは操作しない むしろばらつきは深い部分にだけ存在するか 浅い部分は共通。よって-xで管理すればいいか """ import sys mod = 10**9 + 7 sys.setrecursionlimit(200000) from collections import deque def NC_Dij(lis,start): ret = [float("inf")] * len(lis) ret[start] = 0 q = deque([start]) plis = [i for i in range(len(lis))] while len(q) > 0: now = q.popleft() for nex in lis[now]: if ret[nex] > ret[now] + 1: ret[nex] = ret[now] + 1 plis[nex] = now q.append(nex) return ret,plis def inverse(a): #aのmodを法にした逆元を返す return pow(a,mod-2,mod) def dfs(v): if len(lis[v]) == 0: ret = [ [1,1] ] return ret else: retlis = [] for nex in lis[v]: nret = dfs(nex) retlis.append( [len(nret),nret] ) retlis.sort() #1つしかない場合マージしない if len(retlis) == 1: retlis[-1][1].append([1,1]) return retlis[-1][1] #2つ以上の場合最大のやつにマージする for revd in range(retlis[-2][0]): zmul = 1 amul = 1 for i in range(len(retlis)-1,-1,-1): if revd < retlis[i][0]: zmul *= retlis[i][1][-1-revd][0] amul *= sum(retlis[i][1][-1-revd]) zmul %= mod amul %= mod else: break nsum = 0 for i in range(len(retlis)-1,-1,-1): if revd < retlis[i][0]: nsum += zmul * inverse(retlis[i][1][-1-revd][0]) * retlis[i][1][-1-revd][1] nsum %= mod else: break retlis[-1][1][-1-revd][1] = nsum retlis[-1][1][-1-revd][0] = (amul-nsum) % mod retlis[-1][1].append([1,1]) return retlis[-1][1] N = int(input()) p = list(map(int,input().split())) lis = [ [] for i in range(N+1) ] for i in range(N): #lis[i+1].append(p[i]) lis[p[i]].append(i+1) dlis,plis = NC_Dij(lis,0) maxd = max(dlis) dn = [0] * (maxd+1) for i in dlis: dn[i] += 1 ans = dfs(0) #print (dn,ans) A = 0 for i in range(maxd+1): A += ans[-1-i][1] * pow(2,N+1-dn[i],mod) A %= mod print (A) ```
96,820
Provide a correct Python 3 solution for this coding contest problem. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007. Constraints * 1 \leq N < 2 \times 10^{5} * 0 \leq p_i < i Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Examples Input 2 0 0 Output 8 Input 5 0 1 1 0 4 Output 96 Input 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Output 730395550 "Correct Solution: ``` n, = map(int, input().split()) p = [-1] + [*map(int, input().split())] MOD = 10**9+7 dp = [[] for _ in range(n+1)] dep = [0]*(n+1) nxt = [0]*(n+1) for v in range(n,0,-1): _,nxt[p[v]],dep[p[v]] = sorted([nxt[p[v]],dep[p[v]],dep[v]+1]) tot = [0]*(dep[0]+1) for i in range(n+1): tot[dep[i]] += 1 def merge(p,v): if len(dp[p]) < len(dp[v]): dp[p],dp[v]=dp[v],dp[p] for i in range(-len(dp[v]),0): a,b,c = dp[p][i] d,e,f = dp[v][i] dp[p][i][:] = [a*d%MOD,(b*d+a*e)%MOD,c*f%MOD] for v in range(n,-1,-1): dp[v].append([1,1,2]) for i in range(-nxt[v]-1,0): dp[v][i][0] = dp[v][i][2] - dp[v][i][1] if v: merge(p[v],v) ans = 0 for d in dp[0]: ans += pow(d[2],MOD-2,MOD)*d[1]%MOD print(ans*pow(2,n+1,MOD)%MOD) ```
96,821
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007. Constraints * 1 \leq N < 2 \times 10^{5} * 0 \leq p_i < i Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Examples Input 2 0 0 Output 8 Input 5 0 1 1 0 4 Output 96 Input 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Output 730395550 Submitted Solution: ``` # seishin.py N = int(input()) *P, = map(int, input().split()) MOD = 10**9 + 7 G = [[] for i in range(N+1)] for i, p in enumerate(P): G[p].append(i+1) Q = [None]*(N+1) for i in range(N, -1, -1): # 子ノードのqueを集める R = None for j in G[i]: S = Q[j] if not R: R = S continue # |R| > |S| if len(R) < len(S): R, S = S, R # queの小さい方から大きい方へマージする処理 for s, r in zip(S, R): a0, a1, a2, c0 = s b0, b1, b2, c1 = r r[:] = a0*b0 % MOD, (a0*b1 + a1*b0) % MOD, (a2*(b0 + b1 + b2) + (a0 + a1)*b2 + a1*b1) % MOD, c0+c1 if R: # a0 <- a2 for e in R: e[0] += e[2] e[2] = 0 Q[i] = [[1, 1, 0, 1]] + R else: Q[i] = [[1, 1, 0, 1]] ans = 0 for a0, a1, a2, c in Q[0]: ans += pow(2, N+1-c, MOD) * a1 % MOD print(ans % MOD) ``` No
96,822
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007. Constraints * 1 \leq N < 2 \times 10^{5} * 0 \leq p_i < i Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Examples Input 2 0 0 Output 8 Input 5 0 1 1 0 4 Output 96 Input 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Output 730395550 Submitted Solution: ``` # seishin.py import sys sys.setrecursionlimit(10**6) N = int(input()) *P, = map(int, input().split()) MOD = 10**9 + 7 from itertools import tee G = [[] for i in range(N+1)] for i, p in enumerate(P): G[p].append(i+1) Q = [None]*(N+1) E = [1, 1, 0, 1] for i in range(N, -1, -1): def gen(i): *I, = map(Q.__getitem__, G[i]) r = E while r: a,b,c,d=r yield (a+c,b,0,d) r = None for it in I: s = next(it, None) if s: if r: a0, a1, a2, c0 = s b0, b1, b2, c1 = r r = a0*b0 % MOD, (a0*b1 + a1*b0) % MOD, ((a0 + a1)*b2 + a1*b1) % MOD, c0+c1 else: r = s Q[i] = gen(i) ans = 0 for a0, a1, a2, c in Q[0]: ans += pow(2, N+1-c, MOD) * a1 % MOD print(ans % MOD) ``` No
96,823
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007. Constraints * 1 \leq N < 2 \times 10^{5} * 0 \leq p_i < i Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Examples Input 2 0 0 Output 8 Input 5 0 1 1 0 4 Output 96 Input 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Output 730395550 Submitted Solution: ``` # seishin.py from collections import deque N = int(input()) *P, = map(int, input().split()) MOD = 10**9 + 7 G = [[] for i in range(N+1)] for i, p in enumerate(P): G[p].append(i+1) Q = [None]*(N+1) for i in range(N, -1, -1): # i+1 <- P[i] Q[i] = q = deque([[1, 1, 0, 1]]) # 子ノードのdequeを集める R = [] for j in G[i]: S = Q[j] if not R: R = S continue # |R| > |S| if len(R) < len(S): R, S = S, R # dequeの小さい方から大きい方へマージする処理 for k in range(len(S)): a0, a1, a2, c0 = S.popleft() b0, b1, b2, c1 = R[k] R[k] = [a0*b0 % MOD, (a0*b1 + a1*b0) % MOD, (a0*b2 + a1*b1 + a2*b0 + a1*b2 + a2*b2 + a2*b1) % MOD, c0+c1] # a0 <- a2 for e in R: e[0] += e[2] e[2] = 0 q.extend(R) ans = 0 for a0, a1, a2, c in Q[0]: ans += pow(2, N+1-c, MOD) * a1 % MOD print(ans % MOD) ``` No
96,824
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play, and compute the sum of all those numbers modulo 1,000,000,007. Constraints * 1 \leq N < 2 \times 10^{5} * 0 \leq p_i < i Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Examples Input 2 0 0 Output 8 Input 5 0 1 1 0 4 Output 96 Input 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Output 730395550 Submitted Solution: ``` #!/usr/bin/env python3 import sys sys.setrecursionlimit(202020) def powmod(a, x, m): y = 1 while 0 < x: if x % 2 == 1: y *= a y %= m x //= 2 a = a ** 2 a %= m return y M = 10 ** 9 + 7 I2 = powmod(2, M - 2, M) def dfs(g, v): r = [I2] if len(g[v]) == 0: return r cr = [] for w in g[v]: cr.append(dfs(g, w)) cr.sort(key = lambda v: -len(v)) d_max = len(cr[0]) for j in range(d_max): pr = 1 sm = 0 nc = 0 for cri in cr: if len(cri) <= j: break c = cri[j] pr *= c pr %= M sm += powmod(c, M - 2, M) sm %= M nc += 1 pr *= sm + M - nc pr %= M pp = 1 + M - pr pp %= M r.append(pp) return r def solve(n, p): g = [[] for _ in range(n + 1)] for i in range(n): g[p[i]].append(i + 1) r = dfs(g, 0) ans = 0 P2 = powmod(2, n, M) for c in r: ans += P2 * (1 + M - c) ans %= M return ans def main(): n = input() n = int(n) p = list(map(int, input().split())) print(solve(n, p)) if __name__ == '__main__': main() ``` No
96,825
Provide a correct Python 3 solution for this coding contest problem. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 "Correct Solution: ``` N,K=map(int,input().split()) l=list(map(int,input().split())) l.sort() print(sum(l[N-K:N])) ```
96,826
Provide a correct Python 3 solution for this coding contest problem. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 "Correct Solution: ``` n,k=map(int,input().split()) l=list(map(int,input().split())) sl=sorted(l) print(sum(sl[-k:])) ```
96,827
Provide a correct Python 3 solution for this coding contest problem. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 "Correct Solution: ``` n,k=map(int,input().split());print(sum(sorted(map(int,input().split()))[:-k-1:-1])) ```
96,828
Provide a correct Python 3 solution for this coding contest problem. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 "Correct Solution: ``` n,k=map(int,input().split()) l=list(map(int,input().split())) l.sort() l=l[n-k:n] print(sum(l)) ```
96,829
Provide a correct Python 3 solution for this coding contest problem. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 "Correct Solution: ``` N,K=map(int,input().split()) L=sorted(list(map(int,input().split()))) ans=sum(L[-K:]) print(ans) ```
96,830
Provide a correct Python 3 solution for this coding contest problem. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 "Correct Solution: ``` n,k = map(int,input().split()) l = [int(i) for i in input().split()] l.sort() print(sum(l[-k:])) ```
96,831
Provide a correct Python 3 solution for this coding contest problem. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 "Correct Solution: ``` N,K = list(map(int,input().split())) L =list(map(int,input().split())) L.sort() print(sum(L[-K:])) ```
96,832
Provide a correct Python 3 solution for this coding contest problem. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 "Correct Solution: ``` #067_B n,k=map(int,input().split()) l=sorted(list(map(int,input().split())))[::-1] print(sum(l[:k])) ```
96,833
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 Submitted Solution: ``` n,k=map(int, input().split()) List=sorted(list(map(int, input().split()))) print(sum(List[-k:])) ``` Yes
96,834
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 Submitted Solution: ``` n,k=map(int,input().split()) l=list(map(int,input().split())) print(sum(sorted(l)[-k::])) ``` Yes
96,835
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 Submitted Solution: ``` n, k = map(int, input().split()) li = sorted(list(map(int, input().split()))) print(sum(li[n - k:])) ``` Yes
96,836
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 Submitted Solution: ``` _, k = [int(i) for i in input().split()] print(sum(sorted(int(i) for i in input().split())[-k:])) ``` Yes
96,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 Submitted Solution: ``` N, K = map(int, input().split()) l = list(map(int, input().split())) l.sort(reverse=True) print(l) print(sum(l[:K])) ``` No
96,838
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 Submitted Solution: ``` n, k = list(map(int, input().split())) l = sorted(list(map(int, input().split())), reverse=True) print(l) ans = 0 for i in range(k): ans += l[i] print(ans) ``` No
96,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 Submitted Solution: ``` N,K=map(int,input().split()) li=list(map(int,input().split())) li.sort(reverse=True) ans=0 for k in range(K): ans=ans+li[k] print(ans) ``` No
96,840
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. Constraints * 1 \leq K \leq N \leq 50 * 1 \leq l_i \leq 50 * l_i is an integer. Input Input is given from Standard Input in the following format: N K l_1 l_2 l_3 ... l_{N} Output Print the answer. Examples Input 5 3 1 2 3 4 5 Output 12 Input 15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45 Output 386 Submitted Solution: ``` def main(): N, K = map(lambda i: int(i), input().split(' ')) l = list(map(lambda i: int(i), input().split(' ')) l.sort() l.reverse() m = 0 for i in range(K): m += l[i] print(m) main() ``` No
96,841
Provide a correct Python 3 solution for this coding contest problem. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 "Correct Solution: ``` s = input() print(s.rfind('Z')-s.index('A')+1) ```
96,842
Provide a correct Python 3 solution for this coding contest problem. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 "Correct Solution: ``` ss = input() print(ss.rindex('Z') - ss.index('A') + 1) ```
96,843
Provide a correct Python 3 solution for this coding contest problem. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 "Correct Solution: ``` s=input() a=s.index("A") z=s[::-1].index("Z") print(len(s)-z-a) ```
96,844
Provide a correct Python 3 solution for this coding contest problem. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 "Correct Solution: ``` import re s = input() print(len(re.search('A.*Z', s).group())) ```
96,845
Provide a correct Python 3 solution for this coding contest problem. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 "Correct Solution: ``` s = input() print(len(s) - s.find('A') - s[::-1].find('Z')) ```
96,846
Provide a correct Python 3 solution for this coding contest problem. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 "Correct Solution: ``` s=input() print(-s.find("A")+s.rfind("Z")+1) ```
96,847
Provide a correct Python 3 solution for this coding contest problem. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 "Correct Solution: ``` s = input() print(len(s)-s[::-1].find('Z')-s.find('A')) ```
96,848
Provide a correct Python 3 solution for this coding contest problem. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 "Correct Solution: ``` s = input() d1 = s.find("A") d2 = s.rfind("Z") print(d2-d1+1) ```
96,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 Submitted Solution: ``` s=input() print(len(s[s.find('A'):s.rfind("Z")+1])) ``` Yes
96,850
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 Submitted Solution: ``` s=input() print(s.rfind("Z")-s.find("A")+1) #コピペです ``` Yes
96,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 Submitted Solution: ``` s=str(input()) a,b=s.find("A"),s.rfind("Z") print(b-a+1) ``` Yes
96,852
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 Submitted Solution: ``` s = input() ans = s.rfind('Z') - s.find('A') + 1 print(ans) ``` Yes
96,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 Submitted Solution: ``` import sys def yn(b): print("Yes" if b==1 else "No") return def resolve(): readline=sys.stdin.readline ss=readline().strip() n=0 a=100000000 z=0 for s in sss: if s=="A": a=min(a,n) elif s=="Z": z=n n+=1 print(z-a+1) return resolve() ``` No
96,854
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 Submitted Solution: ``` s=list(input()) a=s.index("A") for i in range(len(s),0): if s[i-1]=="Z": z=i-1 z-=len(s)-1 sum=z-a+1 print(sum) ``` No
96,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 Submitted Solution: ``` # -*- coding: utf-8 -*- s = input() print(s) for i in range(len(s)): if s[i] == 'A': s = s[i:] break s = s[::-1] print(s) for i in range(len(s)): if s[i] == 'Z': s = s[i:] print(len(s)) break ``` No
96,856
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. Constraints * 1 ≦ |s| ≦ 200{,}000 * s consists of uppercase English letters. * There exists a substring of s that starts with `A` and ends with `Z`. Input The input is given from Standard Input in the following format: s Output Print the answer. Examples Input QWERTYASDFZXCV Output 5 Input ZABCZ Output 4 Input HASFJGHOGAKZZFEGA Output 12 Submitted Solution: ``` S=input() ans=0 tmp=0 end=0 for i in range(len(S)): if S[i]=="A": tmp=i break for i in range(1,len(S)): if S[-i]=="Z": end=len(S)-i break print(tmp,end) print(end-tmp+1) ``` No
96,857
Provide a correct Python 3 solution for this coding contest problem. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 "Correct Solution: ``` d=[[-3,0],[-2,0],[-1,0],[1,0],[2,0],[3,0],[0,-3],[0,-2],[0,-1],[0,1],[0,2],[0,3]] def f(x,y,a): a[y][x]='0' for dx,dy in d: if 0<=x+dx<8 and 0<=y+dy<8 and a[y+dy][x+dx]=='1':f(x+dx,y+dy,a) return a for i in range(int(input())): print('Data %d:'%(i+1)) input() a=[list(input()) for _ in [0]*8] for x in f(int(input())-1,int(input())-1,a):print(''.join(x)) ```
96,858
Provide a correct Python 3 solution for this coding contest problem. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 "Correct Solution: ``` def paint(f_inp, x, y): if f_inp[y][x]: f_inp[y][x] = False if f_inp[y][x - 1]: f_inp = paint(f_inp, x - 1, y) if f_inp[y][x - 2]: f_inp = paint(f_inp, x - 2, y) if f_inp[y][x - 3]: f_inp = paint(f_inp, x - 3, y) if f_inp[y][x + 1]: f_inp = paint(f_inp, x + 1, y) if f_inp[y][x + 2]: f_inp = paint(f_inp, x + 2, y) if f_inp[y][x + 3]: f_inp = paint(f_inp, x + 3, y) if f_inp[y - 1][x]: f_inp = paint(f_inp, x, y - 1) if f_inp[y - 2][x]: f_inp = paint(f_inp, x, y - 2) if f_inp[y - 3][x]: f_inp = paint(f_inp, x, y - 3) if f_inp[y + 1][x]: f_inp = paint(f_inp, x, y + 1) if f_inp[y + 2][x]: f_inp = paint(f_inp, x, y + 2) if f_inp[y + 3][x]: f_inp = paint(f_inp, x, y + 3) return f_inp i_data = 1 n = int(input()) for i in range(n): _ = input() print("Data " + str(i_data) + ":") f = [[False for i in range(14)] for j in range(14)] for i in range(8): inp = input() for j in range(8): if inp[j] == "1": f[i + 3][j + 3] = True x = int(input()) y = int(input()) f = paint(f, x + 2, y + 2) for i in range(8): s = "" for j in range(8): if f[i + 3][j + 3]: s = s + "1" else: s = s + "0" print(s) i_data += 1 ```
96,859
Provide a correct Python 3 solution for this coding contest problem. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 "Correct Solution: ``` def print_table(t): for c in t: for r in c: print("{0:d}".format(r),end="") print("") def play(t,x,y): q = [[x,y]] while True: p = q.pop(0) x = p[0] y = p[1] t[y][x] = 0 for i in range(1,4): if x+i < 8: if t[y][x+i] == 1: q.append([x+i,y]) t[y][x+i] = 0 if x-i >= 0: if t[y][x-i] == 1: q.append([x-i,y]) t[y][x-i] = 0 if y+i < 8: if t[y+i][x] == 1: q.append([x,y+i]) t[y+i][x] = 0 if y-i >= 0: if t[y-i][x] == 1: q.append([x,y-i]) t[y-i][x] = 0 if q == []: break return t n = int(input()) for i in range(1,n+1): input() # ?????????skip t = [[int(i) for i in list(input())]] for j in range(0,7): t.append([int(i) for i in list(input())]) x = int(input()) y = int(input()) tt = play(t,x-1,y-1) print('Data {0:d}:'.format(i)) print_table(tt) ```
96,860
Provide a correct Python 3 solution for this coding contest problem. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 "Correct Solution: ``` from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) dd = ((-1, 0), (0, -1), (1, 0), (0, 1)) L = 8 for i in range(N): readline() G = [list(map(int, readline().strip())) for i in range(L)] x = int(readline())-1 y = int(readline())-1 que = deque([(x, y)]) G[y][x] = 0 while que: x, y = que.popleft() for dx, dy in dd: for k in range(1, 4): nx = x + dx*k; ny = y + dy*k if not 0 <= nx < L or not 0 <= ny < L: continue if G[ny][nx]: que.append((nx, ny)) G[ny][nx] = 0 write("Data %d:\n" % (i+1)) for line in G: write("".join(map(str, line))) write("\n") solve() ```
96,861
Provide a correct Python 3 solution for this coding contest problem. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 "Correct Solution: ``` def e(x,y): A[y][x]='0' for dx,dy in[[-3,0],[-2,0],[-1,0],[1,0],[2,0],[3,0],[0,-3],[0,-2],[0,-1],[0,1],[0,2],[0,3]]: if 0<=x+dx<8 and 0<=y+dy<8 and A[y+dy][x+dx]=='1':e(x+dx,y+dy) for i in range(int(input())): print(f'Data {i+1}:') input() A=[list(input())for _ in[0]*8] e(int(input())-1,int(input())-1) for r in A:print(''.join(r)) ```
96,862
Provide a correct Python 3 solution for this coding contest problem. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 "Correct Solution: ``` def e(x,y): A[y][x]='0' for d in range(-3,4): 0<=x+d<8 and A[y][x+d]=='1'and e(x+d,y) 0<=y+d<8 and A[y+d][x]=='1'and e(x,y+d) for i in range(int(input())): print(f'Data {i+1}:') input() A=[list(input())for _ in[0]*8] e(int(input())-1,int(input())-1) for r in A:print(*r,sep='') ```
96,863
Provide a correct Python 3 solution for this coding contest problem. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 "Correct Solution: ``` def f(x,y,a): a[y][x]='0' for dx,dy in [[-3,0],[-2,0],[-1,0],[1,0],[2,0],[3,0],[0,-3],[0,-2],[0,-1],[0,1],[0,2],[0,3]]: if 0<=x+dx<8 and 0<=y+dy<8 and a[y+dy][x+dx]=='1':f(x+dx,y+dy,a) return a for i in range(int(input())): print('Data %d:'%(i+1)) input() a=[list(input()) for _ in [0]*8] [print(*x,sep='')for x in f(int(input())-1,int(input())-1,a)] ```
96,864
Provide a correct Python 3 solution for this coding contest problem. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 "Correct Solution: ``` def bumb(i, j) : global M M[j][i] = 0 for p in range(-3, 4) : if 0 <= i+p < 8 : if M[j][i+p] == '1' : bumb(i+p, j) if 0 <= j+p < 8 : if M[j+p][i] == '1' : bumb(i, j+p) n = int(input()) for i in range(n) : M = [] none = input() for j in range(8) : M.append(list(input())) X = int(input()) Y = int(input()) bumb(X-1, Y-1) print('Data ', i+1, ':', sep='') for j in range(8) : print(*M[j], sep='') ```
96,865
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` num = int(input()) def chain(L, x, y): if L[y][x] == 0: return L[y][x] = 0 for i in range(-3, 4): nx = x + i if nx in range(8): if L[y][nx] > 0: chain(L, nx, y) ny = y + i if ny in range(8): if L[ny][x] > 0: chain(L, x, ny) return for k in range(num): input() L = [] for i in range(8): l = [int(x) for x in input()] L.append(l) x = int(input())-1 y = int(input())-1 chain(L, x, y) print("Data {}:".format(k+1)) for l in L: print( "".join(map(str,l)) ) ``` Yes
96,866
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` def get_input(): while True: try: yield ''.join(input()) except EOFError: break def bomb(table, x, y): table[x][y] = False for i in range(1, 4): if x + i >= 8: break if table[x+i][y]: bomb(table, x+i, y) for i in range(1, 4): if x - i < 0: break if table[x-i][y]: bomb(table, x-i, y) for i in range(1, 4): if y + i >= 8: break if table[x][y+i]: bomb(table, x, y+i) for i in range(1, 4): if y - i < 0: break if table[x][y-i]: bomb(table, x, y-i) return N = int(input()) for l in range(N): input() table = [[False for i in range(8)] for j in range(8)] for i in range(8): L = input() for j in range(8): if int(L[j]) == 1: table[i][j] = True a = int(input()) b = int(input()) bomb(table, b-1, a-1) print("Data " + str(l+1) + ":") for i in range(8): for j in range(8): if table[i][j]: print("1", end="") else: print("0", end="") print("") ``` Yes
96,867
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0071 """ import sys def check_bombs(map, pos, dir, range=3): """ ????¢¨????±???????????????\??????????????????????????§??????????????? (?????°????????????????¢¨????±??????´?????§????????????????????????????????????????????§????????????????????????) :param map: ?????¨?????¶??? :param pos: ??????????????????????????? :param dir: ?????§????????????????¢¨????????? (up, down, left, right) :param range: ????¢¨????±?????????? :return: ???????????????????????????????????? or None """ if dir == 'up': x, y = pos while range > 0 and y > 0: if map[y-1][x] == '1': return (x, y-1) else: y -= 1 range -= 1 elif dir == 'down': x, y = pos while range > 0 and y < len(map)-1: if map[y+1][x] == '1': return (x, y+1) else: y += 1 range -= 1 elif dir == 'left': x, y = pos while range > 0 and x > 0: if map[y][x-1] == '1': return (x-1, y) else: x -= 1 range -= 1 elif dir == 'right': x, y = pos while range > 0 and x < len(map[0])-1: if map[y][x+1] == '1': return (x+1, y) else: x += 1 range -= 1 else: return None def chain_bombs(map, init_pos): """ ???????????£?????????????????¶???????¨?????????? :param map: ???????????????????????¶??? :param init_pos: (0, 0)?????????????????????????????????????????????????????§?¨? :return: ??????????????????????????¶??? """ lmap = map[:] # ??????????????¶????¨??????¨ detonated = [init_pos] # ??±?????????????????????????????????(????????????) while detonated: x, y = detonated.pop() lmap[y][x] = '0' res = check_bombs(lmap, (x, y), 'up') if res: detonated.append(res) res = check_bombs(lmap, (x, y), 'down') if res: detonated.append(res) res = check_bombs(lmap, (x, y), 'left') if res: detonated.append(res) res = check_bombs(lmap, (x, y), 'right') if res: detonated.append(res) return lmap def main(args): data_set = int(input()) maps = [] init_pos = [] for i in range(data_set): _ = input() maps.append([list(input().strip()) for _ in range(8)]) init_pos.append([int(input())-1, int(input())-1]) # ??§?¨????0??????????????????????????? count = 1 for map, pos in zip(maps, init_pos): result = chain_bombs(map, pos) print('Data {}:'.format(count)) for row in result: print(''.join(row)) count += 1 if __name__ == '__main__': main(sys.argv[1:]) ``` Yes
96,868
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` def dfs_bomb(A,x,y): X = [ 1, 0,-1, 0, 2, 0,-2, 0, 3, 0,-3, 0] Y = [ 0, 1, 0,-1, 0, 2, 0,-2, 0, 3, 0,-3] A[x][y] = "0" for i in range(12): xx = x + X[i] yy = y + Y[i] if 0 <= xx < 8 and 0 <= yy < 8: if A[xx][yy] == "1": dfs_bomb(A,xx,yy) if __name__ == '__main__': cnt = int(input()) for i in range(cnt): input() A = [] for _ in range(8): A.append(list(input())) y = int(input()) - 1 x = int(input()) - 1 dfs_bomb(A,x,y) print("Data "+str(i+1)+":") for z in range(8): print("".join(A[z])) ``` Yes
96,869
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` # Aizu Problem 0071: Bombs Chain # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") def bombs_chain(grid, row, col): offsets = [[1, 0], [-1, 0], [0, 1], [0, -1]] queue = [(row, col)] while len(queue) > 0: row0, col0 = queue.pop(0) for row_off, col_off in offsets: for k in range(1, 4): row = row0 + row_off * k col = col0 + col_off * k if 0 <= row < 8 and 0 <= col < 8 and grid[row][col] == 1: grid[row][col] = 0 queue.append((row, col)) return grid N = int(input()) for case in range(N): input() grid = [[int(_) for _ in input().strip()] for __ in range(8)] col = int(input()) - 1 row = int(input()) - 1 grid = bombs_chain(grid, row, col) print("Data %d:" % (case + 1)) for row in grid: print(''.join([str(r) for r in row])) ``` No
96,870
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` n = int(input()) input() for i in range(n): board = [list(input()) for i in range(8)] sx = int(input()) - 1 sy = int(input()) - 1 input() board[sy][sx] == 2 bomb = [] n_bomb = [[sy, sx]] points = [] for j in range(len(board)): while '1' in board[j]: px = board[j].index('1') py = j points.append([py, px]) board[j][px] = '2' while len(n_bomb) != 0: bomb += n_bomb n_bomb = [] for b in bomb: for p in points: if (p[0] == b[0] and b[1]-3 <= p[1] <= b[1]+3) or (p[1] == b[1] and b[0]-3 <= p[0] <= b[0]+3): points.remove(p) n_bomb.append(p) ans = [['0'] * 8 for j in range(8)] for p in points: ans[p[0]][p[1]] = '1' print("Data %s:" % str(i+1)) for p in ans: print("".join(p)) ``` No
96,871
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` # -*- coding: utf-8 -*- import sys import os import itertools T = int(input()) for t in range(T): input() map = [] for i in range(8): s = input().strip() map.append(list(s)) X = int(input()) Y = int(input()) X -= 1 Y -= 1 def exist_bomb(x, y): if 0 <= x < 8 and 0 <= y < 8 and map[y][x] == '1': return True else: return False Q = [] Q.append((X, Y)) while Q: x, y = Q.pop(0) for i in range(1, 4): if exist_bomb(x + i, y): Q.append((x + i, y)) map[y][x+i] = '0' if exist_bomb(x - i, y): Q.append((x - i, y)) map[y][x-i] = '0' if exist_bomb(x, y + i): Q.append((x, y + i)) map[y+i][x] = '0' if exist_bomb(x, y - i): Q.append((x, y - i)) map[y-i][x] = '0' # result if t != 0: print() print("Data {}:".format(t+1)) for i, row in enumerate(map): print(''.join(row), end='') if i != 7: print() ``` No
96,872
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` # -*- coding: utf-8 -*- import sys import os import itertools T = int(input()) for t in range(T): input() map = [] for i in range(8): s = input().strip() map.append(list(s)) X = int(input()) Y = int(input()) X -= 1 Y -= 1 def exist_bomb(x, y): if 0 <= x < 8 and 0 <= y < 8 and map[y][x] == '1': return True else: return False Q = [] Q.append((X, Y)) while Q: x, y = Q.pop(0) for i in range(1, 4): if exist_bomb(x + i, y): Q.append((x + i, y)) map[y][x+i] = '0' if exist_bomb(x - i, y): Q.append((x - i, y)) map[y][x-i] = '0' if exist_bomb(x, y + i): Q.append((x, y + i)) map[y+i][x] = '0' if exist_bomb(x, y - i): Q.append((x, y - i)) map[y-i][x] = '0' # result print("Data {}:".format(t+1)) for row in map: print(''.join(row)) ``` No
96,873
Provide a correct Python 3 solution for this coding contest problem. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 "Correct Solution: ``` def printF(field,w,h): for i in range(h): print(field[i]) def getp(f,p,y,x,h,w,v): if y<0 or x<0 or x>=w: return 0 if y>=h: if v==True: return 1 return 0 k = f[y][x] r = 0 if k==0: if p[y][x]>=0: return p[y][x] r = getp(f,p,y+1,x-1,h,w,False)+getp(f,p,y+1,x,h,w,True)+getp(f,p,y+1,x+1,h,w,False) p[y][x] = r elif k==1: r = 0 elif k==2: if v == True: if p[y][x]>=0: return p[y][x] r = getp(f,p,y+2,x,h,w,True) p[y][x] = r else: r = 0 #print("gp({},{},{}):({},{})".format(x,y,v,k,r)) return r w,h = map(int,input().split()) while w!=0 and h != 0: field = [] for i in range(h): field.append(list(map(int,input().split()))) #initialize p = [] for i in range(h): p.append([-1]*w) #calc print(sum(map(lambda x:getp(field,p,0,x,h,w,True), range(w)))) w,h = map(int,input().split()) ```
96,874
Provide a correct Python 3 solution for this coding contest problem. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 "Correct Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = '{}_{}'.format(x, 0) Q.append((x, 0)) path[t] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue elif cy == y_limit -1: ans += num continue for i in range(len(dx)): nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if (ny >= y_limit - 1) and field[ny][nx] == BLANK: ans += num else: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == BLANK: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = map(int, input().strip().split()) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == '__main__': main(sys.argv[1:]) ```
96,875
Provide a correct Python 3 solution for this coding contest problem. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 "Correct Solution: ``` def solve(c): w, h = len(c[0]), len(c) dp = [[0] * w for _ in range(h)] #????????? for x in range(w): if c[1][x] == 0: dp[1][x] = 1 for y in range(2, h): for x in range(w): if c[y][x] == 1: continue if c[y - 2][x] == 2: dp[y][x] += dp[y - 2][x] if c[y - 1][x] == 0: dp[y][x] += dp[y - 1][x] if c[y][x] == 0: if c[y - 1][x - 1] == 0: dp[y][x] += dp[y - 1][x - 1] if c[y - 1][x + 1] == 0: dp[y][x] += dp[y - 1][x + 1] return sum(dp[-1]) + sum(dp[-2][x] for x in range(w) if c[-2][x] == 2) import sys f = sys.stdin while True: w, h = map(int, f.readline().split()) if w == 0: break course = [[1] * (w + 2)] + [[1] + list(map(int, f.readline().split())) + [1] for _ in range(h)] print(solve(course)) ```
96,876
Provide a correct Python 3 solution for this coding contest problem. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 "Correct Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° # dy = [1, 1, 1] dx = [0, -1, 1] # ?????????????????????????????????????§??????? x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() # ?????§??????????????????????????¨??????????????\??? # ???????????§??????????????§????????´????????¢???????????\?????????????????? for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? k = '{}_{}'.format(x, 0) Q.append((x, 0)) path[k] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? k = '{}_{}'.format(cx, cy) num = path.pop(k) # ????????§?¨?????????????????????° if field[cy][cx] == OBSTACLE: # ?????£????????§?????°??????????????????????????±????????????????????????????????§?????£????????????????? continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: # ?????£???????????????????¶?????????´??????OK??¨????????? ans += num else: k = '{}_{}'.format(cx, cy+2) if not path[k]: Q.append((cx, cy+2)) path[k] += num continue elif cy == y_limit -1: ans += num continue for i in range(3): # ?????????3???len(dy)????????? nx = cx + dx[i] # ?????°????????§?¨? ny = cy + 1 # ??????+1????????§???dy[i]??¨?????????????????????OK if 0<= nx < x_limit: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: k = '{}_{}'.format(nx, ny+2) if not path[k]: Q.append((nx, ny+2)) path[k] += num elif field[ny][nx] == BLANK: if (ny >= y_limit - 1): ans += num else: k = '{}_{}'.format(nx, ny) if not path[k]: Q.append((nx, ny)) path[k] += num return ans def solve2(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = '{}_{}'.format(x, 0) Q.append((x, 0)) path[t] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue elif cy == y_limit -1: ans += num continue for i in range(3): # ?????????3???len(dy)????????? nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == BLANK: if (ny >= y_limit - 1): ans += num else: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = map(int, input().strip().split()) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve2(field) print(result) if __name__ == '__main__': main(sys.argv[1:]) ```
96,877
Provide a correct Python 3 solution for this coding contest problem. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 "Correct Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° # dy = [1, 1, 1] dx = [0, -1, 1] # ?????????????????????????????????????§??????? x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() # ?????§??????????????????????????¨??????????????\??? # ???????????§??????????????§????????´????????¢???????????\?????????????????? for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? k = '{}_{}'.format(x, 0) Q.append((x, 0)) path[k] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? k = '{}_{}'.format(cx, cy) num = path.pop(k) # ????????§?¨?????????????????????° if field[cy][cx] == OBSTACLE: # ?????£????????§?????°??????????????????????????±????????????????????????????????§?????£????????????????? continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: # ?????£???????????????????¶?????????´??????OK??¨????????? ans += num else: k = '{}_{}'.format(cx, cy+2) if not path[k]: Q.append((cx, cy+2)) path[k] += num continue elif cy == y_limit -1: ans += num continue for i in range(3): # ?????????3???len(dy)????????? nx = cx + dx[i] # ?????°????????§?¨? ny = cy + 1 # ??????+1????????§???dy[i]??¨?????????????????????OK if 0<= nx < x_limit: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: k = '{}_{}'.format(nx, ny+2) if not path[k]: Q.append((nx, ny+2)) path[k] += num elif field[ny][nx] == BLANK: if (ny >= y_limit - 1): ans += num else: k = '{}_{}'.format(nx, ny) if not path[k]: Q.append((nx, ny)) path[k] += num return ans def main(args): while True: X, Y = map(int, input().strip().split()) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == '__main__': main(sys.argv[1:]) ```
96,878
Provide a correct Python 3 solution for this coding contest problem. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 "Correct Solution: ``` while True: X, Y = map(int, input().split()) if X == 0: break a = [[1]+list(map(int, input().split()))+[1] for _ in [0]*Y] + [[0]*(X+2)] dp = [list(map(lambda x: x^1, a[0]))] + [[0]*(X+2) for _ in [0]*Y] for y in range(Y-1): for x, (square, cnt) in enumerate(zip(a[y][1:], dp[y][1:-1]), start=1): if square == 0: for tx in range(x-1, x+2): if a[y+1][tx] == 0 or a[y+1][tx] == 2 and x == tx: dp[y+1][tx] += cnt elif square == 2: dp[y+2][x] += cnt for x in range(1, X+1): if a[Y-1][x] != 1: dp[Y][x] += dp[Y-1][x] print(sum(dp[-1])) ```
96,879
Provide a correct Python 3 solution for this coding contest problem. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 "Correct Solution: ``` while(True): X,Y = map(int, input().split()) if X==0 and Y==0: break ar = [list(map(int, input().split())) for _ in range(Y)] ar.append([0]*X) br = [[0]*X for _ in range(Y+1)] for j in range(X): if ar[-2][j] != 1: br[-2][j] = 1 br[-1][j] = 1 for i in range(Y-2,-1,-1): for j in range(X): if j-1 >= 0 and ar[i][j] != 2 and ar[i+1][j-1] == 0: br[i][j] += br[i+1][j-1] if j+1 < X and ar[i][j] != 2 and ar[i+1][j+1] == 0: br[i][j] += br[i+1][j+1] if ar[i][j] != 2 and ar[i+1][j] != 1: br[i][j] += br[i+1][j] if ar[i][j] == 2 and ar[i+2][j] != 1: br[i][j] += br[i+2][j] for j in range(X): if ar[i][j] == 1: br[i][j] = 0 print(sum(br[0])) ```
96,880
Provide a correct Python 3 solution for this coding contest problem. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 "Correct Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = '{}_{}'.format(x, 0) Q.append((x, 0)) path[t] = 1 if y_limit < 2: return len(Q) while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue elif cy == y_limit -1: ans += num continue for i in range(len(dx)): nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if (ny >= y_limit - 1) and field[ny][nx] == BLANK: ans += num else: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == BLANK: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = map(int, input().strip().split()) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == '__main__': main(sys.argv[1:]) ```
96,881
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° # dy = [1, 1, 1] dx = [0, -1, 1] # ?????????????????????????????????????§??????? x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() # ?????§??????????????????????????¨??????????????\??? # ???????????§??????????????§????????´????????¢???????????\?????????????????? for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? k = '{}_{}'.format(x, 0) Q.append((x, 0)) path[k] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? k = '{}_{}'.format(cx, cy) num = path.pop(k) # ????????§?¨?????????????????????° if field[cy][cx] == OBSTACLE: # ?????£????????§?????°??????????????????????????±????????????????????????????????§?????£????????????????? continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: # ?????£???????????????????¶?????????´??????OK??¨????????? ans += num else: k = '{}_{}'.format(cx, cy+2) if not path[k]: Q.append((cx, cy+2)) path[k] += num continue elif cy == y_limit -1: ans += num continue for i in range(3): # ?????????3???len(dy)????????? nx = cx + dx[i] # ?????°????????§?¨? ny = cy + 1 # ??????+1????????§???dy[i]??¨?????????????????????OK if 0<= nx < x_limit: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: k = '{}_{}'.format(nx, ny+2) if not path[k]: Q.append((nx, ny+2)) path[k] += num elif field[ny][nx] == BLANK: if (ny >= y_limit - 1): ans += num else: k = '{}_{}'.format(nx, ny) if not path[k]: Q.append((nx, ny)) path[k] += num return ans def solve2(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = '{}_{}'.format(x, 0) Q.append((x, 0)) path[t] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue elif cy == y_limit -1: ans += num continue for i in range(3): # ?????????3???len(dy)????????? nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == BLANK: if (ny >= y_limit - 1): ans += num else: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def solve3(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 X = len(field[0]) Y = len(field) dp = [[0] * X for _ in range(Y)] # ??????????????°???????????? for x in range(X): if field[0][x] == BLANK: dp[0][x] = 1 for y in range(1, Y): for x in range(X): t = 0 mark = field[y][x] if mark == BLANK: if field[y-1][x] != JUMP: t += dp[y-1][x] if x > 0 and field[y-1][x-1] != JUMP: t += dp[y-1][x-1] if x < X-1 and field[y-1][x+1] != JUMP: t += dp[y-1][x+1] if y > 1 and field[y-2][x] == JUMP: t += dp[y-2][x] elif mark == JUMP: if field[y-1][x] != JUMP: t = dp[y-1][x] if y > 1 and field[y-2][x] == JUMP: t += dp[y-2][x] dp[y][x] = t ans = sum(dp[-1]) if Y > 1: for x in range(X): if field[-2][x] == JUMP: ans += dp[-2][x] return ans def main(args): while True: X, Y = map(int, input().strip().split()) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve3(field) print(result) if __name__ == '__main__': main(sys.argv[1:]) ``` Yes
96,882
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = '{}_{}'.format(x, 0) Q.append((x, 0)) path[t] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue elif cy == y_limit -1: ans += num continue for i in range(3): # ?????????3???len(dy)????????? nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == BLANK: if (ny >= y_limit - 1): ans += num else: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = map(int, input().strip().split()) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == '__main__': main(sys.argv[1:]) ``` Yes
96,883
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` while True: x, y = map(int, input().split()) if x == 0: break mp = [[1] + list(map(int, input().split())) + [1] for _ in range(y)] mp.insert(0, [1] * (x + 2)) mp.append([0] * (x + 2)) mp.append([0] * (x + 2)) tr = [[0] * (x + 2) for _ in range(y + 2)] for i in range(1, x + 1): if mp[1][i] == 0: tr[1][i] = 1 for i in range(2, y + 1): for j in range(1, x + 1): if mp[i][j] == 0: for k in range(j - 1, j + 2): if mp[i - 1][k] == 0: tr[i][j] += tr[i - 1][k] if mp[i - 2][j] == 2: tr[i][j] += tr[i - 2][j] elif mp[i][j] == 2: if mp[i - 1][j] == 0: tr[i][j] += tr[i - 1][j] if mp[i - 2][j] == 2: tr[i][j] += tr[i - 2][j] ans = sum(tr[y]) for i in range(1, x + 1): if mp[y - 1][i] == 2: ans += tr[y - 1][i] print(ans) ``` Yes
96,884
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` while 1: x,y = list(map(int, input().split())) if x == 0: break c = [list(map(int, input().split())) for _ in range(y)] c.append([0]*x) c.append([0]*x) dp = [[0]*x for _ in range(y+2)] for i in range(x): if c[0][i] == 0: dp[0][i] = 1 for i in range(y): for j in range(x): if c[i][j] == 0: if i != y-1: if j != 0 and c[i+1][j-1] == 0: dp[i+1][j-1] += dp[i][j] if j != x-1 and c[i+1][j+1] == 0: dp[i+1][j+1] += dp[i][j] if c[i+1][j] != 1: dp[i+1][j] += dp[i][j] elif c[i][j] == 2: if c[i+2][j] != 1: dp[i+2][j] += dp[i][j] ans = 0 for i in dp[y-1:y+1]: ans += sum(i) print(ans) """ while 1: x,y = list(map(int, input().split())) if x == 0: break c = [list(map(int, input().split())) for _ in range(y)] dp = [[0]*x for _ in range(y+1)] for i in range(x): if c[0][i] == 0: dp[0][i] = 1 for i in range(1,y): for j in range(x): if c[i][j] == 0: if i >= 2 and c[i-2][j] == 2: dp[i][j] += dp[i-2][j] if j != 0 and c[i-1][j-1] == 0:dp[i][j] += dp[i-1][j-1] if j != x-1 and c[i-1][j+1] == 0:dp[i][j] += dp[i-1][j+1] if c[i-1][j] != 1: dp[i][j] += dp[i-1][j] elif c[i][j] == 2: dp[i][j] += dp[i-1][j] if i >= 2 and c[i-2][j] == 2: dp[i][j] += dp[i-2][j] for i in dp: print(i) ans = 0 for i in range(x): ans += dp[y-1][i] if y >= 2 and c[y-2][i] == 2: ans += dp[y-2][j] print(ans) """ ``` Yes
96,885
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = '{}_{}'.format(x, 0) Q.append((x, 0)) path[t] = 1 if y_limit < 2: return len(Q) while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue elif cy == y_limit -1: ans += num continue for i in range(len(dx)): nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if (ny >= y_limit - 1) and field[ny][nx] != OBSTACLE: ans += num else: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == BLANK: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = map(int, input().strip().split()) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == '__main__': main(sys.argv[1:]) ``` No
96,886
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): # 0: ????????°, 1: ?????????, 2: ?????£????????° ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????° Q = deque() for x, m in enumerate(field[0]): if m == 0: # ?????????????????°?????´????????????????????????????????? Q.append((x, 0)) t = '{}_{}'.format(x, 0) path[t] = 1 if y_limit < 2: return len(Q) while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == 1: # ?????£????????§?????°????????????????????? continue elif field[cy][cx] == 2: # ?????£????????§?????°?????????????????£????????° if cy+2 >= y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue for i in range(len(dx)): nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if ny >= y_limit - 1 and field[ny][nx] != 1: ans += num else: if field[ny][nx] == 2 and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == 0: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = map(int, input().strip().split()) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == '__main__': main(sys.argv[1:]) ``` No
96,887
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` def algorithm(): def down_jump(x, y, times): if x == r: out_map[x - 1][y] += times elif x == r - 1: out_map[x][y] += times elif in_map[x][y] == 2: down_jump(x + 2, y, times) else: out_map[x][y] += times while True: c, r = map(int, input().split()) if c == 0 and r == 0: break in_map = [] out_map = [[0 for _ in range(c)] for _ in range(r)] for _ in range(r): in_map.append(list(map(int, input().split()))) for i in range(c): if in_map[0][i] == 0 or in_map[0][i] == 2: out_map[0][i] = 1 for i in range(r): for j in range(c): if in_map[i][j] == 0 or (i == 0 and in_map[i][j] == 2): # ???. if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0 and in_map[i][j] == 0: out_map[i + 1][j - 1] += out_map[i][j] # ???. if in_map[i][j] == 2: down_jump(i, j, out_map[i][j]) elif i + 1 < r and in_map[i + 1][j] == 0: out_map[i + 1][j] += out_map[i][j] elif i + 1 < r and in_map[i + 1][j] == 2: down_jump(i + 1, j, out_map[i][j]) # ???. if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0 and in_map[i][j] == 0: out_map[i + 1][j + 1] += out_map[i][j] for i in range(c): out_map[r - 1][i] = 0 if in_map[r - 1][i] else out_map[r - 1][i] print(sum(out_map[r - 1])) def main(): algorithm() if __name__ == '__main__': main() ``` No
96,888
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` """ Created by Jieyi on 8/16/16. """ def algorithm(): def down_jump(x, y, times): if x == r: out_map[x - 1][y] += times elif x == r - 1: out_map[x][y] += times elif in_map[x][y] == 2: down_jump(x + 2, y, times) else: out_map[x][y] += times while True: c, r = map(int, input().split()) if c == 0 and r == 0: break in_map = [] out_map = [[0 for _ in range(c)] for _ in range(r)] for _ in range(r): in_map.append(list(map(int, input().split()))) for i in range(r): if in_map[0][i] == 0: out_map[0][i] = 1 for i in range(r): for j in range(c): if in_map[i][j] == 0: # ???. if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0: out_map[i + 1][j - 1] += out_map[i][j] # ???. if i + 1 < r and in_map[i + 1][j] == 0: out_map[i + 1][j] += out_map[i][j] elif i + 1 < r and in_map[i + 1][j] == 2: down_jump(i + 1, j, out_map[i][j]) # ???. if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0: out_map[i + 1][j + 1] += out_map[i][j] print(sum(out_map[c - 1])) def main(): algorithm() if __name__ == '__main__': main() ``` No
96,889
Provide a correct Python 3 solution for this coding contest problem. Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of W × H squares. Each square is identified with its column and row number, thus the square located in the x-th column and the y-th row is represented as (x, y). The left-most square in the top row is (0, 0) and the right-most square in the bottom row is (W-1, H-1). Bob moves a character "BomBom" to clear the game. BomBom is initially located at (0, 0). The game is won if Bob successfully destroys all the enemy characters on the board by manipulating BomBom cleverly. The enemy characters are fixed on specific squares, and Bob can manipulate BomBom using the following two operations any number of times. * One-square movement in the up, down, left, or right direction within the board * Using a bomb, eliminate all the enemy characters that are located in the same column and row as that of BomBom BomBom consumes a Cost when it moves from one square to another. BomBom can use a bomb any number of times without consuming a Cost. Use of a bomb has no effect on BomBom’s behavior and it can move even to a square where an enemy character is located. Given the board size and enemy information, make a program to evaluate the minimum Cost BomBom consumes before it destroys all enemy characters. Input The input is given in the following format. W H N x_1 y_1 x_2 y_2 : x_N y_N The first line provides the number of squares in the horizontal direction W (1 ≤ W ≤ 105), in the vertical direction H (1 ≤ H ≤ 105), and the number of enemy characters N (1 ≤ N ≤ 105). Each of the subsequent N lines provides location information of the i-th enemy, column x_i (0 ≤ x_i ≤ W-1) and row y_i (0 ≤ y_i ≤ H-1). The number of enemy characters in a specific square can be either one or zero. Output Output the minimum Cost in a line. Examples Input 5 4 4 0 3 1 1 2 2 2 3 Output 2 Input 6 6 5 2 1 5 2 3 3 1 4 1 5 Output 4 Input 8 8 4 6 0 7 0 0 6 0 7 Output 0 "Correct Solution: ``` w, h, n = map(int, input().split()) xys = sorted([list(map(int, input().split())) for _ in range(n)]) y_max = [0] for _, y in reversed(xys): y_max.append(max(y_max[-1], y)) xs = [0] + [x for x, _ in xys] print(min([xs[i] + y_max[n - i] for i in range(n + 1)])) ```
96,890
Provide a correct Python 3 solution for this coding contest problem. Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of W × H squares. Each square is identified with its column and row number, thus the square located in the x-th column and the y-th row is represented as (x, y). The left-most square in the top row is (0, 0) and the right-most square in the bottom row is (W-1, H-1). Bob moves a character "BomBom" to clear the game. BomBom is initially located at (0, 0). The game is won if Bob successfully destroys all the enemy characters on the board by manipulating BomBom cleverly. The enemy characters are fixed on specific squares, and Bob can manipulate BomBom using the following two operations any number of times. * One-square movement in the up, down, left, or right direction within the board * Using a bomb, eliminate all the enemy characters that are located in the same column and row as that of BomBom BomBom consumes a Cost when it moves from one square to another. BomBom can use a bomb any number of times without consuming a Cost. Use of a bomb has no effect on BomBom’s behavior and it can move even to a square where an enemy character is located. Given the board size and enemy information, make a program to evaluate the minimum Cost BomBom consumes before it destroys all enemy characters. Input The input is given in the following format. W H N x_1 y_1 x_2 y_2 : x_N y_N The first line provides the number of squares in the horizontal direction W (1 ≤ W ≤ 105), in the vertical direction H (1 ≤ H ≤ 105), and the number of enemy characters N (1 ≤ N ≤ 105). Each of the subsequent N lines provides location information of the i-th enemy, column x_i (0 ≤ x_i ≤ W-1) and row y_i (0 ≤ y_i ≤ H-1). The number of enemy characters in a specific square can be either one or zero. Output Output the minimum Cost in a line. Examples Input 5 4 4 0 3 1 1 2 2 2 3 Output 2 Input 6 6 5 2 1 5 2 3 3 1 4 1 5 Output 4 Input 8 8 4 6 0 7 0 0 6 0 7 Output 0 "Correct Solution: ``` W, H, N = map(int, input().split()) P = [list(map(int, input().split())) for i in range(N)] P.sort() st = [] for x, y in P: while st and (st[-1][0] == x or st[-1][1] <= y): st.pop() st.append((x, y)) ans = 10**9 prv = 0 for x, y in st: ans = min(ans, prv+y) prv = x ans = min(ans, prv) print(ans) ```
96,891
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of W × H squares. Each square is identified with its column and row number, thus the square located in the x-th column and the y-th row is represented as (x, y). The left-most square in the top row is (0, 0) and the right-most square in the bottom row is (W-1, H-1). Bob moves a character "BomBom" to clear the game. BomBom is initially located at (0, 0). The game is won if Bob successfully destroys all the enemy characters on the board by manipulating BomBom cleverly. The enemy characters are fixed on specific squares, and Bob can manipulate BomBom using the following two operations any number of times. * One-square movement in the up, down, left, or right direction within the board * Using a bomb, eliminate all the enemy characters that are located in the same column and row as that of BomBom BomBom consumes a Cost when it moves from one square to another. BomBom can use a bomb any number of times without consuming a Cost. Use of a bomb has no effect on BomBom’s behavior and it can move even to a square where an enemy character is located. Given the board size and enemy information, make a program to evaluate the minimum Cost BomBom consumes before it destroys all enemy characters. Input The input is given in the following format. W H N x_1 y_1 x_2 y_2 : x_N y_N The first line provides the number of squares in the horizontal direction W (1 ≤ W ≤ 105), in the vertical direction H (1 ≤ H ≤ 105), and the number of enemy characters N (1 ≤ N ≤ 105). Each of the subsequent N lines provides location information of the i-th enemy, column x_i (0 ≤ x_i ≤ W-1) and row y_i (0 ≤ y_i ≤ H-1). The number of enemy characters in a specific square can be either one or zero. Output Output the minimum Cost in a line. Examples Input 5 4 4 0 3 1 1 2 2 2 3 Output 2 Input 6 6 5 2 1 5 2 3 3 1 4 1 5 Output 4 Input 8 8 4 6 0 7 0 0 6 0 7 Output 0 Submitted Solution: ``` class Node(object):#Nodeを扱うクラス def __init__(self, name): self.name = name def getName(self):#Nodeの名前を返す return self.name def __str__(self): return self.name class Node_W(Node):#重さ付きNodeを扱うクラス def __init__(self, name): self.name = name self.w = 0 def addWeight(self,weight): self.w += weight class Edge(object):#エッジを扱うクラス def __init__(self, src, dest): self.src = src self.dest = dest def getSource(self):#親Nodeを返す return self.src def getDestination(self):#子Nodeを返す return self.dest def __str__(self): return self.src + "->" + self.dest class Graph(object): def __init__(self): self.Nodes = []#グラフ上のNode self.Edges = {}#グラフ上のエッジ親Nodeのキーに対して子Nodeのリストを返す def addNode(self, node):#グラフにNodeを加える if(node in self.Nodes): raise ValueError("そのNodeはもうあるよ") else: self.Nodes.append(node) self.Edges[node] = []#nodeの子Nodeのリスト def addEdges(self, edge):#グラフ上にエッジを加える src = edge.getSource() dest = edge.getDestination() if src not in self.Nodes or dest not in self.Nodes: raise ValueError("そのNodeはグラフ上にありません") else: self.Edges[src].append(dest) def getChildList(self,node):#nodeの子Nodeのリストを返す return self.Edges[node] def put_player(self, x, y, W, H, L):#x, yはplayerの座標, W, Hはx, y座標の限界,Lは受け取ったNode_W型を含むリスト k = W - H index = (H*y) + x + k*y if index >= H*W: raise ValueError("そんな座標はないよ") else: L[index].w = 1 def __str__(self): s = "" for src in self.Nodes: for dest in self.Edges[src]: s = s + src.getNode() + "->" + dest.getNode() + '\n' return s def ShowPath(path):#pathはNode_W型からなるリスト s = "" for nextNode in range(len(path)): s = s + path[nextNode].getName() + "(" + str(path[nextNode].w) + ")" if nextNode != len(path) - 1: s = s + "->" return s all_path1 = []#すべての経路を保存する count = 0 def all_search(g, start, end, path, all_path, toPrint = True):#グラフ上の全経路を保存する path = path + [start] if toPrint == True: ShowPath(path) all_path.append(path) for child in g.getChildList(start): if child not in path:#ループはしない newpath = all_search(g,child,end,path,all_path,toPrint = True) def make_field(W,H): #W,Hはint型 k = 0 k = W - H Nodes= [] #pointの要素数分だけNode_Wを作りリストに保存する for i in range(0,W * H,1): Nodes.append(Node_W(str(i))) g = Graph() for i in range(0,W*H, 1):#グラフ上にNodesで作ったNodeを追加する g.addNode(Nodes[i]) for i in range(H): for w in range(W): num = (H*i) + w + k * i if(i != H - 1):#この時は下につなげるNodeがある g.addEdges(Edge(Nodes[num],Nodes[num + W])) if(w != W - 1):#この時は横につなげるNodeがある g.addEdges(Edge(Nodes[num], Nodes[num + 1])) return g class Player(object): def __init__(self, x, y, L,g,W,H):#x,yはplayerを配置する座標, LはNode_W型を含むリスト,gはplayerを配置するField,W,Xはx座標y座標の限界 g.put_player(x,y,W,H,L) class Main(Player): def __init__(self,L,g,W,H): g.put_player(0,0,W,H,L) self.cost = 0 self.now_position = 0 self.W = W self.H = H self.L = L def move(self,g, node):#gはgraph型,nodeはNode型,与えられたNodeへ進む g.Nodes[self.now_position].w = 0 self.now_position = int(node.getName()) g.Nodes[self.now_position].w = 0 if(int(node.getName()) == 0): self.cost += 0 #0番に移動する場合はコスト0 else: self.cost += 1 def destroy(self, g): h1 = self.W h2 = self.W mod = self.now_position % self.W i = 1 j = 1 k = self.W - self.H g.Nodes[self.now_position].w = 0 while(self.now_position - h1 >= 0):#現在位置の上の敵を消す g.Nodes[self.now_position - h1].w = 0 h1 += self.W while(self.now_position + h2 < self.H * self.W):#現在位置の下の敵を消す g.Nodes[self.now_position + h2].w = 0 h2 += self.W while((self.now_position - i) % self.W != self.W - 1 and self.now_position - i < self.H * self.W and self.now_position - i > 0):#現在位置の左の敵を消す g.Nodes[self.now_position - i].w = 0 i += 1 while((self.now_position + j) % self.W != 0 and self.now_position + j < self.H * self.W and self.now_position + j > 0):#現在位置の右の敵を消す g.Nodes[self.now_position + j].w = 0 j += 1 def ShowGraph(g,H,W):#gはgraph型 result = "" k = W - H for h in range(H): for w in range(W): result = result + g.Nodes[(H * h) + w + k*h].getName() + "(" + str(g.Nodes[(H*h) + w + k * h].w) + ")" if(w != W - 1): result = result + "->" else: result = result + '\n' if (h != H -1): for w in range(W): t = int(g.Nodes[(H*h) + w + k * h].getName()) s = 0 while(t//10 != 0): s += 1 t /= 10 result = result + "↓" + " " + " "*s s = 0 if(w == W - 1): result = result + '\n' return result def SearchWeight(g):#gはgraph型,graph上のNodeがすべて0ならTrue,それ以外ならFalseを返す for i in range(len(g.Nodes)): if g.Nodes[i].w == 1: return False return True def test1():#グラフが正常につくられているかテスト g = make_field(6,6) start = g.Nodes[0] end = g.Nodes[6*6 - 1] all_path = [] all_search(g, start, end, [], all_path,toPrint = True ) main = Player(0,0,g.Nodes,g,6,6) enemy1 = Player(1,1,g.Nodes,g, 6,6) enemy2 = Player(5,5,g.Nodes,g, 6,6) for i in range(len(all_path)): print(ShowPath(all_path[i])) print(str(i)) def test2():#正常に爆破ができるのかを確かめるテスト W, H = map(int, input().split()) g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] main = Main(g.Nodes,g,W,H) N = int(input()) for i in range(N): x, y = map(int, input().split()) Player(x, y, g.Nodes,g,W,H) all_search(g,start, end, [], all_path, toPrint = True) print(ShowGraph(g, H, W)) main.move(g,g.Nodes[6]) main.destroy(g) print("爆破!") print(ShowGraph(g,H,W)) def test3():#グラフ上のある経路を正常に動くのかテスト W, H = map(int, input().split()) g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] main = Main(g.Nodes,g,W,H) N = int(input()) for i in range(N): x, y = map(int, input().split()) Player(x, y, g.Nodes,g,W,H) all_search(g,start, end, [], all_path, toPrint = True) print(ShowPath(all_path[4])) print()#改行 print(ShowGraph(g, H, W)) print()#改行 for path in (all_path[4]): main.move(g,path) print(str(path.getName())+"番に移動しました!") print()#改行 print(ShowGraph(g, H, W)) print() print("現在までのコスト :",str(main.cost)) print()#改行 for i in range(len(all_path)): print(ShowPath(all_path[i])) print(str(i)) def test4():#1つの経路で動くたびに爆発できるのかテスト W, H = map(int, input().split()) g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] main = Main(g.Nodes,g,W,H) N = int(input()) for i in range(N): x, y = map(int, input().split()) Player(x, y, g.Nodes,g,W,H) all_search(g,start, end, [], all_path, toPrint = True) print(ShowPath(all_path[4])) print()#改行 print(ShowGraph(g, H, W)) print()#改行 for path in (all_path[4]): main.move(g,path) print(str(path.getName())+"番に移動しました!") print()#改行 print(ShowGraph(g, H, W)) main.destroy(g) print("爆破しました!") print(ShowGraph(g, H, W)) print() print("現在までのコスト :",str(main.cost)) print()#改行 def test5():#全経路に関して爆発を試す W, H = map(int, input().split()) X = [] Y = [] g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] N = int(input()) for i in range(N): x, y = map(int, input().split()) X.append(x) Y.append(y) all_search(g,start, end, [], all_path, toPrint = True) print()#改行 print(ShowGraph(g, H, W)) print()#改行 for root in all_path: for i in range(N): Player(X[i], Y[i], g.Nodes, g, W, H) main = Main(g.Nodes,g,W,H) for path in (root): print(ShowPath(root)) main.move(g,path) print(str(path.getName())+"番に移動しました!") print()#改行 print(ShowGraph(g, H, W)) main.destroy(g) print("爆破しました!") print(ShowGraph(g, H, W)) if(SearchWeight(g) == True): print("全滅や!") else: print("まだ敵がおるで!") print() print("現在までのコスト :",str(main.cost)) print()#改行 def test6():#全経路に関して爆発を試す W, H = map(int, input().split()) X = [] Y = [] min = H*W #最小のコストを保存 g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] N = int(input()) for i in range(N): x, y = map(int, input().split()) X.append(x) Y.append(y) all_search(g,start, end, [], all_path, toPrint = True) print()#改行 print(ShowGraph(g, H, W)) print()#改行 for root in all_path: for i in range(N): Player(X[i], Y[i], g.Nodes, g, W, H) main = Main(g.Nodes,g,W,H) for path in (root): print(ShowPath(root)) main.move(g,path) print(str(path.getName())+"番に移動しました!") print()#改行 print(ShowGraph(g, H, W)) main.destroy(g) print("爆破しました!") print(ShowGraph(g, H, W)) if(SearchWeight(g) == True): print("全滅や!") if main.cost < min: min = main.cost break else: print("まだ敵がおるで!") print() print("現在までのコスト :",str(main.cost)) print()#改行 print("現在の最小コスト :",str(min)) def test7(): W, H, N = map(int, input().split()) X = [] Y = [] l = 0 min = H*W #最小のコストを保存 g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] for i in range(N): x, y = map(int, input().split()) X.append(x) Y.append(y) all_search(g,start, end, [], all_path, toPrint = False) for root in all_path: for i in range(N): Player(X[i], Y[i], g.Nodes, g, W, H) main = Main(g.Nodes,g,W,H) for path in (root): main.move(g,path) main.destroy(g) if(SearchWeight(g) == True): if main.cost < min: min = main.cost l = root break print(str(min)) print(ShowPath(l)) for i in range(N): Player(X[i], Y[i], g.Nodes, g, W, H) main = Main(g.Nodes, g, W, H) for path in (root): print(ShowPath(root)) main.move(g,path) print(str(path.getName())+"番に移動しました!") print()#改行 print(ShowGraph(g, H, W)) main.destroy(g) print("爆破しました!") print(ShowGraph(g, H, W)) if(SearchWeight(g) == True): print("全滅や!") break else: print("まだ敵がおるで!") print() print("現在までのコスト :",str(main.cost)) print()#改行 def test8(): W, H, N = map(int, input().split()) X = [] Y = [] min = H*W #最小のコストを保存 g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] for i in range(N): x, y = map(int, input().split()) X.append(x) Y.append(y) all_search(g,start, end, [], all_path, toPrint = False) for root in all_path: for i in range(N): Player(X[i], Y[i], g.Nodes, g, W, H) main = Main(g.Nodes,g,W,H) for path in (root): main.move(g,path) main.destroy(g) if(SearchWeight(g) == True): if main.cost < min: min = main.cost break print(str(min)) test8() ``` No
96,892
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of W × H squares. Each square is identified with its column and row number, thus the square located in the x-th column and the y-th row is represented as (x, y). The left-most square in the top row is (0, 0) and the right-most square in the bottom row is (W-1, H-1). Bob moves a character "BomBom" to clear the game. BomBom is initially located at (0, 0). The game is won if Bob successfully destroys all the enemy characters on the board by manipulating BomBom cleverly. The enemy characters are fixed on specific squares, and Bob can manipulate BomBom using the following two operations any number of times. * One-square movement in the up, down, left, or right direction within the board * Using a bomb, eliminate all the enemy characters that are located in the same column and row as that of BomBom BomBom consumes a Cost when it moves from one square to another. BomBom can use a bomb any number of times without consuming a Cost. Use of a bomb has no effect on BomBom’s behavior and it can move even to a square where an enemy character is located. Given the board size and enemy information, make a program to evaluate the minimum Cost BomBom consumes before it destroys all enemy characters. Input The input is given in the following format. W H N x_1 y_1 x_2 y_2 : x_N y_N The first line provides the number of squares in the horizontal direction W (1 ≤ W ≤ 105), in the vertical direction H (1 ≤ H ≤ 105), and the number of enemy characters N (1 ≤ N ≤ 105). Each of the subsequent N lines provides location information of the i-th enemy, column x_i (0 ≤ x_i ≤ W-1) and row y_i (0 ≤ y_i ≤ H-1). The number of enemy characters in a specific square can be either one or zero. Output Output the minimum Cost in a line. Examples Input 5 4 4 0 3 1 1 2 2 2 3 Output 2 Input 6 6 5 2 1 5 2 3 3 1 4 1 5 Output 4 Input 8 8 4 6 0 7 0 0 6 0 7 Output 0 Submitted Solution: ``` w, h, n = map(int, input().split()) a = [] for _ in range(n): a.append(tuple(map(int, input().split()))) mins = min(w, h) i = 0 while i < mins: mins = min(mins, i + max((j[0] > i) * j[1] for j in a)) i += 1 print(mins) ``` No
96,893
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of W × H squares. Each square is identified with its column and row number, thus the square located in the x-th column and the y-th row is represented as (x, y). The left-most square in the top row is (0, 0) and the right-most square in the bottom row is (W-1, H-1). Bob moves a character "BomBom" to clear the game. BomBom is initially located at (0, 0). The game is won if Bob successfully destroys all the enemy characters on the board by manipulating BomBom cleverly. The enemy characters are fixed on specific squares, and Bob can manipulate BomBom using the following two operations any number of times. * One-square movement in the up, down, left, or right direction within the board * Using a bomb, eliminate all the enemy characters that are located in the same column and row as that of BomBom BomBom consumes a Cost when it moves from one square to another. BomBom can use a bomb any number of times without consuming a Cost. Use of a bomb has no effect on BomBom’s behavior and it can move even to a square where an enemy character is located. Given the board size and enemy information, make a program to evaluate the minimum Cost BomBom consumes before it destroys all enemy characters. Input The input is given in the following format. W H N x_1 y_1 x_2 y_2 : x_N y_N The first line provides the number of squares in the horizontal direction W (1 ≤ W ≤ 105), in the vertical direction H (1 ≤ H ≤ 105), and the number of enemy characters N (1 ≤ N ≤ 105). Each of the subsequent N lines provides location information of the i-th enemy, column x_i (0 ≤ x_i ≤ W-1) and row y_i (0 ≤ y_i ≤ H-1). The number of enemy characters in a specific square can be either one or zero. Output Output the minimum Cost in a line. Examples Input 5 4 4 0 3 1 1 2 2 2 3 Output 2 Input 6 6 5 2 1 5 2 3 3 1 4 1 5 Output 4 Input 8 8 4 6 0 7 0 0 6 0 7 Output 0 Submitted Solution: ``` class Node(object):#Nodeを扱うクラス def __init__(self, name): self.name = name def getName(self):#Nodeの名前を返す return self.name def __str__(self): return self.name class Node_W(Node):#重さ付きNodeを扱うクラス def __init__(self, name): self.name = name self.w = 0 def addWeight(self,weight): self.w += weight class Edge(object):#エッジを扱うクラス def __init__(self, src, dest): self.src = src self.dest = dest def getSource(self):#親Nodeを返す return self.src def getDestination(self):#子Nodeを返す return self.dest def __str__(self): return self.src + "->" + self.dest class Graph(object): def __init__(self): self.Nodes = []#グラフ上のNode self.Edges = {}#グラフ上のエッジ親Nodeのキーに対して子Nodeのリストを返す def addNode(self, node):#グラフにNodeを加える if(node in self.Nodes): raise ValueError("そのNodeはもうあるよ") else: self.Nodes.append(node) self.Edges[node] = []#nodeの子Nodeのリスト def addEdges(self, edge):#グラフ上にエッジを加える src = edge.getSource() dest = edge.getDestination() if src not in self.Nodes or dest not in self.Nodes: raise ValueError("そのNodeはグラフ上にありません") else: self.Edges[src].append(dest) def getChildList(self,node):#nodeの子Nodeのリストを返す return self.Edges[node] def put_player(self, x, y, W, H, L):#x, yはplayerの座標, W, Hはx, y座標の限界,Lは受け取ったNode_W型を含むリスト k = W - H index = (H*y) + x + k*y if index >= H*W: raise ValueError("そんな座標はないよ") else: L[index].w = 1 def __str__(self): s = "" for src in self.Nodes: for dest in self.Edges[src]: s = s + src.getNode() + "->" + dest.getNode() + '\n' return s def ShowPath(path):#pathはNode_W型からなるリスト s = "" for nextNode in range(len(path)): s = s + path[nextNode].getName() + "(" + str(path[nextNode].w) + ")" if nextNode != len(path) - 1: s = s + "->" return s all_path1 = []#すべての経路を保存する count = 0 def all_search(g, start, end, path, all_path, toPrint = True):#グラフ上の全経路を保存する path = path + [start] if toPrint == True: ShowPath(path) all_path.append(path) for child in g.getChildList(start): if child not in path:#ループはしない newpath = all_search(g,child,end,path,all_path,toPrint = True) def make_field(W,H): #W,Hはint型 k = 0 if (W < H): k = W - H elif(W > H): k = W - H Nodes= [] #pointの要素数分だけNode_Wを作りリストに保存する for i in range(0,W * H,1): Nodes.append(Node_W(str(i))) g = Graph() for i in range(0,W*H, 1):#グラフ上にNodesで作ったNodeを追加する g.addNode(Nodes[i]) for i in range(H): for w in range(W): num = (H*i) + w + k * i if(i != H - 1):#この時は下につなげるNodeがある g.addEdges(Edge(Nodes[num],Nodes[num + W])) if(w != W - 1):#この時は横につなげるNodeがある g.addEdges(Edge(Nodes[num], Nodes[num + 1])) return g class Player(object): def __init__(self, x, y, L,g,W,H):#x,yはplayerを配置する座標, LはNode_W型を含むリスト,gはplayerを配置するField,W,Xはx座標y座標の限界 g.put_player(x,y,W,H,L) class Main(Player): def __init__(self,L,g,W,H): g.put_player(0,0,W,H,L) self.cost = 0 self.now_position = 0 self.W = W self.H = H self.L = L def move(self,g, node):#gはgraph型,nodeはNode型,与えられたNodeへ進む g.Nodes[self.now_position].w = 0 self.now_position = int(node.getName()) g.Nodes[self.now_position].w = 0 if(int(node.getName()) == 0): self.cost += 0 #0番に移動する場合はコスト0 else: self.cost += 1 def destroy(self, g): h1 = self.H h2 = self.H mod = self.now_position % self.W i = 1 j = 1 k = self.W - self.H g.Nodes[self.now_position].w = 0 while(self.now_position - h1 >= 0):#現在位置の上の敵を消す g.Nodes[self.now_position - h1].w = 0 h1 += self.H - k while(self.now_position + h2 < self.H * self.W):#現在位置の下の敵を消す g.Nodes[self.now_position + h2].w = 0 h2 += self.H + k while((self.now_position - i) % self.W != self.W - 1 and self.now_position - i < self.H * self.W and self.now_position - i > 0):#現在位置の左の敵を消す g.Nodes[self.now_position - i].w = 0 i += 1 while((self.now_position + j) % self.W != 0 and self.now_position + j < self.H * self.W and self.now_position + j > 0):#現在位置の右の敵を消す g.Nodes[self.now_position + j].w = 0 j += 1 def ShowGraph(g,H,W):#gはgraph型 result = "" k = W - H for h in range(H): for w in range(W): result = result + g.Nodes[(H * h) + w + k*h].getName() + "(" + str(g.Nodes[(H*h) + w + k * h].w) + ")" if(w != W - 1): result = result + "->" else: result = result + '\n' if (h != H -1): for w in range(W): t = int(g.Nodes[(H*h) + w + k * h].getName()) s = 0 while(t//10 != 0): s += 1 t /= 10 result = result + "↓" + " " + " "*s s = 0 if(w == W - 1): result = result + '\n' return result def SearchWeight(g):#gはgraph型,graph上のNodeがすべて0ならTrue,それ以外ならFalseを返す for i in range(len(g.Nodes)): if g.Nodes[i].w == 1: return False return True def test1():#グラフが正常につくられているかテスト g = make_field(6,6) start = g.Nodes[0] end = g.Nodes[6*6 - 1] all_path = [] all_search(g, start, end, [], all_path,toPrint = True ) main = Player(0,0,g.Nodes,g,6,6) enemy1 = Player(1,1,g.Nodes,g, 6,6) enemy2 = Player(5,5,g.Nodes,g, 6,6) for i in range(len(all_path)): print(ShowPath(all_path[i])) print(str(i)) def test2():#正常に爆破ができるのかを確かめるテスト W, H = map(int, input().split()) g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] main = Main(g.Nodes,g,W,H) N = int(input()) for i in range(N): x, y = map(int, input().split()) Player(x, y, g.Nodes,g,W,H) all_search(g,start, end, [], all_path, toPrint = True) print(ShowGraph(g, H, W)) main.move(g,g.Nodes[6]) main.destroy(g) print("爆破!") print(ShowGraph(g,H,W)) def test3():#グラフ上のある経路を正常に動くのかテスト W, H = map(int, input().split()) g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] main = Main(g.Nodes,g,W,H) N = int(input()) for i in range(N): x, y = map(int, input().split()) Player(x, y, g.Nodes,g,W,H) all_search(g,start, end, [], all_path, toPrint = True) print(ShowPath(all_path[4])) print()#改行 print(ShowGraph(g, H, W)) print()#改行 for path in (all_path[4]): main.move(g,path) print(str(path.getName())+"番に移動しました!") print()#改行 print(ShowGraph(g, H, W)) print() print("現在までのコスト :",str(main.cost)) print()#改行 for i in range(len(all_path)): print(ShowPath(all_path[i])) print(str(i)) def test4():#1つの経路で動くたびに爆発できるのかテスト W, H = map(int, input().split()) g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] main = Main(g.Nodes,g,W,H) N = int(input()) for i in range(N): x, y = map(int, input().split()) Player(x, y, g.Nodes,g,W,H) all_search(g,start, end, [], all_path, toPrint = True) print(ShowPath(all_path[4])) print()#改行 print(ShowGraph(g, H, W)) print()#改行 for path in (all_path[4]): main.move(g,path) print(str(path.getName())+"番に移動しました!") print()#改行 print(ShowGraph(g, H, W)) main.destroy(g) print("爆破しました!") print(ShowGraph(g, H, W)) print() print("現在までのコスト :",str(main.cost)) print()#改行 def test5():#全経路に関して爆発を試す W, H = map(int, input().split()) X = [] Y = [] g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] N = int(input()) for i in range(N): x, y = map(int, input().split()) X.append(x) Y.append(y) all_search(g,start, end, [], all_path, toPrint = True) print()#改行 print(ShowGraph(g, H, W)) print()#改行 for root in all_path: for i in range(N): Player(X[i], Y[i], g.Nodes, g, W, H) main = Main(g.Nodes,g,W,H) for path in (root): print(ShowPath(root)) main.move(g,path) print(str(path.getName())+"番に移動しました!") print()#改行 print(ShowGraph(g, H, W)) main.destroy(g) print("爆破しました!") print(ShowGraph(g, H, W)) if(SearchWeight(g) == True): print("全滅や!") else: print("まだ敵がおるで!") print() print("現在までのコスト :",str(main.cost)) print()#改行 def test6():#全経路に関して爆発を試す W, H = map(int, input().split()) X = [] Y = [] min = H*W #最小のコストを保存 g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] N = int(input()) for i in range(N): x, y = map(int, input().split()) X.append(x) Y.append(y) all_search(g,start, end, [], all_path, toPrint = True) print()#改行 print(ShowGraph(g, H, W)) print()#改行 for root in all_path: for i in range(N): Player(X[i], Y[i], g.Nodes, g, W, H) main = Main(g.Nodes,g,W,H) for path in (root): print(ShowPath(root)) main.move(g,path) print(str(path.getName())+"番に移動しました!") print()#改行 print(ShowGraph(g, H, W)) main.destroy(g) print("爆破しました!") print(ShowGraph(g, H, W)) if(SearchWeight(g) == True): print("全滅や!") if main.cost < min: min = main.cost break else: print("まだ敵がおるで!") print() print("現在までのコスト :",str(main.cost)) print()#改行 print("現在の最小コスト :",str(min)) def test7(): W, H, N = map(int, input().split()) X = [] Y = [] l = 0 min = H*W #最小のコストを保存 g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] for i in range(N): x, y = map(int, input().split()) X.append(x) Y.append(y) all_search(g,start, end, [], all_path, toPrint = False) for root in all_path: for i in range(N): Player(X[i], Y[i], g.Nodes, g, W, H) main = Main(g.Nodes,g,W,H) for path in (root): main.move(g,path) main.destroy(g) if(SearchWeight(g) == True): if main.cost < min: min = main.cost l = root break print(str(min)) print(ShowPath(l)) for i in range(N): Player(X[i], Y[i], g.Nodes, g, W, H) main = Main(g.Nodes, g, W, H) for path in (root): print(ShowPath(root)) main.move(g,path) print(str(path.getName())+"番に移動しました!") print()#改行 print(ShowGraph(g, H, W)) main.destroy(g) print("爆破しました!") print(ShowGraph(g, H, W)) if(SearchWeight(g) == True): print("全滅や!") break else: print("まだ敵がおるで!") print() print("現在までのコスト :",str(main.cost)) print()#改行 def test8(): W, H, N = map(int, input().split()) X = [] Y = [] min = H*W #最小のコストを保存 g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] for i in range(N): x, y = map(int, input().split()) X.append(x) Y.append(y) all_search(g,start, end, [], all_path, toPrint = False) for root in all_path: for i in range(N): Player(X[i], Y[i], g.Nodes, g, W, H) main = Main(g.Nodes,g,W,H) for path in (root): main.move(g,path) main.destroy(g) if(SearchWeight(g) == True): if main.cost < min: min = main.cost break print(str(min)) test8() ``` No
96,894
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of W × H squares. Each square is identified with its column and row number, thus the square located in the x-th column and the y-th row is represented as (x, y). The left-most square in the top row is (0, 0) and the right-most square in the bottom row is (W-1, H-1). Bob moves a character "BomBom" to clear the game. BomBom is initially located at (0, 0). The game is won if Bob successfully destroys all the enemy characters on the board by manipulating BomBom cleverly. The enemy characters are fixed on specific squares, and Bob can manipulate BomBom using the following two operations any number of times. * One-square movement in the up, down, left, or right direction within the board * Using a bomb, eliminate all the enemy characters that are located in the same column and row as that of BomBom BomBom consumes a Cost when it moves from one square to another. BomBom can use a bomb any number of times without consuming a Cost. Use of a bomb has no effect on BomBom’s behavior and it can move even to a square where an enemy character is located. Given the board size and enemy information, make a program to evaluate the minimum Cost BomBom consumes before it destroys all enemy characters. Input The input is given in the following format. W H N x_1 y_1 x_2 y_2 : x_N y_N The first line provides the number of squares in the horizontal direction W (1 ≤ W ≤ 105), in the vertical direction H (1 ≤ H ≤ 105), and the number of enemy characters N (1 ≤ N ≤ 105). Each of the subsequent N lines provides location information of the i-th enemy, column x_i (0 ≤ x_i ≤ W-1) and row y_i (0 ≤ y_i ≤ H-1). The number of enemy characters in a specific square can be either one or zero. Output Output the minimum Cost in a line. Examples Input 5 4 4 0 3 1 1 2 2 2 3 Output 2 Input 6 6 5 2 1 5 2 3 3 1 4 1 5 Output 4 Input 8 8 4 6 0 7 0 0 6 0 7 Output 0 Submitted Solution: ``` class Node(object):#Nodeを扱うクラス def __init__(self, name): self.name = name def getName(self):#Nodeの名前を返す return self.name def __str__(self): return self.name class Node_W(Node):#重さ付きNodeを扱うクラス def __init__(self, name): self.name = name self.w = 0 def addWeight(self,weight): self.w += weight class Edge(object):#エッジを扱うクラス def __init__(self, src, dest): self.src = src self.dest = dest def getSource(self):#親Nodeを返す return self.src def getDestination(self):#子Nodeを返す return self.dest def __str__(self): return self.src + "->" + self.dest class Graph(object): def __init__(self): self.Nodes = []#グラフ上のNode self.Edges = {}#グラフ上のエッジ親Nodeのキーに対して子Nodeのリストを返す def addNode(self, node):#グラフにNodeを加える if(node in self.Nodes): raise ValueError("そのNodeはもうあるよ") else: self.Nodes.append(node) self.Edges[node] = []#nodeの子Nodeのリスト def addEdges(self, edge):#グラフ上にエッジを加える src = edge.getSource() dest = edge.getDestination() if src not in self.Nodes or dest not in self.Nodes: raise ValueError("そのNodeはグラフ上にありません") else: self.Edges[src].append(dest) def getChildList(self,node):#nodeの子Nodeのリストを返す return self.Edges[node] def put_player(self, x, y, W, H, L):#x, yはplayerの座標, W, Hはx, y座標の限界,Lは受け取ったNode_W型を含むリスト index = (H*y) + x if index >= H*W: raise ValueError("そんな座標はないよ") else: L[index].w = 1 def __str__(self): s = "" for src in self.Nodes: for dest in self.Edges[src]: s = s + src.getNode() + "->" + dest.getNode() + '\n' return s def ShowPath(path):#pathはNode_W型からなるリスト s = "" for nextNode in range(len(path)): s = s + path[nextNode].getName() + "(" + str(path[nextNode].w) + ")" if nextNode != len(path) - 1: s = s + "->" return s all_path1 = []#すべての経路を保存する count = 0 def all_search(g, start, end, path, all_path, toPrint = True):#グラフ上の全経路を保存する path = path + [start] if toPrint == True: ShowPath(path) all_path.append(path) for child in g.getChildList(start): if child not in path:#ループはしない newpath = all_search(g,child,end,path,all_path,toPrint = True) def make_field(W,H): #W,Hはint型 point = [[0 for i in range(H)] for j in range(W)] for x in range(W): for y in range(H): point[x][y] = 0 Nodes= [] #pointの要素数分だけNode_Wを作りリストに保存する for i in range(0,W * H,1): Nodes.append(Node_W(str(i))) g = Graph() for i in range(0,W*H, 1):#グラフ上にNodesで作ったNodeを追加する g.addNode(Nodes[i]) for i in range(H): for w in range(W): num = (H*i) + w if(i != H - 1):#この時は下につなげるNodeがある g.addEdges(Edge(Nodes[num],Nodes[num + W])) if(w != W - 1):#この時は横につなげるNodeがある g.addEdges(Edge(Nodes[num], Nodes[num + 1])) return g class Player(object): def __init__(self, x, y, L,g,W,H):#x,yはplayerを配置する座標, LはNode_W型を含むリスト,gはplayerを配置するField,W,Xはx座標y座標の限界 g.put_player(x,y,W,H,L) class Main(Player): def __init__(self,L,g,W,H): g.put_player(0,0,W,H,L) self.cost = 0 self.now_position = 0 self.W = W self.H = H self.L = L def move(self,g, node):#gはgraph型,nodeはNode型,与えられたNodeへ進む g.Nodes[self.now_position].w = 0 self.now_position = int(node.getName()) g.Nodes[self.now_position].w = 1 if(int(node.getName()) == 0): self.cost += 0 #0番に移動する場合はコスト0 else: self.cost += 1 def destroy(self, g): h1 = self.H h2 = self.H mod = self.now_position % self.W i = 1 j = 1 g.Nodes[self.now_position].w = 0 while(self.now_position - h1 >= 0):#現在位置の上の敵を消す g.Nodes[self.now_position - h1].w = 0 h1 += self.H while(self.now_position + h2 < self.H * self.W):#現在位置の下の敵を消す g.Nodes[self.now_position + h2].w = 0 h2 += self.H while((self.now_position - i) % self.W != self.W - 1 and self.now_position - i < self.H * self.W):#現在位置の左の敵を消す g.Nodes[self.now_position - i].w = 0 i += 1 while((self.now_position + j) % self.W != 0 and self.now_position + j < self.H * self.W):#現在位置の右の敵を消す g.Nodes[self.now_position + j].w = 0 j += 1 def ShowGraph(g,H,W):#gはgraph型 result = "" for h in range(H): for w in range(W): result = result + g.Nodes[(H * h) + w].getName() + "(" + str(g.Nodes[(H*h) + w].w) + ")" if(w != W - 1): result = result + "->" else: result = result + '\n' if (h != H -1): for w in range(W): k = int(g.Nodes[(H*h) + w].getName()) s = 0 while(k//10 != 0): s += 1 k /= 10 result = result + "↓" + " " + " "*s s = 0 if(w == W - 1): result = result + '\n' return result def SearchWeight(g):#gはgraph型,graph上のNodeがすべて0ならTrue,それ以外ならFalseを返す for i in range(len(g.Nodes)): if g.Nodes[i].w == 1: return False return True def test7(): W, H, N = map(int, input().split()) X = [] Y = [] min = H*W #最小のコストを保存 g = make_field(W, H) all_path = [] start = g.Nodes[0] end = g.Nodes[W*H - 1] for i in range(N): x, y = map(int, input().split()) X.append(x) Y.append(y) all_search(g,start, end, [], all_path, toPrint = False) for root in all_path: for i in range(N): Player(X[i], Y[i], g.Nodes, g, W, H) main = Main(g.Nodes,g,W,H) for path in (root): main.move(g,path) main.destroy(g) if(SearchWeight(g) == True): if main.cost < min: min = main.cost break print(str(min)) test7() ``` No
96,895
Provide a correct Python 3 solution for this coding contest problem. JOI has a stove in your room. JOI himself is resistant to the cold, so he doesn't need to put on the stove when he is alone in the room, but he needs to put on the stove when there are visitors. On this day, there are N guests under JOI. The ith (1 \ leq i \ leq N) visitor arrives at time T_i and leaves at time T_i + 1. There can never be more than one visitor at the same time. JOI can turn the stove on and off at any time. However, each time you turn on the stove, you will consume one match. JOI has only K matches, so he can only stove up to K times. The stove is gone at the beginning of the day. When the stove is on, fuel is consumed by that amount, so I want to set the time when the stove is on and off and minimize the total time when the stove is on. Example Input 3 2 1 3 6 Output 4 "Correct Solution: ``` n,k=map(int,input().split()) guest=[] interval=[] flag=0 for i in range(n): guest.append(int(input())) if flag==1: interval.append(guest[-1]-guest[-2]-1) flag=1 interval.sort() ans=n if n>k: for i in range(n-k): ans+=interval[i] print(ans) ```
96,896
Provide a correct Python 3 solution for this coding contest problem. JOI has a stove in your room. JOI himself is resistant to the cold, so he doesn't need to put on the stove when he is alone in the room, but he needs to put on the stove when there are visitors. On this day, there are N guests under JOI. The ith (1 \ leq i \ leq N) visitor arrives at time T_i and leaves at time T_i + 1. There can never be more than one visitor at the same time. JOI can turn the stove on and off at any time. However, each time you turn on the stove, you will consume one match. JOI has only K matches, so he can only stove up to K times. The stove is gone at the beginning of the day. When the stove is on, fuel is consumed by that amount, so I want to set the time when the stove is on and off and minimize the total time when the stove is on. Example Input 3 2 1 3 6 Output 4 "Correct Solution: ``` #!/usr/bin/python3 import os import sys def main(): N, K = read_ints() T = [read_int() for _ in range(N)] print(solve(N, K, T)) def solve(N, K, T): diffs = [T[i + 1] - T[i] for i in range(N - 1)] diffs.sort() t = N for i in range(N - K): t += diffs[i] - 1 return t ############################################################################### DEBUG = 'DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return [int(e) for e in inp().split()] def dprint(*value, sep=' ', end='\n'): if DEBUG: print(*value, sep=sep, end=end) if __name__ == '__main__': main() ```
96,897
Provide a correct Python 3 solution for this coding contest problem. JOI has a stove in your room. JOI himself is resistant to the cold, so he doesn't need to put on the stove when he is alone in the room, but he needs to put on the stove when there are visitors. On this day, there are N guests under JOI. The ith (1 \ leq i \ leq N) visitor arrives at time T_i and leaves at time T_i + 1. There can never be more than one visitor at the same time. JOI can turn the stove on and off at any time. However, each time you turn on the stove, you will consume one match. JOI has only K matches, so he can only stove up to K times. The stove is gone at the beginning of the day. When the stove is on, fuel is consumed by that amount, so I want to set the time when the stove is on and off and minimize the total time when the stove is on. Example Input 3 2 1 3 6 Output 4 "Correct Solution: ``` from bisect import bisect N, K, *T = map(int, open(0).read().split()) S = [(T[i+1] - T[i])-1 for i in range(N-1)] S.sort(reverse=1) print((T[-1] - T[0] + 1) - sum(S[:K-1])) ```
96,898
Provide a correct Python 3 solution for this coding contest problem. JOI has a stove in your room. JOI himself is resistant to the cold, so he doesn't need to put on the stove when he is alone in the room, but he needs to put on the stove when there are visitors. On this day, there are N guests under JOI. The ith (1 \ leq i \ leq N) visitor arrives at time T_i and leaves at time T_i + 1. There can never be more than one visitor at the same time. JOI can turn the stove on and off at any time. However, each time you turn on the stove, you will consume one match. JOI has only K matches, so he can only stove up to K times. The stove is gone at the beginning of the day. When the stove is on, fuel is consumed by that amount, so I want to set the time when the stove is on and off and minimize the total time when the stove is on. Example Input 3 2 1 3 6 Output 4 "Correct Solution: ``` n, k = map(int, input().split()) diff = [] ti = int(input()) + 1 for _ in range(n - 1): ti1 = int(input()) diff.append(ti1 - ti) ti = ti1 + 1 if n <= k: print(n) else: diff.sort() print(n + sum(diff[:n - k])) ```
96,899