output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the number of different kinds of colors of the paint cans. * * *
s198894864
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
a,b,c = map(int.input().split()) if a=b=c: print(1) elif (a=b or b=c or a=c): print(2) else: print(3)
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s207895275
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
cols = map( int, input().split() ) cols set = set( cols ) print( len( cols set ) )
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s386071531
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
a,b,c = int(input().split()) if a=b=c: print(1) elif (a=b or b=c or a=c): print(2) else: print(3)
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s303029683
Wrong Answer
p03962
The input is given from Standard Input in the following format: a b c
i = list(map(int, input().split())) i.sort() a = 0 for k in range(len(i)): if i[k] != i[k - 1]: a += 1 print(a)
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s717435309
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
cols = list( int, input().split() ) num col = cols.unique(); print( num col )
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s163426428
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
a,b.c=map(int,input().split()) L=[a,b,c] L.sort() if L[0]==L[2]: print(1) elif L[0]<L[1]<L[2]: print(3) else: print(2)
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s586022005
Accepted
p03962
The input is given from Standard Input in the following format: a b c
A = sorted(list(map(int, input().split()))) print(4 - A.count(A[1]))
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s335590784
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
a = list(map(int, input().split()) a = list(set(a)) print(len(a))
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s063257187
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
a,b,c = map(int,input().split()) print(len(set{a,b,c}))
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s957183008
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
a=list(map(int,input().split()) return len(set(a))
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s005250152
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
abc = list(map(int, input().split())) print(len(set(abc))
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s302132476
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
int(input(a, b, c)) set(pennki) = (a, b, c) len(set(pennki))
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s692922268
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
n, c = list(map(int, input().split())) print(c * ((c - 1) ** (n - 1)))
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s295198000
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
a = int(input().split()) print(len(list(set(a)))
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
Print the number of different kinds of colors of the paint cans. * * *
s934756180
Runtime Error
p03962
The input is given from Standard Input in the following format: a b c
a = [int(i) for i in input().split()] print(len(set(a))
Statement AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
[{"input": "3 1 4", "output": "3\n \n\nThree different colors: 1, 3, and 4.\n\n* * *"}, {"input": "3 3 33", "output": "2\n \n\nTwo different colors: 3 and 33."}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s830518682
Accepted
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
# coding: utf-8 import sys from collections import deque sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def main(): N = ir() P = lr() P = [((p - 1) // N, (p - 1) % N) for p in P] dp = [[min(i, N - 1 - i, j, N - 1 - j) for j in range(N)] for i in range(N)] people = [[True] * N for i in range(N)] answer = 0 for i, j in P: answer += dp[i][j] people[i][j] = False que = deque([(i, j, dp[i][j])]) popleft = que.popleft append = que.append while que: y, x, cur = popleft() cur += people[y][x] if x > 0: if dp[y][x - 1] > cur: dp[y][x - 1] = cur append((y, x - 1, cur)) if x < N - 1: if dp[y][x + 1] > cur: dp[y][x + 1] = cur append((y, x + 1, cur)) if y > 0: if dp[y - 1][x] > cur: dp[y - 1][x] = cur append((y - 1, x, cur)) if y < N - 1: if dp[y + 1][x] > cur: dp[y + 1][x] = cur append((y + 1, x, cur)) print(answer) if __name__ == "__main__": main()
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s914719850
Wrong Answer
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
# -*- coding: utf-8 -*- import sys buff_readline = sys.stdin.buffer.readline def read_int(): return tuple(buff_readline()) def read_int_n(): return tuple(map(int, buff_readline().split())) def slv(N, P): M = N + 2 cost = [0] * M**2 occupy = [True] * M**2 for i in range(N): im = i * (M + 1) for j in range(N): cost[im + j + 1] = min(i, j, N - i - 1, N - j - 1) ds = [-1, 1, -M, M] ans = 0 for p in P: p -= 1 x = p // N y = p % N p = x * M + y + M + 1 ans += cost[p] occupy[p] = False s = [p] while s: pi = s.pop() for d in ds: ni = pi + d nc = cost[pi] + (1 if occupy[pi] else 0) if nc < cost[ni]: s.append(ni) cost[ni] = nc return ans def main(): # N = read_int() # P = read_int_n() # print(slv(N, P)) import random N = 500 P = list(range(1, N**2 + 1)) random.shuffle(P) print(slv(N, P)) if __name__ == "__main__": main()
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s157645620
Runtime Error
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
#!/usr/bin/env python3 n = int(input()) numbers = input().split(" ") r = 0 p = [] hate = [-1] * (n * n) is_seated = [1] * (n * n) def is_area(x, y): if x >= 0 and x < n and y >= 0 and y < n: return True else: return False def rewrite(x, y): global hate global is_seated global n # print("b") # print(x, y) index = (x) * n + (y) # if hate[index] == -1: # print("error") # print(x, y) # print("-------") points = [[x - 1, y - 1], [x - 1, y + 1], [x + 1, y - 1], [x + 1, y + 1]] flag = 0 for point in points: if is_area(point[0], point[1]): new_index = point[0] * n + point[1] if ( hate[new_index] == -1 or hate[new_index] > is_seated[index] + hate[index] ): hate[new_index] = is_seated[index] + hate[index] rewrite(point[0], point[1]) else: flag += 1 if flag == 4: return for x in numbers: p.append(int(x)) for i in range(n): hate[i] = 0 hate[n * n - n + i] = 0 hate[i * n] = 0 hate[i * n + n - 1] = 0 for k in p: for i in range(n): for j in range(n): # if hate[i * n + j] == -1: # print("error") rewrite(i, j) r += hate[k - 1] is_seated[k - 1] = 0 # for i in range(n): # for j in range(n): # print(hate[i * n + j], end = "") # print() print(r)
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s473374676
Wrong Answer
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
import sys from collections import deque # from numba import jit input_methods = ["clipboard", "file", "key"] using_method = 0 input_method = input_methods[using_method] tin = lambda: map(int, input().split()) lin = lambda: list(map(int, input().split())) mod = 1000000007 # +++++ # @jit def gg(nn, x, y, n, is_sit, cc, av): q = deque() q.append(1000 * x + y) while q: v = q.popleft() x, y = v // 1000, v % 1000 nn[x][y] -= 1 k = nn[x][y] cc[x][y] = av for dx, dy in ([-1, 0], [0, -1], [1, 0], [0, 1]): if x + dx < 0 or x + dx >= n or y + dy < 0 or y + dy >= n: continue if nn[x + dx][y + dy] <= k + is_sit[x + dx][y + dy]: continue if cc[x + dx][y + dy] == av: continue q.append((x + dx) * 1000 + (y + dy)) cc[x + dx][y + dy] = av # print('yyyyyy') # for l,ll in zip(nn,cc): # print(l,ll) def main(): n = int(input()) nn = [[(n + 1) // 2] * n for _ in range(n)] is_sit = [[1] * n for _ in range(n)] cc = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): nn[i][j] = min(i + 1, j + 1, n - i, n - j) # for l in nn: # print(l) # b , c = tin() pl = lin() ans = 0 for i, p in enumerate(pl): x, y = (p - 1) // n, (p - 1) % n ans += nn[x][y] - 1 is_sit[x][y] = 0 gg(nn, x, y, n, is_sit, cc, i) print(ans) # s = input() # +++++ isTest = False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text = clipboard.get() input_l = input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform == "ios": if input_method == input_methods[0]: ic = input_clipboard() input = lambda: ic.__next__() elif input_method == input_methods[1]: sys.stdin = open("inputFile.txt") else: pass isTest = True else: pass input = sys.stdin.readline ret = main() if ret is not None: print(ret)
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s951859370
Wrong Answer
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
from collections import defaultdict from collections import deque import math N = int(input()) P = list(map(int, input().split())) map = [] for i in range(N): map.append([]) for j in range(N): map[i].append(True) def check(x, y): distance = defaultdict(lambda: defaultdict(lambda: 500)) stack = deque() stack.append([x, y]) distance[x][y] = 0 min_d = 500 while len(stack) != 0: x_y = stack.popleft() new_x = x_y[0] new_y = x_y[1] distance_xy = distance[new_x][new_y] if distance_xy < min_d and ( new_x == 0 or new_y == 0 or new_x == N - 1 or new_y == N - 1 ): min_d = distance_xy if x <= new_x: if new_x + 1 < N: if distance[new_x + 1][new_y] == 500: stack.append([new_x + 1, new_y]) next_d = distance_xy if map[new_x + 1][new_y]: next_d += 1 if next_d < distance[new_x + 1][new_y]: distance[new_x + 1][new_y] = next_d if x >= new_x: if 0 <= new_x - 1: if distance[new_x - 1][new_y] == 500: stack.append([new_x - 1, new_y]) next_d = distance_xy if map[new_x - 1][new_y]: next_d += 1 if next_d < distance[new_x - 1][new_y]: distance[new_x - 1][new_y] = next_d if y <= new_y: if new_y + 1 < N: if distance[new_x][new_y + 1] == 500: stack.append([new_x, new_y + 1]) next_d = distance_xy if map[new_x][new_y + 1]: next_d += 1 if next_d < distance[new_x][new_y + 1]: distance[new_x][new_y + 1] = next_d if y >= new_y: if 0 <= new_y - 1: if distance[new_x][new_y - 1] == 500: stack.append([new_x, new_y - 1]) next_d = distance_xy if map[new_x][new_y - 1]: next_d += 1 if next_d < distance[new_x][new_y - 1]: distance[new_x][new_y - 1] = next_d return min_d result = 0 for p in P: px = (p - 1) % N py = math.floor((p - 1) / N) result += check(px, py) map[px][py] = False print(result)
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s208779743
Wrong Answer
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
# -*- coding: utf-8 -*- import sys from collections import deque sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() YesNo = lambda b: bool([print("Yes")] if b else print("No")) YESNO = lambda b: bool([print("YES")] if b else print("NO")) int1 = lambda x: int(x) - 1 def main(): N = int(input()) P = tuple(map(int1, input().split())) c = [[1] * N for _ in range(N)] ans = 0 dy, dx = [1, 0, -1, 0], [0, 1, 0, -1] class UnionFind: def __init__(self, n): self.par = [i for i in range(n)] self.siz = [1] * n def root(self, x): while self.par[x] != x: self.par[x] = self.par[self.par[x]] x = self.par[x] return x def unite(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False if self.siz[x] < self.siz[y]: x, y = y, x self.siz[x] += self.siz[y] self.par[y] = x return True def is_same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return self.siz[self.root(x)] u = UnionFind(N**2) dist = [INF] * (N**2) for p in P: que = deque([(p // N, p % N)]) d = [[INF] * N for _ in range(N)] d[p // N][p % N] = 0 f = True f2 = False MAX = INF while que and f: y, x = que.popleft() if f2 and d[y][x] >= MAX: tmp = MAX break for k in range(4): ny, nx = (y + dy[k], x + dx[k]) if 0 <= ny < N and 0 <= nx < N: if d[ny][nx] == INF: if c[ny][nx] == 1: d[ny][nx] = d[y][x] + 1 que.append((ny, nx)) else: MAX = min(MAX, d[y][x] + dist[u.root(ny * N + nx)]) f2 = True else: tmp = d[y][x] f = False break ans += tmp dist[u.root(p)] = tmp y, x = p // N, p % N for k in range(4): ny, nx = (y + dy[k], x + dx[k]) if 0 <= ny < N and 0 <= nx < N and c[ny][nx] == 0: res0 = u.root(p) res1 = u.root(ny * N + nx) u.unite(p, ny * N + nx) dist[u.root(p)] = min(dist[res0], dist[res1]) c[p // N][p % N] = 0 print(ans) if __name__ == "__main__": main()
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s350772673
Wrong Answer
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
N = int(input()) P = list(map(int, input().split())) import heapq def dijkstra_heap(s): # 始点sから各頂点への最短距離 d = [float("inf")] * (N**2) used = [True] * (N**2) # True:未確定 d[s] = 0 used[s] = False edgelist = [] for e in edge[s]: heapq.heappush(edgelist, e) while len(edgelist): minedge = heapq.heappop(edgelist) # まだ使われてない頂点の中から最小の距離のものを探す if not used[minedge[1]]: continue v = minedge[1] d[v] = minedge[0] used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist, [e[0] + d[v], e[1]]) return d edge = [[] for i in range(N**2)] for i in range(N): for j in range(N): x = i * N + j if (i == 0) or (i == N - 1) or (j == 0) or (j == N - 1): edge[x].append([0, 0]) edge[0].append([0, x]) continue if j != 0: edge[x].append([1, x - 1]) edge[x - 1].append([1, x]) if j != N - 1: edge[x].append([1, x + 1]) edge[x + 1].append([1, x]) if i != 0: edge[x].append([1, x - N]) edge[x - N].append([1, x]) if i != N - 1: edge[x].append([1, x + N]) edge[x + N].append([1, x]) ans = 0 for p in P: x = p - 1 a = x // N b = x % N ans += dijkstra_heap(0)[x] if b != 0: edge[x].append([0, x - 1]) edge[x - 1].append([0, x]) if b != N - 1: edge[x].append([0, x + 1]) edge[x + 1].append([0, x]) if a != 0: edge[x].append([0, x - N]) edge[x - N].append([0, x]) if a != N - 1: edge[x].append([0, x + N]) edge[x + N].append([0, x]) print(ans)
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s046203264
Runtime Error
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
import sys def _i(): return int(sys.stdin.readline().strip()) def _ia(): return map(int, sys.stdin.readline().strip().split()) def update(n, cost, flag, idx, ci): # left if idx % n != 0: idx_ = idx - 1 if cost[idx_] > ci: cost[idx_] = ci update(n, cost, flag, idx_, ci + flag[idx_]) # right idx_ = idx + 1 if idx_ % n != 0: if cost[idx_] > ci: cost[idx_] = ci update(n, cost, flag, idx_, ci + flag[idx_]) # front idx_ = idx - n if idx_ >= 0: if cost[idx_] > ci: cost[idx_] = ci update(n, cost, flag, idx_, ci + flag[idx_]) # back idx_ = idx + n if idx_ // n < n: if cost[idx_] > ci: cost[idx_] = ci update(n, cost, flag, idx_, ci + flag[idx_]) def main(): n = _i() p = list(map(lambda x: int(x) - 1, _ia())) cost = [min(i // n, i % n, n - 1 - (i % n), n - 1 - i // n) for i in range(n**2)] flag = [1] * n**2 tot = 0 for pi in p: flag[pi] = 0 ci = cost[pi] tot += ci update(n, cost, flag, pi, ci) return tot if __name__ == "__main__": print(main())
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s416057536
Accepted
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
N, *P = map(int, open(0).read().split()) dp = [0] + [min(i, j, N - 1 - i, N - 1 - j) for i in range(N) for j in range(N)] memo = [1] * (N * N + 1) def move(fr, to): if dp[to] > dp[fr] + memo[fr]: dp[to] = dp[fr] + memo[fr] S.append(to) ans = 0 for p in P: ans += dp[p] memo[p] = 0 S = [p] while S: v = S.pop() q, r = divmod(v - 1, N) if r != 0: move(v, v - 1) if r != N - 1: move(v, v + 1) if q < N - 1: move(v, v + N) if q >= 1: move(v, v - N) print(ans)
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s106751814
Wrong Answer
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
print(3 | 6)
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s632439649
Wrong Answer
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
print("軽い気持ちで参加してごめんなさい")
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s627387074
Wrong Answer
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
print(1)
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s282905810
Wrong Answer
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
N = int(input()) P = input().split() M = [[1] * N for i in range(N)] Hate = 0 for ij in range(N**2): j = (int(P[ij]) - 1) % N i = (int(P[ij]) - 1) // N K1 = 0 K2 = 0 K3 = 0 K4 = 0 M[i][j] = 0 for k in range(0, i): if M[k][j] == 1: K1 += 1 for k in range(i, N): if M[k][j] == 1: K2 += 1 for k in range(0, j): if M[i][k] == 1: K3 += 1 for k in range(j, N): if M[i][k] == 1: K4 += 1 Hate += min(K1, K2, K3, K4) print(Hate)
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s791566630
Wrong Answer
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
from collections import deque def main(): n = int(input()) p = list(map(int, input().split())) for i in range(len(p)): p[i] -= 1 to_outsides = [[0 for _ in range(n)] for _ in range(n)] not_exist = [["■" for _ in range(n)] for _ in range(n)] for i in range(n): for j in range(n): to_outside = [i, n - 1 - i, j, n - 1 - j] to_outsides[i][j] = min(to_outside) directions = [[-1, 0], [1, 0], [0, -1], [0, 1]] answer = 0 for i, person in enumerate(p): exited = [person // n, person % n] answer += to_outsides[exited[0]][exited[1]] not_exist[exited[0]][exited[1]] = "□" seen = deque() seen.append([exited[0], exited[1]]) todo = deque([exited]) renews = [] while len(todo) > 0: now = todo.pop() renews.append(now) for direction in directions: try: checking = [now[0] + direction[0], now[1] + direction[1]] to_outsides[checking[0]][checking[1]] except: continue if [checking[0], checking[1]] not in seen: if ( not_exist[checking[0]][checking[1]] == "□" and to_outsides[checking[0]][checking[1]] == to_outsides[now[0]][now[1]] ) or to_outsides[checking[0]][checking[1]] > to_outsides[now[0]][ now[1] ]: todo.append([checking[0], checking[1]]) seen.append([checking[0], checking[1]]) else: seen.append([checking[0], checking[1]]) for renew in renews: if to_outsides[renew[0]][renew[1]] != 0: to_outsides[renew[0]][renew[1]] -= 1 print(answer) main()
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s778147169
Wrong Answer
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
from collections import deque N = int(input()) offset = 0 field = N people = [[1 for _ in range(field)] for _ in range(field)] HL = [0] * N HR = [0] * N Hcnt = 0 for P in input().split(): visited = [[600 for _ in range(field)] for _ in range(field)] seen = [[0 for _ in range(field)] for _ in range(field)] nowx = (int(P) - 1) // N nowy = (int(P) - 1) % N todo = deque() todo.append((nowx, nowy)) mv = [(0, 1), (1, 0), (-1, 0), (0, -1)] seen[nowx][nowy] += 1 people[nowx][nowy] = 0 visited[nowx][nowy] = 0 flag = False while len(todo) > 0: nowx, nowy = todo.popleft() for i in range(len(mv)): dx, dy = mv[i] nx = nowx + dx ny = nowy + dy if nx >= N or nx < 0 or ny >= N or ny < 0: continue if visited[nx][ny] > visited[nowx][nowy] + people[nx][ny]: visited[nx][ny] = visited[nowx][nowy] + people[nx][ny] seen[nx][ny] += 1 if seen[nx][ny] > 3: continue todo.append((nx, ny)) if flag: break for n in range(N): HL[n] = visited[n][0] HR[n] = visited[n][N - 1] Hcnt += min(min(visited[0]), min(visited[N - 1]), min(HL), min(HR)) print(Hcnt)
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
If ans is the number of pairs of viewers described in the statement, you should print on Standard Output ans * * *
s990379507
Wrong Answer
p02670
The input is given from Standard Input in the format N P_1 P_2 \cdots P_{N^2}
def chk_1st_row(p_l, N): if p_l <= N: return True else: return False def chk_last_row(p_l, N): if N**2 - N + 1 <= p_l: return True else: return False def chk_isle(p_l, N): if p_l % N == 0 or p_l % N == 1: return True else: return False def chk_right(p_l, p, N): # print(p_l, ',', N * (p_l // N + 1)) for i in range(p_l + 1, N * (p_l // N + 1) + 1): if i in p: return True return False def chk_left(p_l, p, N): # print(p_l, N * (p_l // N)) for i in range(N * (p_l // N) + 1, p_l): if i in p: return True return False def chk_front(p_l, p, N): while p_l > 0: p_l -= N if p_l in p: return True break return False def chk_rear(p_l, p, N): while p_l < N**2: p_l += N if p_l in p: return True break return False N = int(input()) count = 0 in_theater = [] for i in range(1, N**2 + 1): in_theater.append(i) p = list(map(int, input().split())) # print(p) for i in range(N**2): p_l = p[0] p.remove(p[0]) if chk_1st_row(p_l, N): continue elif chk_last_row(p_l, N): continue elif chk_isle(p_l, N): continue elif not (chk_right(p_l, p, N)): continue elif not (chk_left(p_l, p, N)): continue elif not (chk_front(p_l, p, N)): continue elif not (chk_rear(p_l, p, N)): continue count += 1 # print(p_l, count) print(count)
Statement Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2. At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat **currently** occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever. Compute the number of pairs of viewers (x, y) such that y will hate x forever.
[{"input": "3\n 1 3 7 9 5 4 8 6 2", "output": "1\n \n\nBefore the end of the movie, the viewers are arranged in the cinema as\nfollows:\n\n \n \n 1 2 3\n 4 5 6\n 7 8 9\n \n\nThe first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema\nwithout going through any seat, so they will not be hated by anybody.\n\nThen, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are\ncurrently seated while leaving the cinema; hence he will be hated by at least\none of those viewers.\n\nFinally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2)\nwithout going through any occupied seat (actually, they can leave the cinema\nwithout going through any seat at all).\n\n* * *"}, {"input": "4\n 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8", "output": "3\n \n\n* * *"}, {"input": "6\n 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30", "output": "11"}]
Print the possible ways Ringo could have thrown in K balls, modulo 998244353. * * *
s202745414
Wrong Answer
p03431
Input is given from Standard Input in the following format: N K
m = 998244353 def c(n, r): return (g[n] * h[r] * h[n - r]) % m g = [1, 1] h = g[:] v = [0, 1] for i in range(2, 999999): g.append((g[-1] * i) % m) v.append((-v[m % i] * (m // i)) % m) h.append((h[-1] * v[i]) % m) N, K = map(int, input().split()) P = 0 for k in range(N - 1, K): P += c(K - 1, k) print(P)
Statement In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage. A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules: * A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten. * A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten. Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times: * Grab either a red ball or a blue ball. * Throw that ball into the cage. Then, one of the chameleons eats it. After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
[{"input": "2 4", "output": "7\n \n\nWe will use `R` to represent a red ball, and `B` to represent a blue ball.\nThere are seven ways to throw in balls that satisfy the condition: `BRRR`,\n`RBRB`, `RBRR`, `RRBB`, `RRBR`, `RRRB` and `RRRR`.\n\n* * *"}, {"input": "3 7", "output": "57\n \n\n* * *"}, {"input": "8 3", "output": "0\n \n\n* * *"}, {"input": "8 10", "output": "46\n \n\n* * *"}, {"input": "123456 234567", "output": "857617983"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s320299860
Accepted
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
# AtCoder Beginner Contest 075 # B - Minesweeper # https://atcoder.jp/contests/abc075/tasks/abc075_b H, W, *S = open(0).read().split() H, W = int(H), int(W) S = [tuple(s) for s in S] ans = [[0] * W for _ in [0] * H] dirs = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] for y, _s in enumerate(S): for x, s in enumerate(_s): if s == "#": ans[y][x] = "#" for dy, dx in dirs: if 0 <= x + dx < W and 0 <= y + dy < H and S[y + dy][x + dx] != "#": ans[y + dy][x + dx] += 1 for a in ans: print("".join(map(str, a)))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s604547859
Accepted
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
def read_input(): h, w = map(int, input().split()) slist = [] for i in range(h): slist.append(input().strip()) return h, w, slist # i, jの周辺に1を足す def sumup(board, i, j): def notbomb(x): return x != "#" up = i - 1 >= 0 down = i + 1 < len(board) left = j - 1 >= 0 right = j + 1 < len(board[0]) if up: if notbomb(board[i - 1][j]): board[i - 1][j] += 1 if left: if notbomb(board[i - 1][j - 1]): board[i - 1][j - 1] += 1 if right: if notbomb(board[i - 1][j + 1]): board[i - 1][j + 1] += 1 if left: if notbomb(board[i][j - 1]): board[i][j - 1] += 1 if right: if notbomb(board[i][j + 1]): board[i][j + 1] += 1 if down: if notbomb(board[i + 1][j]): board[i + 1][j] += 1 if left: if notbomb(board[i + 1][j - 1]): board[i + 1][j - 1] += 1 if right: if notbomb(board[i + 1][j + 1]): board[i + 1][j + 1] += 1 return board def submit(): h, w, slist = read_input() board = [] for s in slist: board.append([0 if c == "." else c for c in s]) for i in range(h): for j in range(w): if board[i][j] == "#": board = sumup(board, i, j) for row in board: print("".join([str(c) for c in row])) if __name__ == "__main__": submit()
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s940115479
Wrong Answer
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
g, r = map(int, input().split()) A = ["." * (r + 2)] for i in range(g): w = "." + input() + "." A.append(w) A.append("." * (r + 2)) print(A) for i in range(1, g + 1): for j in range(1, r + 1): if A[i][j] == ".": B = [] for m in [i - 1, i, i + 1]: for k in [j - 1, j, j + 1]: B.append(A[m][k]) print(B) print(B.count("#")) A[i] = A[i][1 : r + 1 :].replace(".", str(B.count("#")), 1) A[i] = "." + A[i] + "." for i in range(1, g + 1): print(A[i][1 : r + 1 :])
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s684594618
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
H, W = map(int, input().split()) S = [list(input()) for i in range(H)] for i in range(1, H - 1): for j in range(1, W - 1): if S[i][j] == ".": x = [ S[i - 1][j - 1], S[i - 1][j], S[i - 1][j + 1], S[i][j - 1], S[i][j + 1], S[i + 1][j - 1], S[i + 1][j], S[i + 1][j + 1], ] S[i][j] = x.count("#") for j in range(1, W - 1): if S[0][j] == ".": x = [S[0][j - 1], S[0][j + 1], S[1][j - 1], S[1][j], S[1][j + 1]] S[0][j] = x.count("#") if S[H - 1][j] == ".": x = [ S[H - 1][j - 1], S[H - 1][j + 1], S[H - 2][j - 1], S[H - 2][j], S[H - 2][j + 1], ] S[H - 1][j] = x.count("#") for i in range(1, H - 1): if S[i][0] == ".": x = [S[i - 1][0], S[i - 1][1], S[i][1], S[i + 1][0], S[i + 1][1]] S[i][0] = x.count("#") if S[i][W - 1] == ".": x = [ S[i - 1][W - 1], S[i - 1][W - 2], S[i][W - 2], S[i + 1][W - 1], S[i + 1][W - 2], ] S[i][W - 1] = x.count("#") if S[0][0] == ".": x = [S[0][1], S[1][0], S[1][1]] S[0][0] = x.count("#") if S[H - 1][0] == ".": x = [S[H - 1][1], S[H - 2][0], S[H - 2][1]] S[H - 1][0] = x.count("#") if S[0][W - 1] == ".": x = [S[0][W - 2], S[1][W - 1], S[1][W - 2]] S[0][W - 1] = x.count("#") if S[H - 1][W - 1] == ".": x = [S[H - 1][W - 2], S[H - 2][W - 1], S[H - 2][W - 2]] S[H - 1][W - 1] = x.count("#") for i in range(len(S)): S[i] = [str(x) for x in S[i]] print("".join(S[i]))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s805350284
Wrong Answer
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
def check_current_posi(s_i_list, h, w): _height = len(s_i_list) _width = len(s_i_list[0]) if h == -1 or w == -1 or h >= _height or w >= _width: return False else: if s_i_list[h][w] == "#": # bomb return True else: # not bomb return False # hとwは0から def check_around_bomb_num(s_i_list, h, w): check_posi_h = h - 1 check_posi_w = w - 1 bomb_counter = 0 for i in range(3): for j in range(3): if check_current_posi(s_i_list, check_posi_h, check_posi_w): bomb_counter += 1 check_posi_w += 1 check_posi_h += 1 check_posi_w = w - 1 return bomb_counter # _input = [6, 6] _input = list(map(int, input().split(" "))) height = _input[0] width = _input[1] s_i_list = [] for i in range(height): _input_row = list(input()) s_i_list.append(_input_row) # s_i_list = [['#', '#', '#', '#', '#', '.'], ['#', '.', '#', '.', '#', '#'], ['#', '#', '#', '#', '.', '#'], ['.', '#', '.', '.', '#', '.'], ['#', '.', '#', '#', '.', '.'], ['#', '.', '#', '.', '.', '.']] for row in range(height): for column in range(width): if s_i_list[row][column] == "#": continue s_i_list[row][column] = check_around_bomb_num(s_i_list, row, column) print(s_i_list)
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s386386991
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
h,w = map(int, input().split()) s = [list(input()) for _ in range(h)] ans = [[0]*w for _ in range(h)] for i in range(h): for j in range(w): if s[i][j] == "#": ans[i][j] = "#" for i2 in range(i-1, i+2): if i2 < 0 or h-1 < i2: continue for j2 in range(j-1, j+2): if (j2 < 0 or w-1 < j2): continue elif ans[i2][j2] == "#": continue ans[i2][j2] += 1 for i in ans: print("".join(map(str,i)))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s879382201
Accepted
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
li = [] a, b = map(int, input().split()) for i in range(a): li.append(list(input())) for i in range(a): for j in range(b): if li[i][j] == ".": li[i][j] = 0 if i != 0 and li[i - 1][j] == "#": li[i][j] += 1 if i != a - 1 and li[i + 1][j] == "#": li[i][j] += 1 if j != 0 and li[i][j - 1] == "#": li[i][j] += 1 if j != b - 1 and li[i][j + 1] == "#": li[i][j] += 1 if i != 0 and j != 0 and li[i - 1][j - 1] == "#": li[i][j] += 1 if i != a - 1 and j != 0 and li[i + 1][j - 1] == "#": li[i][j] += 1 if i != 0 and j != b - 1 and li[i - 1][j + 1] == "#": li[i][j] += 1 if i != a - 1 and j != b - 1 and li[i + 1][j + 1] == "#": li[i][j] += 1 print(li[i][j], end="") print()
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s471897635
Accepted
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
H, W = [int(i) for i in input().split(" ")] S = [input() for i in range(H)] for k, v in enumerate(S): for kk, vv in enumerate(list(v)): checkTarget = [] if vv == "#": print("#", end="") else: if H == 1 and W == 1: print("0", end="") break if k == 0 and kk == 0: checkTarget = [S[k][kk + 1], S[k + 1][kk], S[k + 1][kk + 1]] elif k == 0 and kk > 0 and kk < len(v) - 1 and H == 1: checkTarget = [ S[k][kk - 1], S[k][kk + 1], ] elif k == 0 and kk > 0 and kk < len(v) - 1: checkTarget = [ S[k][kk - 1], S[k][kk + 1], S[k + 1][kk - 1], S[k + 1][kk], S[k + 1][kk + 1], ] elif k == 0 and kk == len(v) - 1 and H == 1: checkTarget = [ S[k][kk - 1], ] elif k == 0 and kk == len(v) - 1: checkTarget = [S[k][kk - 1], S[k + 1][kk - 1], S[k + 1][kk]] elif k > 0 and k < len(S) - 1 and kk == 0 and W == 1: checkTarget = [S[k - 1][kk], S[k + 1][kk]] elif k > 0 and k < len(S) - 1 and kk == 0: checkTarget = [ S[k - 1][kk], S[k - 1][kk + 1], S[k][kk + 1], S[k + 1][kk], S[k + 1][kk + 1], ] elif k > 0 and k < len(S) - 1 and kk == len(v) - 1: checkTarget = [ S[k - 1][kk - 1], S[k - 1][kk], S[k][kk - 1], S[k + 1][kk - 1], S[k + 1][kk], ] elif k == len(S) - 1 and kk == 0 and W == 1: checkTarget = [S[k - 1][kk]] elif k == len(S) - 1 and kk == 0: checkTarget = [S[k - 1][kk], S[k - 1][kk + 1], S[k][kk + 1]] elif k == len(S) - 1 and kk > 0 and kk < len(v) - 1: checkTarget = [ S[k - 1][kk - 1], S[k - 1][kk], S[k - 1][kk + 1], S[k][kk - 1], S[k][kk + 1], ] elif k == len(S) - 1 and kk == len(v) - 1: checkTarget = [S[k - 1][kk - 1], S[k - 1][kk], S[k][kk - 1]] else: checkTarget = [ S[k - 1][kk - 1], S[k - 1][kk], S[k - 1][kk + 1], S[k][kk - 1], S[k][kk + 1], S[k + 1][kk - 1], S[k + 1][kk], S[k + 1][kk + 1], ] print(len([i for i in checkTarget if i == "#"]), end="") print("", end="\n" if k != len(S) - 1 else "")
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s360117403
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
x = input().split() h = int(x[0]) w = int(x[1]) inp = [0] * h * w for i in range(h): x = input() y = 0 r = i * w for j in x: if j == "#": inp[r + y] = "#" if r + y == 0: if inp[r + y + 1] != "#": inp[r + y + 1] += 1 if inp[r + y + w] != "#": inp[r + y + w] += 1 if inp[r + y + w + 1] != "#": inp[r + y + w + 1] += 1 elif r + y == w - 1: if inp[w - 2] != "#": inp[w - 2] += 1 if inp[w - 1 + w] != "#": inp[w - 1 + w] += 1 if inp[w - 2 + w] != "#": inp[w - 2 + w] += 1 elif r + y == (h - 1) * w: if inp[r + y - w] != "#": inp[r + y - w] += 1 if inp[r + y - w + 1] != "#": inp[r + y - w + 1] += 1 if inp[r + y + 1] != "#": inp[r + y + 1] += 1 elif r + y == h * w - 1: if inp[r + y - 1] != "#": inp[r + y - 1] += 1 if inp[r + y - w - 1] != "#": inp[r + y - w - 1] += 1 if inp[r + y - w] != "#": inp[r + y - w] += 1 elif r + y < w - 1: if inp[r + y - 1] != "#": inp[r + y - 1] += 1 if inp[r + y + 1] != "#": inp[r + y + 1] += 1 if inp[r + y + w] != "#": inp[r + y + w] += 1 if inp[r + y + w - 1] != "#": inp[r + y + w - 1] += 1 if inp[r + y + w + 1] != "#": inp[r + y + w + 1] += 1 elif (r + y) % w == 0: if inp[r + y - w] != "#": inp[r + y - w] += 1 if inp[r + y + 1] != "#": inp[r + y + 1] += 1 if inp[r + y + w] != "#": inp[r + y + w] += 1 if inp[r + y - w + 1] != "#": inp[r + y - w + 1] += 1 if inp[r + y + w + 1] != "#": inp[r + y + w + 1] += 1 elif (r + y) % w == w - 1: if inp[r + y - 1] != "#": inp[r + y - 1] += 1 if inp[r + y - w] != "#": inp[r + y - w] += 1 if inp[r + y + w] != "#": inp[r + y + w] += 1 if inp[r + y + w - 1] != "#": inp[r + y + w - 1] += 1 if inp[r + y - w - 1] != "#": inp[r + y - w - 1] += 1 elif r + y > (h - 1) * w: if inp[r + y - 1] != "#": inp[r + y - 1] += 1 if inp[r + y + 1] != "#": inp[r + y + 1] += 1 if inp[r + y - w] != "#": inp[r + y - w] += 1 if inp[r + y - w - 1] != "#": inp[r + y - w - 1] += 1 if inp[r + y - w + 1] != "#": inp[r + y - w + 1] += 1 else: if inp[r + y - 1] != "#": inp[r + y - 1] += 1 if inp[r + y + 1] != "#": inp[r + y + 1] += 1 if inp[r + y + w] != "#": inp[r + y + w] += 1 if inp[r + y + w - 1] != "#": inp[r + y + w - 1] += 1 if inp[r + y + w + 1] != "#": inp[r + y + w + 1] += 1 if inp[r + y - w] != "#": inp[r + y - w] += 1 if inp[r + y - w + 1] != "#": inp[r + y - w + 1] += 1 if inp[r + y - w - 1] != "#": inp[r + y - w - 1] += 1 y += 1 ans = "" for i in range(h): for j in range(w): ans += str(inp[i * w + j]) print(ans) ans = ""
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s558858965
Wrong Answer
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
import sys if sys.platform == "ios": sys.stdin = open("input.txt") h, w = [int(x) for x in input().split()] board = [input() for _ in range(h)] mines = ["" for _ in range(h)] print(board) for row in range(h): for col in range(w): if board[row][col] != "#": counts = 0 dx = [x for x in range(-1, 2) if (col + x >= 0 and col + x < w)] dy = [y for y in range(-1, 2) if (row + y >= 0 and row + y < h)] # print('row:{}, col:{}, dx:{}, dy:{}'.format(row,col,dx,dy)) for x in dx: for y in dy: # print('row+y:{}, col+x:{}'.format(row+y, col+x)) if board[row + y][col + x] == "#": counts += 1 mines[row] += str(counts) else: mines[row] += "#" for mine in mines: print(mine)
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s259808537
Accepted
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
a, b = map(int, input().split()) c = [] for i in range(a): c.append(list(input().replace(".", "0"))) for i in range(a): for j in range(b): if c[i][j] == "#": for x in range(i - 1, i + 2): for y in range(j - 1, j + 2): if 0 <= x <= a - 1 and 0 <= y <= b - 1 and c[x][y] != "#": c[x][y] = str(int(c[x][y]) + 1) for i in range(a): print("".join(c[i]))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s651390911
Accepted
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
import sys sys.setrecursionlimit(200000) def input(): return sys.stdin.readline()[:-1] def ii(t: type = int): return t(input()) def il(t: type = int): return list(map(t, input().split())) def imi(N: int, t: type = int): return [ii(t) for _ in range(N)] def iml(N: int, t: type = int): return [il(t) for _ in range(N)] class UnionFind: def __init__(self, n): self.par = [i for i in range(n)] self.rank = [0] * (n) # 検索 def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] # 併合 def union(self, x, y): x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 同じ集合に属するか判定 def same_check(self, x, y): return self.find(x) == self.find(y) def solve(): H, W = il() S = imi(H, str) from itertools import product dst = ((i, j) for i, j in product(range(-1, 2), repeat=2)) dst = list(dst) B = [[0] * W for _ in range(H)] sharp_pos = [] for i, j in product(range(H), range(W)): if S[i][j] == "#": B[i][j] = "#" sharp_pos.append((i, j)) for i, j in sharp_pos: for d in dst: x = i + d[1] y = j + d[0] if 0 <= x < H and 0 <= y < W: if S[i][j] == "#" and S[x][y] == ".": B[x][y] += 1 for b in B: print("".join(map(str, b))) if __name__ == "__main__": solve()
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s113240789
Wrong Answer
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
H, W = map(int, input().split()) Ws = W + 2 Hs = H + 2 root = [[0] * Ws for i in range(Hs)] c = 0 for i in range(H): I = "" I = input() print(I) for j in range(W): print("youso is ", I[j]) k = I[j] root[i + 1][j + 1] = k root2 = [[0] * W for i in range(H)] for i in range(H): for j in range(W): if root[i + 1][j + 1] == ".": c = 0 if root[i + 1 + 1][j + 1 + 1] == "#": c += 1 if root[i + 1 + 1][j + 1] == "#": c += 1 if root[i + 1 + 1][j - 1 + 1] == "#": c += 1 if root[i + 1 - 1][j + 1 + 1] == "#": c += 1 if root[i + 1 - 1][j + 1] == "#": c += 1 if root[i + 1 - 1][j - 1 + 1] == "#": c += 1 if root[i + 1 + 1][j + 1 + 1] == "#": c += 1 if root[i + 1 + 1][j + 1 - 1] == "#": c += 1 root2[i][j] = c else: root2[i][j] = "#" for i in range(H): print(root[H])
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s059787465
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
Y_DIR[-1,0,1] X_DIR[-1,0,1] def count_bomb(y,x): cnt=0 for yd in Y_DIR: yy=y+yd if not (0<=yy<h): continue for xd in X_DIR: xx=x+xd if not (0<=xx<w): continue if s[yy][xx]=="#": cnt+=1 return cnt h,w=map(int,input().split()) s=[] for i in range(h): s.append(input()) for y in range(h): for x in range(w) if s[y][x] == ".": s[y][x]=str(count_bomb(y,x)) print("\n".join(s))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s772279123
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
H, W = map(int, input().split()) S = [list(input()) for _ in range(H)] dydx = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] def check(h, w): count = 0 for dy, dx in dydx: if 0 <= h + dy < H and 0 <= w + dx < W and S[h+dy][w+dx] == '#': count += 1 return count for h in range(H): for w in range(W): if S[h][w] == '.': S[h][w] = check(h, w) print("".join(S[h])
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s192632888
Wrong Answer
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
h, w = map(int, input().split()) S = [] for i in range(h): S.append(list(input())) if h == 1 and w == 1: print(S[0][0]) if h == 1 and w == 2: if S == [[".", "#"]]: print("1#") if S == [["#", "#"]]: print("##") if S == [["#", "."]]: print("#1") if S == [[".", "."]]: print("..") if h == 1 and w >= 3: for g in range(w): if S[0][0] == ".": if S[0][1] == "#": S[0][0] = "1" if 1 <= g <= w - 2: if S[0][g] == ".": S[0][g] = str(S[0][g - 1 : g + 2].count("#")) if S[0][w - 1] == ".": if S[0][w - 2] == "#": S[0][w - 1] = "1" print("".join(S[0])) if h >= 3 and w == 1: for y in range(h): if S[0][0] == ".": if S[1][0] == "#": S[0][0] = "1" if 1 <= y <= h - 2: if S[y][0] == ".": count = 0 if S[y - 1][0] == "#": count += 1 if S[y + 1][0] == "#": count += 1 S[y][0] = int(count) if S[h - 1][0] == ".": if S[h - 2][0] == "#": S[h - 1][0] = "1" for p in S: print(p[0]) if h == 2 and w == 1: if S == [["."], ["."]]: print(".") print(".") if S == [["#"], ["."]]: print("#") print("1") if S == [["."], ["#"]]: print("1") print("#") if S == [["#"], ["#"]]: print("#") print("#") if h >= 2 and w >= 2: for k in range(h): for j in range(w): if S[k][j] == ".": if k == 0 and j == 0: count = 0 if S[0][1] == "#": count += 1 count += S[1][0:2].count("#") S[k][j] = str(count) elif k == 0 and 1 <= j <= w - 2: count = 0 count += S[0][j - 1 : j + 2].count("#") count += S[1][j - 1 : j + 2].count("#") S[k][j] = str(count) elif k == 0 and j == w - 1: count = 0 if S[0][j - 1] == "#": count += 1 count += S[1][j - 1 :].count("#") S[k][j] = str(count) elif 1 <= k <= h - 2 and j == 0: count = 0 count += S[k - 1][0:2].count("#") if S[k][1] == "#": count += 1 count += S[k + 1][0:2].count("#") S[k][j] = str(count) elif 1 <= k <= h - 2 and 1 <= j <= w - 2: count = 0 count += S[k - 1][j - 1 : j + 2].count("#") count += S[k][j - 1 : j + 2].count("#") count += S[k + 1][j - 1 : j + 2].count("#") S[k][j] = str(count) elif 1 <= k <= h - 2 and j == w - 1: count = 0 count += S[k - 1][j - 1 :].count("#") count += S[k][j - 1 :].count("#") count += S[k + 1][j - 1 :].count("#") S[k][j] = str(count) elif k == h - 1 and j == 0: count = 0 count += S[k - 1][0:2].count("#") count += S[k][1].count("#") S[k][j] = str(count) elif k == h - 1 and 1 <= j <= w - 2: count = 0 count += S[k - 1][j - 1 : j + 2].count("#") count += S[k][j - 1 : j + 2].count("#") S[k][j] = str(count) elif k == h - 1 and j == w - 1: count = 0 count += S[k - 1][j - 1 :].count("#") count += S[k][j - 1 :].count("#") S[k][j] = str(count) for p in S: print("".join(p))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s945524297
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
# 全日本汚いコード選手権Pythonの部 H, W = map(int, input().split()) S = [] for i in range(H): S.append(list(input())) L = [[0 for w in range(W)] for h in range(H)] if S[0][1] == "#": L[0][0] += 1 if S[1][0] == "#": L[0][0] += 1 if S[1][1] == "#": L[0][0] += 1 if S[H - 1][1] == "#": L[H - 1][0] += 1 if S[H - 2][0] == "#": L[H - 1][0] += 1 if S[H - 2][1] == "#": L[H - 1][0] += 1 if S[0][W - 2] == "#": L[0][W - 1] += 1 if S[1][W - 1] == "#": L[0][W - 1] += 1 if S[1][W - 2] == "#": L[0][W - 1] += 1 if S[H - 1][W - 2] == "#": L[H - 1][W - 1] += 1 if S[H - 2][W - 1] == "#": L[H - 1][W - 1] += 1 if S[H - 2][W - 2] == "#": L[H - 1][W - 1] += 1 for w in range(1, W - 1): if S[0][w - 1] == "#": L[0][w] += 1 if S[0][w + 1] == "#": L[0][w] += 1 if S[1][w - 1] == "#": L[0][w] += 1 if S[1][w] == "#": L[0][w] += 1 if S[1][w + 1] == "#": L[0][w] += 1 if S[H - 1][w - 1] == "#": L[H - 1][w] += 1 if S[H - 1][w + 1] == "#": L[H - 1][w] += 1 if S[H - 2][w - 1] == "#": L[H - 1][w] += 1 if S[H - 2][w] == "#": L[H - 1][w] += 1 if S[H - 2][w + 1] == "#": L[H - 1][w] += 1 for h in range(1, H - 1): if S[h - 1][0] == "#": L[h][0] += 1 if S[h + 1][0] == "#": L[h][0] += 1 if S[h - 1][1] == "#": L[h][0] += 1 if S[h][1] == "#": L[h][0] += 1 if S[h + 1][1] == "#": L[h][0] += 1 if S[h - 1][W - 1] == "#": L[h][W - 1] += 1 if S[h + 1][W - 1] == "#": L[h][W - 1] += 1 if S[h - 1][W - 2] == "#": L[h][W - 1] += 1 if S[h][W - 2] == "#": L[h][W - 1] += 1 if S[h + 1][W - 2] == "#": L[h][W - 1] += 1 for w in range(1, W - 1): for h in range(1, H - 1): if S[h - 1][w - 1] == "#": L[h][w] += 1 if S[h - 1][w] == "#": L[h][w] += 1 if S[h - 1][w + 1] == "#": L[h][w] += 1 if S[h][w - 1] == "#": L[h][w] += 1 if S[h][w + 1] == "#": L[h][w] += 1 if S[h + 1][w - 1] == "#": L[h][w] += 1 if S[h + 1][w] == "#": L[h][w] += 1 if S[h + 1][w + 1] == "#": L[h][w] += 1 C = [["" for w in range(W)] for h in range(H)] for w in range(W): for h in range(H): if S[h][w] == ".": C[h][w] = str(L[h][w]) else: C[h][w] = "#" o = "" for c in C: o = "" for cc in c: o += cc print(o)
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s792176637
Wrong Answer
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
H, W = map(int, input().split(" ")) S = [] for i in range(H): S.append(list(input())) for i in range(H): for j in range(W): if S[i][j] == ".": S[i][j] = 0 if H == 1 and W == 1: print(S[0][0]) elif H == 1: if S[0][0] == "#": if S[0][1] != "#": S[0][1] += 1 if S[0][W - 1] == "#": if S[0][W - 2] != "#": S[0][W - 2] += 1 print("test") for i in range(1, H - 1): if S[0][i - 1] != "#": S[0][i - 1] += 1 if S[0][i + 1] != "#": S[0][i + 1] += 1 for i in range(H): print("".join(map(str, S[i][:]))) elif W == 1: if S[0][0] == "#": if S[1][0] != "#": S[1][0] += 1 if S[H - 1][0] == "#": if S[H - 2][0] != "#": S[H - 2][0] += 1 for i in range(1, W - 1): if S[i - 1][0] != "#": S[i - 1][0] += 1 if S[i + 1][0] != "#": S[i + 1][0] += 1 for i in range(H): print("".join(map(str, S[i][:]))) else: # 4隅の処理 if S[0][0] == "#": if S[1][0] != "#": S[1][0] += 1 if S[0][1] != "#": S[0][1] += 1 if S[1][1] != "#": S[1][1] += 1 if S[0][W - 1] == "#": if S[0][W - 2] != "#": S[0][W - 2] += 1 if S[1][W - 2] != "#": S[1][W - 2] += 1 if S[1][W - 1] != "#": S[1][W - 1] += 1 if S[H - 1][0] == "#": if S[H - 2][0] != "#": S[H - 2][0] += 1 if S[H - 1][1] != "#": S[H - 1][1] += 1 if S[H - 2][1] != "#": S[H - 2][1] += 1 if S[H - 1][W - 1] == "#": if S[H - 2][W - 1] != "#": S[H - 2][W - 1] += 1 if S[H - 2][W - 2] != "#": S[H - 2][W - 2] += 1 if S[H - 1][W - 2] != "#": S[H - 1][W - 2] += 1 # 端の処理 for i in range(1, H - 1): if S[i][0] == "#": if S[i - 1][0] != "#": S[i - 1][0] += 1 if S[i + 1][0] != "#": S[i + 1][0] += 1 if S[i][1] != "#": S[i][1] += 1 if S[i - 1][1] != "#": S[i - 1][1] += 1 if S[i + 1][1] != "#": S[i + 1][1] += 1 for i in range(1, H - 1): if S[i][W - 1] == "#": if S[i - 1][W - 1] != "#": S[i - 1][W - 1] += 1 if S[i + 1][W - 1] != "#": S[i + 1][W - 1] += 1 if S[i][W - 2] != "#": S[i][W - 2] += 1 if S[i - 1][W - 2] != "#": S[i - 1][W - 2] += 1 if S[i + 1][W - 2] != "#": S[i + 1][W - 2] += 1 for i in range(1, W - 1): if S[0][i] == "#": if S[0][i - 1] != "#": S[0][i - 1] += 1 if S[0][i + 1] != "#": S[0][i + 1] += 1 if S[1][i] != "#": S[1][i] += 1 if S[1][i - 1] != "#": S[1][i - 1] += 1 if S[1][i + 1] != "#": S[1][i + 1] += 1 for i in range(1, W - 1): if S[H - 1][i] == "#": if S[H - 1][i - 1] != "#": S[H - 1][i - 1] += 1 if S[H - 1][i + 1] != "#": S[H - 1][i + 1] += 1 if S[H - 2][i] != "#": S[H - 2][i] += 1 if S[H - 2][i - 1] != "#": S[H - 2][i - 1] += 1 if S[H - 2][i + 1] != "#": S[H - 2][i + 1] += 1 for i in range(1, H - 1): for j in range(1, W - 1): if S[i][j] == "#": if S[i - 1][j - 1] != "#": S[i - 1][j - 1] += 1 if S[i - 1][j] != "#": S[i - 1][j] += 1 if S[i - 1][j + 1] != "#": S[i - 1][j + 1] += 1 if S[i][j - 1] != "#": S[i][j - 1] += 1 if S[i][j + 1] != "#": S[i][j + 1] += 1 if S[i + 1][j - 1] != "#": S[i + 1][j - 1] += 1 if S[i + 1][j] != "#": S[i + 1][j] += 1 if S[i + 1][j + 1] != "#": S[i + 1][j + 1] += 1 for i in range(H): print("".join(map(str, S[i][:]))) # # def replace(i,j,S): # yp = i + 1 # ym = i - 1 # xp = j + 1 # xm = j - 1 # count = 0 # if ym >= 0: # if S[ym][j] == "#": # count += 1 # if S[yp][j] == "#": # count += 1 # return S # # print(S) # print(S)
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s281366188
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
H,W = map(int,input().split()) grid = [[0]*W]*H for h in range(H): row = input.split() for w,r in enumerate(row): if r == "#": if h>=1: grid[h-1][w] += 1 if w>=1: grid[h-1][w-1] += 1 if w<=W-1: grid[h-1][w+1] += 1 if h<=H-1: grid[h+1][w] += 1 if w>=1: grid[h+1][w-1] += 1 if w<=W-1: grid[h+1][w+1] += 1 if w>=1: grid[h][w-1] +=1 if w<=W-1: grid[h][w+1] +=1 grid.append([0 if v == "." else "#" for v in input().split()]) for g in grid: print("".join([str(v) for v in g])
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s580345704
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
H, W = map(int, input().split()) INPUT = [list(input()) for i in range(H)] OUTPUT = INPUT.copy() for i in range(H): for j in range(W): if INPUT[i][j] == '#': OUTPUT[i][j] = '#'a else: OUTPUT[i][j] = 0 for I in (i-1, i, i+1): if not (I < 0 or H <= I): for J in (j-1, j, j+1): if not (J < 0 or W <= J): if INPUT[I][J] == '#': OUTPUT[i][j] += 1 for i in range(H): print(''.join(map(str, OUTPUT[i])))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s658692187
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
h,w=map(int,input().split()) list2=[[0 for i in range(w)]for j in range(h)] list1 = [for _ in range(h) input().split()[] dx=[-1,-1,-1,0,0,1,1,1] dy=[-1,0,1,-1,1,-1,0,1] for j in range(h): for i in range(w): if list1[j][i]=="#": for k in range(8): xk=i+dx[k] yk=j+dy[k] if xk>=0 and xk<w and yk>=0 and yk<h: list2[yk][xk]+=1 for j in range(h): for i in range(w): if list1[j][i]=="#": list2[j][i]="#" else: list2[j][i]=str(list2[j][i]) for j in range(h): print("".join(list2[j]))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s976432193
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
h,w = map(int, input().split()) Array = [list(map(int, input().split())) for _ in range(h)] dx = [1,1,0,-1,-1,-1,0,1] dy = [0,1,1,1,0,-1,-1,-1] for i in range(h): for j in range(w): if Array[i][j]='#': continue num=0 for d in range(8): ni = i+dy[d] nj = j+dx[d] if ni<0 or h<=ni: continue if nj<0 or w<=nj: continue if Array[ni][nj]=='#': num=num+1 Array[i][j]=char(num + '0') for i in Array: print(*Array)
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s404153713
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
a, b = [int(input()) for i in range(2)] c = [str(input()) for i in range(a)] for i in range(a): c[i] = "." + c[i] + "." c = ["." * (b + 2)] + c + ["." * (b + 2)] d = [["0" for i in range(b)] for j in range(a)] for i in range(1, a + 1): for j in range(1, b + 1): f = 0 for k in range(-1, 2): for l in range(-1, 2): if c[i + k][j + l] == "#": f += 1 d[i - 1][j - 1] = str(f) for i in range(1, a + 1): for j in range(1, b + 1): if c[i][j] == "#": d[i - 1][j - 1] = "#" for i in range(a): dd = "" for j in range(b): dd += str(d[i][j]) print(dd)
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s030274912
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
3 5 ##### ##### #####h, w = map(int, input().split()) field = [["" for _ in range(w)] for _ in range(h)] for i in range(h): s = input() for j in range(w): field[i][j] = s[j] dx = [1, 1, 0, -1, -1, -1, 0, 1] dy = [0, 1, 1, 1, 0, -1, -1, -1] def numbering(x, y): if field[y][x] == ".": c = 0 for i in range(8): nx = x + dx[i] ny = y + dy[i] if 0 <= nx and nx < w and 0 <= ny and ny < h: if field[ny][nx] == "#": c += 1 field[y][x] = str(c) for X in range(w): for Y in range(h): numbering(X, Y) for Y in range(h): for X in range(w): print(field[Y][X], end = "") print()
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s116077072
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
# -*- coding:utf-8 -*- H,W=map(int,input().split()) boxes=list() boxes[0]=[0]*W boxes[H+1]=[0]*W for i in range(H): boxes[i+1]=list() boxes[i+1][0]=0 bowes[i+1][W+1]=0 x=input() for j in range(W): if x[j]=='.': boxes[i+1][j+1]=0 elif x[j]=='#': boxes[i+1][j+1]=1 answer=list() for n in range(H): answer[n]=list() for k in range(W): count=0 if boxes[n][k]==1: count+=1 if boxes[n][k+1]==1: count+=1 if boxes[n][k+2]==1: count+=1 if boxes[n+1][k]==1: count+=1 if boxes[n+1][k+2]==1: count+=1 if boxes[n+2][k]==1: count+=1 if boxes[n+2][k+1]==1: count+=1 if boxes[n+2][k+2]==1: count+=1 if count==0: answer[n][k]='#' else: answer[n][k]=str(count) for v in range(H): answe=''.join(answer[v]) print(answe)
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s587642569
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
H,W=map(int,input().split()) s=[list(input()) for i in range(H)] for i in range(H): ans=[0]*W for i in range(W): if s[i][j]=="#": ans[j]=="#" continue count=0 if i > 0: if s[i-1][j]=="#": count+=1 if j > 0: if s[i-1][j-1]=="#": count+=1 if j < W-1: if s[i-1][j+1]=5"#": count+=1 if i<H-1: if s[i+1][j]=="#": count+=1 if j >0: if s[i+1][j-1]=="#": count+=1 if j<W-1: if s[i+1][j+1]=="#": count+=1 if j>0: if s[i][j-1]==”#”: count+=1 if j<W-1: if s[i][j+1]=="#": count+=1 ans[j]=count print("".join(map(str,ans)))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s177079529
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
h,w = map(int,input().split()) Array = [list(map(int,input())) for _ in range(h)] dx = [1,1,0,-1,-1,-1,0,1] dy = [0,1,1,1,0,-1,-1,-1] for i in range(h): for j in range(w): if Array[i][j]='#': continue num=0 for d in range(8): ni = i+dy[d] nj = j+dx[d] if ni<0 or h<=ni: continue if nj<0 or w<=nj: continue if Array[ni][nj]=='#': num=num+1 Array[i][j]=char(num) for i in Array: print(i)
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s404276994
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
h,w=map(int,input().split()) mapdata=[] result=[] k=[] def get_bomb(i,j): count=0 for x in (i-1.i,i+1): for y in (j-1,j,j+1): if 0<=x<=h-1 and 0<=y<=w-1: if mapdata[x][y]=='#': count+=1 return count for i in range(h): line=list(input()) mapdata.append(line) for i in range(h): for j in range(w): if mapdata[i][j]=='.': k.append(get_bomb(i,j)) else: k.append('#') result.append(k) k=[] for i in range(len(result)): print(result[i])
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s079442397
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
a
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s973646511
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
h,w = map(int,input().split()) Array = [list(map(int,input().split())) for _ in range(h)] dx = [1,1,0,-1,-1,-1,0,1] dy = [0,1,1,1,0,-1,-1,-1] for i in range(h): for j in range(w): if Array[i][j]='#': continue num=0 for d in range(8): ni = i+dy[d] nj = j+dx[d] if ni<0 or h<=ni: continue if nj<0 or w<=nj: continue if Array[ni][nj]=='#': num=num+1 Array[i][j]=char(num) for i in Array: print(*Array)
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s963165054
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
h,w = int(input()) Array = [list(map(int, input().split())) for _ in range(h)] dx = [1,1,0,-1,-1,-1,0,1] dy = [0,1,1,1,0,-1,-1,-1] for i in range(h): for j in range(w): if Array[i][j]='#': continue num=0 for d in range(8): ni = i+dy[d] nj = j+dx[d] if ni<0 or h<=ni: continue if nj<0 or w<=nj: continue if Array[ni][nj]=='#': num=num+1 Array[i][j]=char(num + '0') for i in Array: print(*Array)
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s548545569
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
h,w = map(int,input().split()) Array = [list(map(str,input())) for _ in range(h)] dx = [1,1,0,-1,-1,-1,0,1] dy = [0,1,1,1,0,-1,-1,-1] for i in range(h): for j in range(w): if Array[i][j]='#': continue num=0 for d in range(8): ni = i+dy[d] nj = j+dx[d] if ni<0 or h<=ni: continue if nj<0 or w<=nj: continue if Array[ni][nj]=='#': num=num+1 Array[i][j]=str(num) for i in Array: print(*i)
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s778436668
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
# 入力 H,W=map(int,input().split()) l=[] for i in range(H): l.append(list(input())) for i in range(H): for j in range(W): # 地雷数のカウンタ c=0 # '#'の場合はなにもしない if l[i][j]=='#': pass # '#'以外の場合 else: # 左上 if 0<i and 0<j and l[i-1][j-1]=='#': c+=1 # 上 if 0<i and l[i-1][j]=='#': c+=1 # 右上 if 0<i and j<W-1 and l[i-1][j+1]=='#': c+=1 # 左 if 0<j and l[i][j-1]=='#': c+=1 # 右 if j<W-1 and l[i][j+1]=='#': c+=1 # 左下 if i<H-1 and 0<j and l[i+1][j-1]=='#': c+=1 # 下 if i<H-1 and l[i+1][j]=='#': c+=1 # 右下 if i<H-1 and j<W-1 and l[i+1][j+1]=='#': c+=1 # 地雷隣接数を記載 l[i][j]=str(c) # 出力 for i in range(H): print(''.join(l[i]))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s818696611
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
h = int(input()) w = int(input()) s = list(input() for i in range(1,h+1) number = [] cnt = 0 for i in range(1,h+1) : if i != 1 and i != h : for j in range(1,w+1) : if j != 1 and j != w : number = [s[i-1][j-1],s[i-1][j],s[i-1][j+1],s[i][j-1],s[i][j+1],s[i+1][j-1],s[i+1][j],s[i+1][j+1]] cnt = number.count('#') s[i][j] = cnt elif i == 1 : for j in range(1,w+1) : if j != 1 and j != w : number = [s[i-1][j-1],s[i-1][j],s[i-1][j+1],s[i][j-1],s[i][j+1],s[i+1][j-1],s[i+1][j],s[i+1][j+1]] cnt = number.count('#') s[i][j] = cnt elif j == 1 : number = [s[1][2],s[2][1],s[2][2]] cnt = number.count('#') s[1][1] = cnt elif j == w : number = [s[1][w-1],s[2][w-1],s[2][w]] cnt = number.count('#') s[1][w] = cnt elif i == h : for j in range(1,w+1) : if j == 1 : number = [s[h-1][1],s[h-1][2],s[h][2]] cnt = number.count('#') s[h][1] = cnt elif j == w : number = [s[h-1][w-1],s[h-1][w],s[h][w-1]] cnt = number.count('#') s[h][w] = cnt print(''.join(s))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s860796494
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
h,w=map(int,input().split()) s=[list(input()) for _ in range(h)] for i in range(h): for j in range(w): if i==0: if j==0 and s[0][0]=='.': l1=[s[0][1],s[1][0],s[1][1]] l1l=l1.count('#') s[0][0]=l1l elif j==w-1 and s[0][w-1]=='.': r1=[s[0][w-2],s[1][w-2],s[1][w-1]] r1r=r1.count('#') s[0][w-1]=r1r elif j!=0 and j!=w-1 and s[0][j]=='.': l1j=[s[0][j-1],s[0][j+1],[s[1][j-1],s[1][j],s[1][j+1]] l1jj=l1j.count('#') s[0][j]==l1jj else:pass elif i==h-1: if j==0 and s[h-1][0]=='.': lh=[s[h-1][1],s[h-2][0],s[h-2][1]] lhl=lh.count('#') s[h-1][0]=lhl elif j==w-1 and s[h-1][w-1]=='.': rh=[s[h-1][w-2],s[h-2][w-2],s[h-2][w-1]] rhr=rh.count('#') s[h-1][w-1]=rhr elif j!=0 and j!=w-1 and s[h-1][j]=='.': lhj=[s[h-1][j-1],s[h-1][j+1],[s[h-2][j-1],s[h-2][j],s[h-2][j+1]] lhjj=lhj.count('#') s[0][j]==lhjj else:pass else: if j==0 and s[i][0]=='.': li=[s[i-1][0],s[i-1][1],s[i][1],s[i+1][1],s[i+1][0]] lil=li.count('#') s[i][0]=lil elif j==w-1 and s[i][w-1]=='.': ri=[s[i-1][w-1],s[i-1][w-2],s[i][w-1],s[i+1][w-2],s[i+1][w-1]] rir=ri.count('#') s[i][w-1]=rir elif j!=0 and j!=w-1 and s[i][j]=='.': lij=[s[i-1][j-1],s[i-1][j],s[i-1][j+1],s[i][j-1],s[i][j+1],s[i+1][j-1],s[i+1][j],s[i+1][j+1]] lijj=lij.count('#') s[i][j]==lijj else:pass print("".join(s[i]))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s981273822
Accepted
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
H, W = map(int, input().split()) S = ["."] * (W + 2) i = 0 while i < H: S += ["."] + list(input()) + ["."] i += 1 S += ["."] * (W + 2) j = W + 3 while j <= (W + 2) * (H + 1) - 2: count = 0 if S[j] != "#": if S[j - (W + 3)] == "#": count += 1 if S[j - (W + 2)] == "#": count += 1 if S[j - (W + 1)] == "#": count += 1 if S[j - 1] == "#": count += 1 if S[j + 1] == "#": count += 1 if S[j + (W + 1)] == "#": count += 1 if S[j + (W + 2)] == "#": count += 1 if S[j + (W + 3)] == "#": count += 1 S[j] = str(count) j += 1 k = 1 while k <= H: print("".join(S[k * (W + 2) + 1 : k * (W + 2) + 1 + W])) k += 1
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). * * *
s871212800
Runtime Error
p03574
Input is given from Standard Input in the following format: H W S_1 : S_H
h, w = map(int, input().split()) s = [0] * h for i in range(h): s[i] = str(input()) t = [[0] * w] * h for j in range(h): if j == 0: for k in range(w): if k == 0: u = s[0][1] + s[1][0] + s[1][1] elif k == w - 1: u = s[0][k - 1] + s[1][k - 1] + s[1][k] else: u = s[0][k - 1] + s[0][k + 1] + s[1][k - 1] + s[1][k] + s[1][k + 1] v = u.count("#") if s[j][k] == "#": v = "#" t[j][k] = str(v) elif j == h - 1: for k in range(w): if k == 0: u = s[j][1] + s[j - 1][0] + s[j - 1][1] elif k == w - 1: u = s[j][k - 1] + s[j - 1][k - 1] + s[j - 1][k] else: u = ( s[j][k - 1] + s[j][k + 1] + s[j - 1][k - 1] + s[j - 1][k] + s[j - 1][k + 1] ) v = u.count("#") if s[j][k] == "#": v = "#" t[j][k] = str(v) else: for k in range(w): if k == 0: u = s[j][1] + s[j - 1][0] + s[j - 1][1] + s[j + 1][0] + s[j + 1][1] elif k == w - 1: u = ( s[j][k - 1] + s[j - 1][k - 1] + s[j - 1][k] + s[j + 1][k - 1] + s[j + 1][k] ) else: u = ( s[j][k - 1] + s[j][k + 1] + s[j - 1][k - 1] + s[j - 1][k] + s[j - 1][k + 1] + s[j + 1][k - 1] + s[j + 1][k] + s[j + 1][k + 1] ) v = u.count("#") if s[j][k] == "#": v = "#" t[j][k] = str(v) print("".join(t[j]))
Statement You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
[{"input": "3 5\n .....\n .#.#.\n .....", "output": "11211\n 1#2#1\n 11211\n \n\nFor example, let us observe the empty square at the first row from the top and\nfirst column from the left. \nThere is one bomb square adjacent to this empty square: the square at the\nsecond row and second column. \nThus, the `.` corresponding to this empty square is replaced with `1`.\n\n* * *"}, {"input": "3 5\n #####\n #####\n #####", "output": "#####\n #####\n #####\n \n\nIt is possible that there is no empty square.\n\n* * *"}, {"input": "6 6\n #####.\n #.#.##\n ####.#\n .#..#.\n #.##..\n #.#...", "output": "#####3\n #8#7##\n ####5#\n 4#65#2\n #5##21\n #4#310"}]
Print the maximum value taken by x during the operations. * * *
s882298998
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
N = int(input()) S = input() a = 0 sum_a = 0 for i in range(N): if S[i]=="I": sum_a += 1 a = max (a , sum_a) else: sum_a- = 1 print(a)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s846352591
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
n =int(input()) s = input() x = 0 for i in s: if i ="I": x =max(x,x+1) else: x =max(x,x-1) print(x)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s939032996
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
n = int(input()) s = input() x = 0 ans = 0 for c in s: if c=='I' x+=1 ans = max(x,ans) else: x-=1 print(ans)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s761704649
Accepted
p03827
The input is given from Standard Input in the following format: N S
import sys, collections as cl, bisect as bs sys.setrecursionlimit(100000) input = sys.stdin.readline mod = 10**9 + 7 Max = sys.maxsize def l(): # intのlist return list(map(int, input().split())) def m(): # 複数文字 return map(int, input().split()) def onem(): # Nとかの取得 return int(input()) def s(x): # 圧縮 a = [] if len(x) == 0: return [] aa = x[0] su = 1 for i in range(len(x) - 1): if aa != x[i + 1]: a.append([aa, su]) aa = x[i + 1] su = 1 else: su += 1 a.append([aa, su]) return a def jo(x): # listをスペースごとに分ける return " ".join(map(str, x)) def max2(x): # 他のときもどうように作成可能 return max(map(max, x)) def In(x, a): # aがリスト(sorted) k = bs.bisect_left(a, x) if k != len(a) and a[k] == x: return True else: return False def pow_k(x, n): ans = 1 while n: if n % 2: ans *= x x *= x n >>= 1 return ans """ def nibu(x,n,r): ll = 0 rr = r while True: mid = (ll+rr)//2 if rr == mid: return ll if (ここに評価入れる): rr = mid else: ll = mid+1 """ n = onem() po = input()[:-1] ma = 0 co = 0 for a in po: if a == "I": co += 1 else: co -= 1 ma = max(ma, co) print(ma)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s737814010
Accepted
p03827
The input is given from Standard Input in the following format: N S
from sys import stdin def fetch_one_line(): return stdin.readline().rstrip() def fetch_int_input(): return [int(s) for s in fetch_one_line().split()] def fetch_inputs(times): return [fetch_one_line() for _ in range(times)] def fetch_int_inputs(times): return [[int(s) for s in fetch_one_line()] for _ in range(times)] sum = 0 change = {"I": 1, "D": -1} length = int(fetch_one_line()) target = fetch_one_line() records = [0 for _ in range(length)] for i, t in enumerate(target): sum += change[t] records[i] = sum max_val = max(records) if max_val < 0: max_val = 0 print(max_val)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s909984386
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
N = int(input()) S = input() x = 0 max = 0 for i in range(N): if S[i] == ‘I’: x += 1 else: x -= 1 if x > max: max = x print(max)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s892194336
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
n = int(input()) s = input() ans = 0 cur = 0 for c in s: if c == 'I': cur += 1 ans = max(ans, cur) else: cur -= 1 print(ans)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s887194392
Accepted
p03827
The input is given from Standard Input in the following format: N S
# -*- coding: utf-8 -*- import sys from collections import defaultdict, deque # def input(): return sys.stdin.readline()[:-1] # warning not \n # def input(): return sys.stdin.buffer.readline()[:-1] def solve(): n = int(input()) s = input() cnt = 0 ans = 0 for e in s: if e == "I": cnt += 1 else: cnt -= 1 ans = max(ans, cnt) print(ans) t = 1 # t = int(input()) for case in range(1, t + 1): ans = solve() """ 1 4 7 RRRR 1 1 0 1 ---- 4 1 4 47 RCRR 1 1 0 1 ---- -1 2 2 10 RR RR 1 7 4 1 ---- 4 2 2 10 RR RR 7 4 7 4 ---- -1 3 3 8 RCR RRC RRR 1 1 1 1 1 1 1 3 1 3 3 1 RCR RRC RRR 1 1 1 1 1 1 1 3 1 """
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s235388159
Accepted
p03827
The input is given from Standard Input in the following format: N S
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left, bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil from operator import itemgetter def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def LI2(): return [int(input()) for i in range(n)] def MXI(): return [[LI()] for i in range(n)] def printns(x): print("\n".join(x)) def printni(x): print("\n".join(list(map(str, x)))) inf = 10**17 mod = 10**9 + 7 # s=input().rstrip() sm = 0 n = I() mx = 0 s = input().rstrip() for i in range(n): if s[i] == "I": sm += 1 else: sm -= 1 if sm > mx: mx = sm print(mx)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s316999240
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
_ = input() S = input() max_n = 0 temp = 0 for s in S: temp += 1 if s == 'I' else temp -= 1 if max_n < temp: max_n = temp print(max_n)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s959987127
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
n = int(input()) s = list(map(lambda x: 1 if x == "I" else -1, list(input())) x = 0 m = 0 for i in s: x += i m = max(m,x) print(m)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s735355590
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
S=input() max_v =0 v =0 for i in S: if i=="I": v+=1 if v>max_v: max_v=v else: v-=
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s990317435
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
n=int(input()) s=list(input()) k=[0] for i in range(0,n): if s[i]=='I':k.append(int(k[i]+1) else:k.append(int(k[i]-1)) print(max(k))
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s172169867
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
n = input() s = input() x = 0 y = 0 for i in range(n): if s[i] == "I": y += 1 x = max(x,y) if s[i] == "D": y = y - 1 x = max(x,y) print(x)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s838587918
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
l=[] x=0 l.append(x) n=int(input()) s=input() for i in s: if(i=='I'): x++ l.append(x) if(i=='D'): x-- l.append(x) print(max(l))
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s001119287
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
n = int(input()) s = input() x = 0 l = [0] for n in range(n): if s[n] == "I": x += 1 l.append(x) else: x -= 1 l.append(x) print(max(l))
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s977856571
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
l=[] x=0 l.append(x) n=int(input()) s=input() for i in s: if(i=='I'): x++ l.append(x) if(i=='D'): x-- l.append(x) print(max(l))
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s020350300
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
N = int(input()) line = input() x = 0 t = 0 for i in range(N): if line[i] == 'I': t += 1 else if line[i] == 'D': t -= 1 x = max(t,x) print(x)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s773479044
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
n = int(input()) s = input() x = 0 l = [0] for i in range(n): if s[i] == "I": x += 1 l.append(x) else: x -= 1 l.append(x) print(max(l))
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s423621683
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
N = int(input()) S = input() ans = 0 x = 0 for s in S: v = 1 if s == 'I' else: 0 x += v ans = max(ans, x) print(ans)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s079991453
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
i = int(input()) s = input() ans = 0 for x in range(len(i)) : if s[x] == "I" : ans ++ else : ans -- print(ans)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s332798043
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
N=int(input()) S=input() ans=0 cnt=0 for i in range(N): if S[i]='I': cnt+=1 ans=max(cnt,ans) else: cnt-=1 print(ans)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s486276912
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
n=int(input()) s=input() ans=0 x=0 for i in range(n): if s[i]=='I': ans+=1 x=max(0,ans) else: ans-=1 print(x)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s474201501
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
n = int(input()) s = list(input()) for i in s: if i =="I": n += 1 else: n -= 1 print(n)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s000317804
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
n = int(input()) s = input() x = m = 0 for i range(n): x += [-1,1][s[i] == I]; m = max(m,x) print(m)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s010790292
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
N = int(input()) S = list(input()) x = 0 for item in S: if item == 'I": x+= 1 if item == 'D': x-= 1
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s112938253
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
n = input() s = input() x = 0 y = 0 for i in range(len(s)): if s[i] == "I": y += 1 x = max(x,y) if s[i] == "D": y = y - 1 x = max(x,y) print(x)
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s953206439
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
def main(): n = int(input()) s = list(input().split()) ans = 0 now = 0 for i, i_d in enumerate(s): if i_d == 'I': now += 1 ans = max(ans, now) else: now -= 1 print(ans) if __name__ = '__main__': main()
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s810631791
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
# ABC052B - Increment Decrement def main(): _, S = tuple(input() for _ in range(2)) ans, x = [0], 0 for i in S: x += 1 i == "I" else -1 ans += [x] print(max(ans)) if __name__ == "__main__": main()
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the maximum value taken by x during the operations. * * *
s631890812
Runtime Error
p03827
The input is given from Standard Input in the following format: N S
= int(input()) S = str(input()) cnt = 0 ans = [] for i in range(0,N): if S[i] == "I": cnt = cnt+1 elif S[i] == "D": cnt = cnt-1 ans.append(cnt) if max(ans) <= 0: print("0") else: print(max(ans))
Statement You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
[{"input": "5\n IIDID", "output": "2\n \n\nAfter each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively.\nThus, the output should be 2, the maximum value.\n\n* * *"}, {"input": "7\n DDIDDII", "output": "0\n \n\nThe initial value x=0 is the maximum value taken by x, thus the output should\nbe 0."}]
Print the minimum number of operations needed. * * *
s091173378
Accepted
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
import copy H, W = map(int, input().split()) root_list = [] for _ in range(H): root_list.append(list(str(input()))) change_list = copy.deepcopy(root_list) DP_list = [] for i, line in enumerate(root_list): DP_line = [] str_pt = root_list[i][0] if i == 0: DP_line.append(0) # 初期値 else: if root_list[i - 1][0] == line[0]: # 1文字目が上下一致 DP_line.append(DP_list[i - 1][0]) else: DP_line.append(DP_list[i - 1][0] + 1) for j, pt in enumerate(line[1:], 1): # 先頭は抜かす if i == 0: # 1行目 if str_pt == pt: # 前の文字と一致 DP_line.append(DP_line[j - 1]) # 前の値を入れる else: DP_line.append(DP_line[j - 1] + 1) # 違ったら1足す str_pt = pt else: # 2行目以降(上下左右比較) # 横比較 if str_pt == pt: yoko_pt = DP_line[j - 1] else: yoko_pt = DP_line[j - 1] + 1 # 縦比較 if pt == root_list[i - 1][j]: tate_pt = DP_list[i - 1][j] else: tate_pt = DP_list[i - 1][j] + 1 DP_line.append(min(yoko_pt, tate_pt)) str_pt = pt DP_list.append(DP_line) result = DP_list[H - 1][W - 1] // 2 if root_list[0][0] == "#": result += 1 if root_list[H - 1][W - 1] == "#": result += 1 if root_list[0][0] == "#" and root_list[H - 1][W - 1] == "#": if result == 2 or (H == 1 and W == 1): result = 1 else: result -= 1 print(result)
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]