message
stringlengths
2
45.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
254
108k
cluster
float64
3
3
__index_level_0__
int64
508
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem. Allen's future parking lot can be represented as a rectangle with 4 rows and n (n ≤ 50) columns of rectangular spaces, each of which can contain at most one car at any time. He imagines having k (k ≤ 2n) cars in the grid, and all the cars are initially in the second and third rows. Each of the cars also has a different designated parking space in the first or fourth row. Allen has to put the cars into corresponding parking places. <image> Illustration to the first example. However, since Allen would never entrust his cars to anyone else, only one car can be moved at a time. He can drive a car from a space in any of the four cardinal directions to a neighboring empty space. Furthermore, Allen can only move one of his cars into a space on the first or fourth rows if it is the car's designated parking space. Allen knows he will be a very busy man, and will only have time to move cars at most 20000 times before he realizes that moving cars is not worth his time. Help Allen determine if he should bother parking his cars or leave it to someone less important. Input The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 2n), representing the number of columns and the number of cars, respectively. The next four lines will contain n integers each between 0 and k inclusive, representing the initial state of the parking lot. The rows are numbered 1 to 4 from top to bottom and the columns are numbered 1 to n from left to right. In the first and last line, an integer 1 ≤ x ≤ k represents a parking spot assigned to car x (you can only move this car to this place), while the integer 0 represents a empty space (you can't move any car to this place). In the second and third line, an integer 1 ≤ x ≤ k represents initial position of car x, while the integer 0 represents an empty space (you can move any car to this place). Each x between 1 and k appears exactly once in the second and third line, and exactly once in the first and fourth line. Output If there is a sequence of moves that brings all of the cars to their parking spaces, with at most 20000 car moves, then print m, the number of moves, on the first line. On the following m lines, print the moves (one move per line) in the format i r c, which corresponds to Allen moving car i to the neighboring space at row r and column c. If it is not possible for Allen to move all the cars to the correct spaces with at most 20000 car moves, print a single line with the integer -1. Examples Input 4 5 1 2 0 4 1 2 0 4 5 0 0 3 0 5 0 3 Output 6 1 1 1 2 1 2 4 1 4 3 4 4 5 3 2 5 4 2 Input 1 2 1 2 1 2 Output -1 Input 1 2 1 1 2 2 Output 2 1 1 1 2 4 1 Note In the first sample test case, all cars are in front of their spots except car 5, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most 20000 will be accepted. In the second sample test case, there is only one column, and the cars are in the wrong order, so no cars can move and the task is impossible. Submitted Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- import time max = 20000 def test(x1, x2, n, s): for i in range(x1+1, x2+1): if s[n][i] != 0: return False return True def lastshift(n, s, a): m = 0 for i in range(n): if s[1][i] != 0 and s[1][i] == s[0][i]: s[1][i] = 0 m += 1 a.append([s[0][i], 1, i+1] ) elif s[2][i] != 0 and s[2][i] == s[0][i] and s[1][i] == 0: s[2][i] = 0 m += 1 a.append([s[0][i], 2, i+1]) a.append([s[0][i], 1, i+1]) if s[2][i] != 0 and s[2][i] == s[3][i]: s[2][i] = 0 m += 1 a.append([s[3][i], 4, i+1]) elif s[2][i] != 0 and s[1][i] == s[3][i] and s[2][i] == 0: s[1][i] = 0 m += 1 a.append([s[3][i], 3, i+1]) a.append([s[3][i], 4, i+1]) return(m) (n, k) = (int(i) for i in input().split()) s = [] s.append([int(i) for i in input().split()]) s.append([int(i) for i in input().split()]) s.append([int(i) for i in input().split()]) s.append([int(i) for i in input().split()]) start = time.time() a = [] m = lastshift(n, s, a) I = -1 for i in range(n): if s[1][i] == 0: l = 1 I = i break if s[2][i] == 0: l = 2 I = i break if I >= 0: while(m < k): b = s[1][0] e = s[2][n-1] if l == 1: for i in range(I, n-1): s[1][i] = s[1][i+1] if s[1][i+1] != 0: a.append([s[1][i+1], 2, i+1]) if b!=0: a.append([b, 3, 1]) for i in range(n-1, 0, -1): s[2][i] = s[2][i-1] if s[2][i] != 0: a.append([s[2][i], 3, i+1]) if e!=0: a.append([e, 2, n]) for i in range(I): s[1][i] = s[1][i+1] if s[1][i+1] != 0: a.append([s[1][i+1], 2, i+1]) s[1][n-1] = e s[2][0] = b else: for i in range(I, 0, -1): s[2][i] = s[2][i-1] if s[2][i] != 0: a.append([s[2][i], 3, i+1]) if b!=0: a.append([b, 3, 1]) for i in range(n-1): s[1][i] = s[1][i+1] if s[1][i] != 0: a.append([s[1][i], 2, i+1]) if e!=0: a.append([e, 2, n]) for i in range(n-1, I, -1): s[2][i] = s[2][i-1] if s[2][i] != 0: a.append([s[2][i], 3, i+1]) s[1][n-1] = e s[2][0] = b I += 2*l-3 if I == -1: I = 0 l = 2 if I == n: I = n-1 l = 1 s[l][I] = 0 # print() # for i in range(4): # for j in range(n): # print(s[i][j], end=" ") # print() # print() m += lastshift(n, s, a) print(len(a)) for i in range(len(a)): print(a[i][0], a[i][1], a[i][2]) else: print(-1) finish = time.time() #print(finish - start) ```
instruction
0
96,732
3
193,464
No
output
1
96,732
3
193,465
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem. Allen's future parking lot can be represented as a rectangle with 4 rows and n (n ≤ 50) columns of rectangular spaces, each of which can contain at most one car at any time. He imagines having k (k ≤ 2n) cars in the grid, and all the cars are initially in the second and third rows. Each of the cars also has a different designated parking space in the first or fourth row. Allen has to put the cars into corresponding parking places. <image> Illustration to the first example. However, since Allen would never entrust his cars to anyone else, only one car can be moved at a time. He can drive a car from a space in any of the four cardinal directions to a neighboring empty space. Furthermore, Allen can only move one of his cars into a space on the first or fourth rows if it is the car's designated parking space. Allen knows he will be a very busy man, and will only have time to move cars at most 20000 times before he realizes that moving cars is not worth his time. Help Allen determine if he should bother parking his cars or leave it to someone less important. Input The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 2n), representing the number of columns and the number of cars, respectively. The next four lines will contain n integers each between 0 and k inclusive, representing the initial state of the parking lot. The rows are numbered 1 to 4 from top to bottom and the columns are numbered 1 to n from left to right. In the first and last line, an integer 1 ≤ x ≤ k represents a parking spot assigned to car x (you can only move this car to this place), while the integer 0 represents a empty space (you can't move any car to this place). In the second and third line, an integer 1 ≤ x ≤ k represents initial position of car x, while the integer 0 represents an empty space (you can move any car to this place). Each x between 1 and k appears exactly once in the second and third line, and exactly once in the first and fourth line. Output If there is a sequence of moves that brings all of the cars to their parking spaces, with at most 20000 car moves, then print m, the number of moves, on the first line. On the following m lines, print the moves (one move per line) in the format i r c, which corresponds to Allen moving car i to the neighboring space at row r and column c. If it is not possible for Allen to move all the cars to the correct spaces with at most 20000 car moves, print a single line with the integer -1. Examples Input 4 5 1 2 0 4 1 2 0 4 5 0 0 3 0 5 0 3 Output 6 1 1 1 2 1 2 4 1 4 3 4 4 5 3 2 5 4 2 Input 1 2 1 2 1 2 Output -1 Input 1 2 1 1 2 2 Output 2 1 1 1 2 4 1 Note In the first sample test case, all cars are in front of their spots except car 5, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most 20000 will be accepted. In the second sample test case, there is only one column, and the cars are in the wrong order, so no cars can move and the task is impossible. Submitted Solution: ``` """ http://codeforces.com/contest/996/problem/C """ class CarAlgorithm: def __init__(self, n, k, parking): self.n = n self.k = k self.parking = parking self._step_count = 0 self._steps = [] self._done = False for i in range(4): assert len(parking[i]) == n, "%s != %s" % (len(parking[i]), n) def do(self): """ 1) загоянем все тривиальные машины 2) ищем пробел (если нет, то нет решения) 3) для каждой машины рассчитываем минимальной путь до парковки 4) выбираем машину с минимальным расстоянием до парковки """ if self._done: return self._steps self._done = True n, k, parking = self.n, self.k, self.parking car_target_cells = {} # solve trivial cars for park_str, car_str in [(0, 1), (3, 2)]: for i in range(n): car_number = parking[park_str][i] if car_number == 0: continue elif parking[car_str][i] == car_number: self.move_car(parking, car_str, i, park_str, i) else: car_target_cells[car_number] = (park_str, i) # car_number = parking[3][i] # if car_number == 0: # continue # elif parking[2][i] == car_number: # self.move_car(parking, 2, i, 3, i) # else: # car_target_cells[car_number] = (3, i) # print(car_target_cells) while True: # find shortest path for all cars # choose car with minimal shortest path # find free cell target_shortest_path = None target_car_cell = None target_dst_str, target_dst_col = None, None free_cell = None for j in range(1, 3): for i in range(n): if parking[j][i] == 0: if free_cell and target_car_cell and \ abs(target_car_cell[0] - j) >= abs(target_car_cell[0] - free_cell[0]): continue free_cell = j, i else: cur_car = parking[j][i] target_str, target_col = car_target_cells[cur_car] cur_shortest_path = find_path(j, i, target_str, target_col) if target_shortest_path is None or len(cur_shortest_path) < len(target_shortest_path): target_shortest_path = cur_shortest_path target_car_cell = j, i target_dst_str, target_dst_col = target_str, target_col if target_shortest_path is None: # car is on the road is not found return self._steps # move car to cell before dst cell car_cell_str, car_cell_col = target_car_cell for path_next_cell_str, path_next_cell_col in target_shortest_path: if parking[path_next_cell_str][path_next_cell_col] != 0: # move free cell to next cell from path if not free_cell: self._step_count = -1 return self._step_count free_cell_str, free_cell_col = free_cell if free_cell_str < car_cell_str < path_next_cell_str or path_next_cell_col < car_cell_str < free_cell_str: # .****сx or xc****. # |_____| |_____| if free_cell_str == 1: if parking[2][free_cell_col] != 0: self.move_car(parking, 2, free_cell_col, 1, free_cell_col) free_cell_str = 2 else: # free_cell_str == 2 self.move_car(parking, 1, free_cell_col, 2, free_cell_col) free_cell_str = 1 free_cell_step = 1 if free_cell_col < path_next_cell_col else -1 for _ in range(free_cell_col, path_next_cell_col, free_cell_step): next_col = free_cell_col + 1 if parking[free_cell_str][next_col] != 0: self.move_car(parking, free_cell_str, next_col, free_cell_str, free_cell_col) free_cell_col += free_cell_step if (free_cell_str, path_next_cell_str) in [(1, 2), (2, 1)]: self.move_car(parking, path_next_cell_str, path_next_cell_col, free_cell_str, free_cell_col) free_cell = path_next_cell_str, path_next_cell_col self.move_car(parking, car_cell_str, car_cell_col, path_next_cell_str, path_next_cell_col) car_cell_str, car_cell_col = path_next_cell_str, path_next_cell_col self.move_car(parking, car_cell_str, car_cell_col, target_dst_str, target_dst_col) def move_car(self, parking, from_str, from_col, to_str, to_col): car_number = parking[from_str][from_col] # print("%s %s %s" % (car_number, to_str, to_col)) self._steps.append((car_number, to_str+1, to_col+1)) # print("%s %s %s" % (car_number, to_str+1, to_col+1)) # print("%s %s %s %s" % (car_number, to_str+1, to_col+1, parking)) parking[to_str][to_col] = parking[from_str][from_col] parking[from_str][from_col] = 0 self._step_count += 1 def find_path(from_str, from_col, to_str, to_col): """ return internal path between from_cell and to_cell (borders are not included) """ str_direct = 1 if from_col < to_col else -1 path = [ (from_str, i) for i in range( from_col + str_direct, to_col + str_direct, str_direct ) ] if from_str == 1 and to_str == 3: path.append((2, to_col)) elif from_str == 2 and to_str == 0: path.append((1, to_col)) # col_direct = 1 if from_str < to_str else -1 # path.extend([ # (i, to_col) for i in range( # from_str + col_direct, to_str + col_direct, col_direct # ) # ]) # print(from_str, from_col, path) return path def test(): assert find_path(*(1,0), *(0,0)) == [], find_path(*(1,0), *(0,0)) assert find_path(*(1,0), *(0,1)) == [(1,1)] assert find_path(*(1,0), *(0,1)) == [(1,1)] assert find_path(*(2,0), *(0,1)) == [(2,1), (1,1)] assert find_path(*(1,0), *(3,0)) == [(2,0)], find_path(*(1,0), *(3,0)) a = CarAlgorithm(4, 5, [[1, 2, 0, 4,], [1, 2, 0, 4,], [5, 0, 0, 3,], [0, 5, 0, 3,]]) assert a.do() == 6, a.do() a = CarAlgorithm(1, 2, [[1], [2], [1], [2]]) assert a.do() == -1, a.do() a = CarAlgorithm(1, 2, [[1], [1], [2], [2]]) assert a.do() == 2, a.do() a = CarAlgorithm(50, 99, [ [i for i in range(50)], [i for i in range(75, 100)] + [i for i in range(50, 75)], [i for i in range(25, 50)] + [i for i in range(25)], [i for i in range(50, 100)] ]) # print(a.parking) assert a.do() == 2, a.do() def do(): n, k = [int(str_i) for str_i in input().split()] p = [ [int(str_i) for str_i in input().split()] for _ in range(4) ] steps = CarAlgorithm(n, k, p).do() if steps == -1: print(-1) else: print(len(steps)) for s in steps: print("%s %s %s" % s) # test() do() ```
instruction
0
96,733
3
193,466
No
output
1
96,733
3
193,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem. Allen's future parking lot can be represented as a rectangle with 4 rows and n (n ≤ 50) columns of rectangular spaces, each of which can contain at most one car at any time. He imagines having k (k ≤ 2n) cars in the grid, and all the cars are initially in the second and third rows. Each of the cars also has a different designated parking space in the first or fourth row. Allen has to put the cars into corresponding parking places. <image> Illustration to the first example. However, since Allen would never entrust his cars to anyone else, only one car can be moved at a time. He can drive a car from a space in any of the four cardinal directions to a neighboring empty space. Furthermore, Allen can only move one of his cars into a space on the first or fourth rows if it is the car's designated parking space. Allen knows he will be a very busy man, and will only have time to move cars at most 20000 times before he realizes that moving cars is not worth his time. Help Allen determine if he should bother parking his cars or leave it to someone less important. Input The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 2n), representing the number of columns and the number of cars, respectively. The next four lines will contain n integers each between 0 and k inclusive, representing the initial state of the parking lot. The rows are numbered 1 to 4 from top to bottom and the columns are numbered 1 to n from left to right. In the first and last line, an integer 1 ≤ x ≤ k represents a parking spot assigned to car x (you can only move this car to this place), while the integer 0 represents a empty space (you can't move any car to this place). In the second and third line, an integer 1 ≤ x ≤ k represents initial position of car x, while the integer 0 represents an empty space (you can move any car to this place). Each x between 1 and k appears exactly once in the second and third line, and exactly once in the first and fourth line. Output If there is a sequence of moves that brings all of the cars to their parking spaces, with at most 20000 car moves, then print m, the number of moves, on the first line. On the following m lines, print the moves (one move per line) in the format i r c, which corresponds to Allen moving car i to the neighboring space at row r and column c. If it is not possible for Allen to move all the cars to the correct spaces with at most 20000 car moves, print a single line with the integer -1. Examples Input 4 5 1 2 0 4 1 2 0 4 5 0 0 3 0 5 0 3 Output 6 1 1 1 2 1 2 4 1 4 3 4 4 5 3 2 5 4 2 Input 1 2 1 2 1 2 Output -1 Input 1 2 1 1 2 2 Output 2 1 1 1 2 4 1 Note In the first sample test case, all cars are in front of their spots except car 5, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most 20000 will be accepted. In the second sample test case, there is only one column, and the cars are in the wrong order, so no cars can move and the task is impossible. Submitted Solution: ``` n, k = list(map(int, input().split())) table = [] for row in range(4): table.append(list(map(int, input().split()))) moves = [] def make_move(start,finish): moves.append((table[start[0]][start[1]], finish[0]+1, finish[1]+1)) table[finish[0]][finish[1]] = table[start[0]][start[1]] table[start[0]][start[1]] = 0 def move_all_to_places(): for pos in range(n): if (table[1][pos] == table[0][pos]) and table[1][pos]: make_move((1,pos), (0,pos)) if (table[2][pos] == table[3][pos]) and table[2][pos]: make_move((2,pos), (3,pos)) move_all_to_places() found = False for pos in range(n): if table[1][pos] == 0: found = True break if table[2][pos] == 0: found = True break if not found: print(-1) exit() for cnt in range(20000): if (table[1][0] != 0) and (table[2][0] == 0) : make_move((1,0), (2,0)) # moved down for pos in range(1,n): if (table[1][pos-1] == 0) and (table[1][pos] != 0): make_move((1,pos), (1, pos-1)) if (table[1][n-1] == 0) and (table[2][n-1] != 0) : make_move((2,n-1), (1,n-1)) # moved up for pos in range(n-2,-1, -1): if (table[2][pos+1] == 0) and (table[2][pos] != 0): make_move((2,pos), (2, pos+1)) move_all_to_places() print(len(moves)) for m in moves: print(*m) ```
instruction
0
96,734
3
193,468
No
output
1
96,734
3
193,469
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` num = int(input()) def chain(L, x, y): if L[y][x] == 0: return L[y][x] = 0 for i in range(-3, 4): nx = x + i if nx in range(8): if L[y][nx] > 0: chain(L, nx, y) ny = y + i if ny in range(8): if L[ny][x] > 0: chain(L, x, ny) return for k in range(num): input() L = [] for i in range(8): l = [int(x) for x in input()] L.append(l) x = int(input())-1 y = int(input())-1 chain(L, x, y) print("Data {}:".format(k+1)) for l in L: print( "".join(map(str,l)) ) ```
instruction
0
96,866
3
193,732
Yes
output
1
96,866
3
193,733
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` def get_input(): while True: try: yield ''.join(input()) except EOFError: break def bomb(table, x, y): table[x][y] = False for i in range(1, 4): if x + i >= 8: break if table[x+i][y]: bomb(table, x+i, y) for i in range(1, 4): if x - i < 0: break if table[x-i][y]: bomb(table, x-i, y) for i in range(1, 4): if y + i >= 8: break if table[x][y+i]: bomb(table, x, y+i) for i in range(1, 4): if y - i < 0: break if table[x][y-i]: bomb(table, x, y-i) return N = int(input()) for l in range(N): input() table = [[False for i in range(8)] for j in range(8)] for i in range(8): L = input() for j in range(8): if int(L[j]) == 1: table[i][j] = True a = int(input()) b = int(input()) bomb(table, b-1, a-1) print("Data " + str(l+1) + ":") for i in range(8): for j in range(8): if table[i][j]: print("1", end="") else: print("0", end="") print("") ```
instruction
0
96,867
3
193,734
Yes
output
1
96,867
3
193,735
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0071 """ import sys def check_bombs(map, pos, dir, range=3): """ ????¢¨????±???????????????\??????????????????????????§??????????????? (?????°????????????????¢¨????±??????´?????§????????????????????????????????????????????§????????????????????????) :param map: ?????¨?????¶??? :param pos: ??????????????????????????? :param dir: ?????§????????????????¢¨????????? (up, down, left, right) :param range: ????¢¨????±?????????? :return: ???????????????????????????????????? or None """ if dir == 'up': x, y = pos while range > 0 and y > 0: if map[y-1][x] == '1': return (x, y-1) else: y -= 1 range -= 1 elif dir == 'down': x, y = pos while range > 0 and y < len(map)-1: if map[y+1][x] == '1': return (x, y+1) else: y += 1 range -= 1 elif dir == 'left': x, y = pos while range > 0 and x > 0: if map[y][x-1] == '1': return (x-1, y) else: x -= 1 range -= 1 elif dir == 'right': x, y = pos while range > 0 and x < len(map[0])-1: if map[y][x+1] == '1': return (x+1, y) else: x += 1 range -= 1 else: return None def chain_bombs(map, init_pos): """ ???????????£?????????????????¶???????¨?????????? :param map: ???????????????????????¶??? :param init_pos: (0, 0)?????????????????????????????????????????????????????§?¨? :return: ??????????????????????????¶??? """ lmap = map[:] # ??????????????¶????¨??????¨ detonated = [init_pos] # ??±?????????????????????????????????(????????????) while detonated: x, y = detonated.pop() lmap[y][x] = '0' res = check_bombs(lmap, (x, y), 'up') if res: detonated.append(res) res = check_bombs(lmap, (x, y), 'down') if res: detonated.append(res) res = check_bombs(lmap, (x, y), 'left') if res: detonated.append(res) res = check_bombs(lmap, (x, y), 'right') if res: detonated.append(res) return lmap def main(args): data_set = int(input()) maps = [] init_pos = [] for i in range(data_set): _ = input() maps.append([list(input().strip()) for _ in range(8)]) init_pos.append([int(input())-1, int(input())-1]) # ??§?¨????0??????????????????????????? count = 1 for map, pos in zip(maps, init_pos): result = chain_bombs(map, pos) print('Data {}:'.format(count)) for row in result: print(''.join(row)) count += 1 if __name__ == '__main__': main(sys.argv[1:]) ```
instruction
0
96,868
3
193,736
Yes
output
1
96,868
3
193,737
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` def dfs_bomb(A,x,y): X = [ 1, 0,-1, 0, 2, 0,-2, 0, 3, 0,-3, 0] Y = [ 0, 1, 0,-1, 0, 2, 0,-2, 0, 3, 0,-3] A[x][y] = "0" for i in range(12): xx = x + X[i] yy = y + Y[i] if 0 <= xx < 8 and 0 <= yy < 8: if A[xx][yy] == "1": dfs_bomb(A,xx,yy) if __name__ == '__main__': cnt = int(input()) for i in range(cnt): input() A = [] for _ in range(8): A.append(list(input())) y = int(input()) - 1 x = int(input()) - 1 dfs_bomb(A,x,y) print("Data "+str(i+1)+":") for z in range(8): print("".join(A[z])) ```
instruction
0
96,869
3
193,738
Yes
output
1
96,869
3
193,739
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` # Aizu Problem 0071: Bombs Chain # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") def bombs_chain(grid, row, col): offsets = [[1, 0], [-1, 0], [0, 1], [0, -1]] queue = [(row, col)] while len(queue) > 0: row0, col0 = queue.pop(0) for row_off, col_off in offsets: for k in range(1, 4): row = row0 + row_off * k col = col0 + col_off * k if 0 <= row < 8 and 0 <= col < 8 and grid[row][col] == 1: grid[row][col] = 0 queue.append((row, col)) return grid N = int(input()) for case in range(N): input() grid = [[int(_) for _ in input().strip()] for __ in range(8)] col = int(input()) - 1 row = int(input()) - 1 grid = bombs_chain(grid, row, col) print("Data %d:" % (case + 1)) for row in grid: print(''.join([str(r) for r in row])) ```
instruction
0
96,870
3
193,740
No
output
1
96,870
3
193,741
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` n = int(input()) input() for i in range(n): board = [list(input()) for i in range(8)] sx = int(input()) - 1 sy = int(input()) - 1 input() board[sy][sx] == 2 bomb = [] n_bomb = [[sy, sx]] points = [] for j in range(len(board)): while '1' in board[j]: px = board[j].index('1') py = j points.append([py, px]) board[j][px] = '2' while len(n_bomb) != 0: bomb += n_bomb n_bomb = [] for b in bomb: for p in points: if (p[0] == b[0] and b[1]-3 <= p[1] <= b[1]+3) or (p[1] == b[1] and b[0]-3 <= p[0] <= b[0]+3): points.remove(p) n_bomb.append(p) ans = [['0'] * 8 for j in range(8)] for p in points: ans[p[0]][p[1]] = '1' print("Data %s:" % str(i+1)) for p in ans: print("".join(p)) ```
instruction
0
96,871
3
193,742
No
output
1
96,871
3
193,743
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` # -*- coding: utf-8 -*- import sys import os import itertools T = int(input()) for t in range(T): input() map = [] for i in range(8): s = input().strip() map.append(list(s)) X = int(input()) Y = int(input()) X -= 1 Y -= 1 def exist_bomb(x, y): if 0 <= x < 8 and 0 <= y < 8 and map[y][x] == '1': return True else: return False Q = [] Q.append((X, Y)) while Q: x, y = Q.pop(0) for i in range(1, 4): if exist_bomb(x + i, y): Q.append((x + i, y)) map[y][x+i] = '0' if exist_bomb(x - i, y): Q.append((x - i, y)) map[y][x-i] = '0' if exist_bomb(x, y + i): Q.append((x, y + i)) map[y+i][x] = '0' if exist_bomb(x, y - i): Q.append((x, y - i)) map[y-i][x] = '0' # result if t != 0: print() print("Data {}:".format(t+1)) for i, row in enumerate(map): print(''.join(row), end='') if i != 7: print() ```
instruction
0
96,872
3
193,744
No
output
1
96,872
3
193,745
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | ● | □ | □ | ● | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | ● | □ | □ ● | □ | □ | □ | ● | □ | □ | ● □ | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | ● | □ | □ | □ ● | □ | ● | □ | □ | □ | ● | □ □ | ● | □ | ● | □ | □ | ● | □ Figure 1 | Figure 2 When a bomb explodes, the blast affects the three squares above, below, left, and right of the bomb, and the bombs placed in those squares also explode in a chain reaction. For example, if the bomb shown in Fig. 3 explodes, the square shown in Fig. 4 will be affected by the blast. | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ● | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ ■| ■| ■| ●| ■| ■| ■| □ □ | □ | □ | ■ | □ | □ | □ | □ □ | □ | □ | ■ | □ | □ | □ | □ Figure 3 | Figure 4 Create a program that reads the state where the bomb is placed and the position of the bomb that explodes first, and outputs the state of the final plane. Input The input is given in the following format: n (Blank line) Data set 1 (Blank line) Data set 2 .. .. Data set n The first line gives the number of datasets n (n ≤ 20). Then n datasets are given. One blank line is given immediately before each dataset. Each dataset is given in the following format: g1,1g2,1 ... g8,1 g1,2g2,2 ... g8,2 :: g1,8g2,8 ... g8,8 X Y The first eight lines are given eight strings representing the plane. Each string is a sequence of 8 characters, with 1 representing the square with the bomb and 0 representing the square without the bomb. The next two lines give the X and Y coordinates of the first bomb to explode. The coordinates of the upper left, lower left, upper right, and lower right are (1, 1), (1, 8), (8, 1), and (8, 8), respectively. For example, when the bomb shown in Figure 4 explodes for the first time, the coordinates given are (4, 6). Output Please output as follows for each data set. Let 1 be the square with the bomb left without exploding, and 0 be the square without the bomb. Make one line of the plane one line consisting of eight numbers, and output the final plane state with a character string of eight lines. The beginning of each dataset must be output from Data x: as in the sample output. Where x is the dataset number. Example Input 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 Output Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Submitted Solution: ``` # -*- coding: utf-8 -*- import sys import os import itertools T = int(input()) for t in range(T): input() map = [] for i in range(8): s = input().strip() map.append(list(s)) X = int(input()) Y = int(input()) X -= 1 Y -= 1 def exist_bomb(x, y): if 0 <= x < 8 and 0 <= y < 8 and map[y][x] == '1': return True else: return False Q = [] Q.append((X, Y)) while Q: x, y = Q.pop(0) for i in range(1, 4): if exist_bomb(x + i, y): Q.append((x + i, y)) map[y][x+i] = '0' if exist_bomb(x - i, y): Q.append((x - i, y)) map[y][x-i] = '0' if exist_bomb(x, y + i): Q.append((x, y + i)) map[y+i][x] = '0' if exist_bomb(x, y - i): Q.append((x, y - i)) map[y-i][x] = '0' # result print("Data {}:".format(t+1)) for row in map: print(''.join(row)) ```
instruction
0
96,873
3
193,746
No
output
1
96,873
3
193,747
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° # dy = [1, 1, 1] dx = [0, -1, 1] # ?????????????????????????????????????§??????? x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() # ?????§??????????????????????????¨??????????????\??? # ???????????§??????????????§????????´????????¢???????????\?????????????????? for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? k = '{}_{}'.format(x, 0) Q.append((x, 0)) path[k] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? k = '{}_{}'.format(cx, cy) num = path.pop(k) # ????????§?¨?????????????????????° if field[cy][cx] == OBSTACLE: # ?????£????????§?????°??????????????????????????±????????????????????????????????§?????£????????????????? continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: # ?????£???????????????????¶?????????´??????OK??¨????????? ans += num else: k = '{}_{}'.format(cx, cy+2) if not path[k]: Q.append((cx, cy+2)) path[k] += num continue elif cy == y_limit -1: ans += num continue for i in range(3): # ?????????3???len(dy)????????? nx = cx + dx[i] # ?????°????????§?¨? ny = cy + 1 # ??????+1????????§???dy[i]??¨?????????????????????OK if 0<= nx < x_limit: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: k = '{}_{}'.format(nx, ny+2) if not path[k]: Q.append((nx, ny+2)) path[k] += num elif field[ny][nx] == BLANK: if (ny >= y_limit - 1): ans += num else: k = '{}_{}'.format(nx, ny) if not path[k]: Q.append((nx, ny)) path[k] += num return ans def solve2(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = '{}_{}'.format(x, 0) Q.append((x, 0)) path[t] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue elif cy == y_limit -1: ans += num continue for i in range(3): # ?????????3???len(dy)????????? nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == BLANK: if (ny >= y_limit - 1): ans += num else: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def solve3(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 X = len(field[0]) Y = len(field) dp = [[0] * X for _ in range(Y)] # ??????????????°???????????? for x in range(X): if field[0][x] == BLANK: dp[0][x] = 1 for y in range(1, Y): for x in range(X): t = 0 mark = field[y][x] if mark == BLANK: if field[y-1][x] != JUMP: t += dp[y-1][x] if x > 0 and field[y-1][x-1] != JUMP: t += dp[y-1][x-1] if x < X-1 and field[y-1][x+1] != JUMP: t += dp[y-1][x+1] if y > 1 and field[y-2][x] == JUMP: t += dp[y-2][x] elif mark == JUMP: if field[y-1][x] != JUMP: t = dp[y-1][x] if y > 1 and field[y-2][x] == JUMP: t += dp[y-2][x] dp[y][x] = t ans = sum(dp[-1]) if Y > 1: for x in range(X): if field[-2][x] == JUMP: ans += dp[-2][x] return ans def main(args): while True: X, Y = map(int, input().strip().split()) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve3(field) print(result) if __name__ == '__main__': main(sys.argv[1:]) ```
instruction
0
96,882
3
193,764
Yes
output
1
96,882
3
193,765
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = '{}_{}'.format(x, 0) Q.append((x, 0)) path[t] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue elif cy == y_limit -1: ans += num continue for i in range(3): # ?????????3???len(dy)????????? nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == BLANK: if (ny >= y_limit - 1): ans += num else: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = map(int, input().strip().split()) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == '__main__': main(sys.argv[1:]) ```
instruction
0
96,883
3
193,766
Yes
output
1
96,883
3
193,767
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` while True: x, y = map(int, input().split()) if x == 0: break mp = [[1] + list(map(int, input().split())) + [1] for _ in range(y)] mp.insert(0, [1] * (x + 2)) mp.append([0] * (x + 2)) mp.append([0] * (x + 2)) tr = [[0] * (x + 2) for _ in range(y + 2)] for i in range(1, x + 1): if mp[1][i] == 0: tr[1][i] = 1 for i in range(2, y + 1): for j in range(1, x + 1): if mp[i][j] == 0: for k in range(j - 1, j + 2): if mp[i - 1][k] == 0: tr[i][j] += tr[i - 1][k] if mp[i - 2][j] == 2: tr[i][j] += tr[i - 2][j] elif mp[i][j] == 2: if mp[i - 1][j] == 0: tr[i][j] += tr[i - 1][j] if mp[i - 2][j] == 2: tr[i][j] += tr[i - 2][j] ans = sum(tr[y]) for i in range(1, x + 1): if mp[y - 1][i] == 2: ans += tr[y - 1][i] print(ans) ```
instruction
0
96,884
3
193,768
Yes
output
1
96,884
3
193,769
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` while 1: x,y = list(map(int, input().split())) if x == 0: break c = [list(map(int, input().split())) for _ in range(y)] c.append([0]*x) c.append([0]*x) dp = [[0]*x for _ in range(y+2)] for i in range(x): if c[0][i] == 0: dp[0][i] = 1 for i in range(y): for j in range(x): if c[i][j] == 0: if i != y-1: if j != 0 and c[i+1][j-1] == 0: dp[i+1][j-1] += dp[i][j] if j != x-1 and c[i+1][j+1] == 0: dp[i+1][j+1] += dp[i][j] if c[i+1][j] != 1: dp[i+1][j] += dp[i][j] elif c[i][j] == 2: if c[i+2][j] != 1: dp[i+2][j] += dp[i][j] ans = 0 for i in dp[y-1:y+1]: ans += sum(i) print(ans) """ while 1: x,y = list(map(int, input().split())) if x == 0: break c = [list(map(int, input().split())) for _ in range(y)] dp = [[0]*x for _ in range(y+1)] for i in range(x): if c[0][i] == 0: dp[0][i] = 1 for i in range(1,y): for j in range(x): if c[i][j] == 0: if i >= 2 and c[i-2][j] == 2: dp[i][j] += dp[i-2][j] if j != 0 and c[i-1][j-1] == 0:dp[i][j] += dp[i-1][j-1] if j != x-1 and c[i-1][j+1] == 0:dp[i][j] += dp[i-1][j+1] if c[i-1][j] != 1: dp[i][j] += dp[i-1][j] elif c[i][j] == 2: dp[i][j] += dp[i-1][j] if i >= 2 and c[i-2][j] == 2: dp[i][j] += dp[i-2][j] for i in dp: print(i) ans = 0 for i in range(x): ans += dp[y-1][i] if y >= 2 and c[y-2][i] == 2: ans += dp[y-2][j] print(ans) """ ```
instruction
0
96,885
3
193,770
Yes
output
1
96,885
3
193,771
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = '{}_{}'.format(x, 0) Q.append((x, 0)) path[t] = 1 if y_limit < 2: return len(Q) while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue elif cy == y_limit -1: ans += num continue for i in range(len(dx)): nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if (ny >= y_limit - 1) and field[ny][nx] != OBSTACLE: ans += num else: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == BLANK: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = map(int, input().strip().split()) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == '__main__': main(sys.argv[1:]) ```
instruction
0
96,886
3
193,772
No
output
1
96,886
3
193,773
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): # 0: ????????°, 1: ?????????, 2: ?????£????????° ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????° Q = deque() for x, m in enumerate(field[0]): if m == 0: # ?????????????????°?????´????????????????????????????????? Q.append((x, 0)) t = '{}_{}'.format(x, 0) path[t] = 1 if y_limit < 2: return len(Q) while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == 1: # ?????£????????§?????°????????????????????? continue elif field[cy][cx] == 2: # ?????£????????§?????°?????????????????£????????° if cy+2 >= y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue for i in range(len(dx)): nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if ny >= y_limit - 1 and field[ny][nx] != 1: ans += num else: if field[ny][nx] == 2 and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == 0: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = map(int, input().strip().split()) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == '__main__': main(sys.argv[1:]) ```
instruction
0
96,887
3
193,774
No
output
1
96,887
3
193,775
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` def algorithm(): def down_jump(x, y, times): if x == r: out_map[x - 1][y] += times elif x == r - 1: out_map[x][y] += times elif in_map[x][y] == 2: down_jump(x + 2, y, times) else: out_map[x][y] += times while True: c, r = map(int, input().split()) if c == 0 and r == 0: break in_map = [] out_map = [[0 for _ in range(c)] for _ in range(r)] for _ in range(r): in_map.append(list(map(int, input().split()))) for i in range(c): if in_map[0][i] == 0 or in_map[0][i] == 2: out_map[0][i] = 1 for i in range(r): for j in range(c): if in_map[i][j] == 0 or (i == 0 and in_map[i][j] == 2): # ???. if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0 and in_map[i][j] == 0: out_map[i + 1][j - 1] += out_map[i][j] # ???. if in_map[i][j] == 2: down_jump(i, j, out_map[i][j]) elif i + 1 < r and in_map[i + 1][j] == 0: out_map[i + 1][j] += out_map[i][j] elif i + 1 < r and in_map[i + 1][j] == 2: down_jump(i + 1, j, out_map[i][j]) # ???. if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0 and in_map[i][j] == 0: out_map[i + 1][j + 1] += out_map[i][j] for i in range(c): out_map[r - 1][i] = 0 if in_map[r - 1][i] else out_map[r - 1][i] print(sum(out_map[r - 1])) def main(): algorithm() if __name__ == '__main__': main() ```
instruction
0
96,888
3
193,776
No
output
1
96,888
3
193,777
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's create a program for the oil tree shop that outputs the number of patterns of how to slide based on the floor plan of the course. <image> The course is represented by a grid of X x Y squares as shown above. It is assumed that the origin is at the upper left, the x coordinate increases as it goes to the right, and the y coordinate increases as it goes down. Each gliding pattern starts at the highest point (y = 1, but without obstacles) and progresses towards the goal (y = Y). A runner in a grid square (x, y) can move to either (x − 1, y + 1), (x, y + 1), or (x + 1, y + 1). I will. There are obstacles and jumping platforms in the squares, and you cannot enter the squares with obstacles, and when you enter the squares with jumping platforms, you will move to (x, y + 2). However, there is no jumping platform in the highest cell (the cell with y = 1), and when entering a cell with a jumping platform, you can only enter from the cell with the same x coordinate. Starting from the top of the course (y = 1) and crossing the bottom without deviating from the course (y ≥ Y), it is considered as one way of sliding and ends. Create a program that takes the course information as input and outputs the total number of slips. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: X Y c11 c21 ... cX1 c12 c22 ... cX2 :: c1Y c2Y ... cXY The first line gives the course size X, Y (1 ≤ X, Y ≤ 15). Course information is given in the Y line that follows. cij (one of 0, 1, or 2) is an integer that represents the information of the squares of x = i, y = j, where 0 is a movable square, 1 is a square with an obstacle, and 2 is a square with a jumping platform. Represents. The number of datasets does not exceed 50. Output For each input dataset, the number of patterns of how to slide the course is output on one line. Example Input 5 5 0 0 0 0 1 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 5 5 0 0 1 0 0 2 1 0 2 0 1 0 0 1 1 0 2 1 2 0 0 1 0 0 0 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 8 6 52694573 Submitted Solution: ``` """ Created by Jieyi on 8/16/16. """ def algorithm(): def down_jump(x, y, times): if x == r: out_map[x - 1][y] += times elif x == r - 1: out_map[x][y] += times elif in_map[x][y] == 2: down_jump(x + 2, y, times) else: out_map[x][y] += times while True: c, r = map(int, input().split()) if c == 0 and r == 0: break in_map = [] out_map = [[0 for _ in range(c)] for _ in range(r)] for _ in range(r): in_map.append(list(map(int, input().split()))) for i in range(r): if in_map[0][i] == 0: out_map[0][i] = 1 for i in range(r): for j in range(c): if in_map[i][j] == 0: # ???. if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0: out_map[i + 1][j - 1] += out_map[i][j] # ???. if i + 1 < r and in_map[i + 1][j] == 0: out_map[i + 1][j] += out_map[i][j] elif i + 1 < r and in_map[i + 1][j] == 2: down_jump(i + 1, j, out_map[i][j]) # ???. if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0: out_map[i + 1][j + 1] += out_map[i][j] print(sum(out_map[c - 1])) def main(): algorithm() if __name__ == '__main__': main() ```
instruction
0
96,889
3
193,778
No
output
1
96,889
3
193,779
Provide a correct Python 3 solution for this coding contest problem. <!-- Problem D --> Tally Counters A number of tally counters are placed in a row. Pushing the button on a counter will increment the displayed value by one, or, when the value is already the maximum, it goes down to one. All the counters are of the same model with the same maximum value. <image> Fig. D-1 Tally Counters Starting from the values initially displayed on each of the counters, you want to change all the displayed values to target values specified for each. As you don't want the hassle, however, of pushing buttons of many counters one be one, you devised a special tool. Using the tool, you can push buttons of one or more adjacent counters, one push for each, in a single operation. You can choose an arbitrary number of counters at any position in each operation, as far as they are consecutively lined up. How many operations are required at least to change the displayed values on counters to the target values? Input The input consists of multiple datasets, each in the following format. > n m > a1 a2 ... an > b1 b2 ... bn > Each dataset consists of 3 lines. The first line contains n (1 ≤ n ≤ 1000) and m (1 ≤ m ≤ 10000), the number of counters and the maximum value displayed on counters, respectively. The second line contains the initial values on counters, ai (1 ≤ ai ≤ m), separated by spaces. The third line contains the target values on counters, bi (1 ≤ bi ≤ m), separated by spaces. The end of the input is indicated by a line containing two zeros. The number of datasets does not exceed 100. Output For each dataset, print in a line the minimum number of operations required to make all of the counters display the target values. Sample Input 4 5 2 3 1 4 2 5 5 2 3 100 1 10 100 1 10 100 5 10000 4971 7482 1238 8523 1823 3287 9013 9812 297 1809 0 0 Output for the Sample Input 4 0 14731 Example Input 4 5 2 3 1 4 2 5 5 2 3 100 1 10 100 1 10 100 5 10000 4971 7482 1238 8523 1823 3287 9013 9812 297 1809 0 0 Output 4 0 14731
instruction
0
96,914
3
193,828
"Correct Solution: ``` import sys readline = sys.stdin.readline write = sys.stdout.write def solve(C, N, M, range = range, min = min): K = N // 4 + 1 S = [0]*K T = [0]*K U = [0]*(K+1) for i in range(N-1): U[0] = 10**18 for j in range(K): U[j+1] = min(U[j], S[j]) k = K-1 ci = C[i]; cj = C[i+1] r = 10**18 for j in range(K-1, -1, -1): while ci + k*M > cj + j*M: r = min(r, ci + k*M + S[k]) k -= 1 T[j] = min(r - j*M - cj, U[k+1]) S, T = T, S ci = C[-1] for i in range(K): S[i] += ci + i*M write("%d\n" % min(S)) while 1: N, M = map(int, readline().split()) if N == 0: break *A, = map(int, readline().split()) *B, = map(int, readline().split()) C = [(b - a) % M for a, b in zip(A, B)] solve(C, N, M) ```
output
1
96,914
3
193,829
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events. A destructive fire raged through the Forest, and several trees were damaged by it. Precisely speaking, you have a n × m rectangle map which represents the damaged part of the Forest. The damaged trees were marked as "X" while the remaining ones were marked as ".". You are sure that all burnt trees are shown on the map. All the trees outside the map are undamaged. The firemen quickly extinguished the fire, and now they are investigating the cause of it. The main version is that there was an arson: at some moment of time (let's consider it as 0) some trees were set on fire. At the beginning of minute 0, only the trees that were set on fire initially were burning. At the end of each minute, the fire spread from every burning tree to each of 8 neighboring trees. At the beginning of minute T, the fire was extinguished. The firemen want to find the arsonists as quickly as possible. The problem is, they know neither the value of T (how long the fire has been raging) nor the coordinates of the trees that were initially set on fire. They want you to find the maximum value of T (to know how far could the arsonists escape) and a possible set of trees that could be initially set on fire. Note that you'd like to maximize value T but the set of trees can be arbitrary. Input The first line contains two integer n and m (1 ≤ n, m ≤ 10^6, 1 ≤ n ⋅ m ≤ 10^6) — the sizes of the map. Next n lines contain the map. The i-th line corresponds to the i-th row of the map and contains m-character string. The j-th character of the i-th string is "X" if the corresponding tree is burnt and "." otherwise. It's guaranteed that the map contains at least one "X". Output In the first line print the single integer T — the maximum time the Forest was on fire. In the next n lines print the certificate: the map (n × m rectangle) where the trees that were set on fire are marked as "X" and all other trees are marked as ".". Examples Input 3 6 XXXXXX XXXXXX XXXXXX Output 1 ...... .X.XX. ...... Input 10 10 .XXXXXX... .XXXXXX... .XXXXXX... .XXXXXX... .XXXXXXXX. ...XXXXXX. ...XXXXXX. ...XXXXXX. ...XXXXXX. .......... Output 2 .......... .......... ...XX..... .......... .......... .......... .....XX... .......... .......... .......... Input 4 5 X.... ..XXX ..XXX ..XXX Output 0 X.... ..XXX ..XXX ..XXX Submitted Solution: ``` import os, sys, math import collections #res = solve('(R' + ('(R)R' * 2) + ')') if os.path.exists('testing'): name = os.path.basename(__file__) if name.endswith('.py'): name = name[:-3] src = open(name + '.in.txt', encoding='utf8') input = src.readline sy, sx = map(int, input().strip().split()) data = [ [0] * (sx + 2) ] for y in range(0, sy): data.append([0] + [ 1 if q == 'X' else 0 for q in input().strip() ] + [0]) data.append([0] * (sx + 2)) def print_data(): return for y in data: print(''.join(map(str, y))) def solve(): ranges_h = [ [ (x, x) for x in range(sx + 2) ] for _ in range(sy + 2) ] ranges_w = [ [ (y, y) for _ in range(sx + 2) ] for y in range(sy + 2) ] colcount = [ 0 ] * (sx + 2) for y in range(1, sy + 1): rowcount = 0 for x in range(1, sx + 1): if data[y][x]: colcount[x] += 1 rowcount += 1 else: tmp = (y - colcount[x], y - 1) for yy in range(y - colcount[x], y): ranges_h[yy][x] = tmp tmp = (x - rowcount, x - 1) for xx in range(x - rowcount, x): ranges_w[y][xx] = tmp rowcount = 0 colcount[x] = 0 else: x += 1 tmp = (x - rowcount, x) for xx in range(x - rowcount, x): ranges_w[y][xx] = (x - rowcount, x) else: y += 1 for x in range(1, sx + 1): tmp = (y - colcount[x], y - 1) for yy in range(y - colcount[x], y): ranges_h[yy][x] = tmp def calc_r_w(x, y, dx): rw = ranges_w[y][x] if dx < 0: rw = x - rw[0] else: rw = rw[1] - x return rw def calc_r_h(x, y, dy): rh = ranges_h[y][x] if dy < 0: rh = y - rh[0] else: rh = rh[1] - y return rh max_T = 99999999 found = None print_data() def calc_dxdyr(x, y): max_r = 0 mdx = mdy = None for dx, dy in ((-1, -1), (-1, 1), (1, -1), (1, 1)): min_r_w = calc_r_w(x, y, dx) min_r_h = calc_r_h(x, y, dy) r = 1 while True: min_r_w2 = calc_r_w(x, y + dy * r, dx) min_r_h2 = calc_r_h(x + dx * r, y, dy) min_r_w = min(min_r_w, min_r_w2) min_r_h = min(min_r_h, min_r_h2) if min_r_w <= r or min_r_h <= r: break r += 1 if r > max_r: max_r = r mdx = dx mdy = dy return max_r, mdx, mdy for y in range(1, sy + 1): for x in range(1, sx + 1): if data[y][x] != 1: continue for dx, dy in ((-1, -1), (-1, 1), (1, -1), (1, 1)): if data[y - dy][x - dx] == 0 and data[y - dy][x] == 0 and data[y][x - dx] == 0: break else: continue min_r_w = calc_r_w(x, y, dx) min_r_h = calc_r_h(x, y, dy) r = 1 while True: min_r_w2 = calc_r_w(x, y + dy * r, dx) min_r_h2 = calc_r_h(x + dx * r, y, dy) min_r_w = min(min_r_w, min_r_w2) min_r_h = min(min_r_h, min_r_h2) if min_r_w <= r or min_r_h <= r: break r += 1 if r < 2: max_T = 0 for y in data: for x in range(len(y)): if y[x]: y[x] = 7 print_data() return 0 max_T = min(max_T, r // 2) data[y + (r // 2) * dy][x + (r // 2) * dx] = 7 for yy in range(y, y + r * dy + dy, dy): for xx in range(x, x + r * dx + dx, dx): data[yy][xx] |= 2 print_data() return max_T T = solve() print(T) for y in range(1, sy + 1): print(''.join('X' if data[y][x] == 7 else '.' for x in range(1, sx + 1))) ```
instruction
0
97,081
3
194,162
No
output
1
97,081
3
194,163
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events. A destructive fire raged through the Forest, and several trees were damaged by it. Precisely speaking, you have a n × m rectangle map which represents the damaged part of the Forest. The damaged trees were marked as "X" while the remaining ones were marked as ".". You are sure that all burnt trees are shown on the map. All the trees outside the map are undamaged. The firemen quickly extinguished the fire, and now they are investigating the cause of it. The main version is that there was an arson: at some moment of time (let's consider it as 0) some trees were set on fire. At the beginning of minute 0, only the trees that were set on fire initially were burning. At the end of each minute, the fire spread from every burning tree to each of 8 neighboring trees. At the beginning of minute T, the fire was extinguished. The firemen want to find the arsonists as quickly as possible. The problem is, they know neither the value of T (how long the fire has been raging) nor the coordinates of the trees that were initially set on fire. They want you to find the maximum value of T (to know how far could the arsonists escape) and a possible set of trees that could be initially set on fire. Note that you'd like to maximize value T but the set of trees can be arbitrary. Input The first line contains two integer n and m (1 ≤ n, m ≤ 10^6, 1 ≤ n ⋅ m ≤ 10^6) — the sizes of the map. Next n lines contain the map. The i-th line corresponds to the i-th row of the map and contains m-character string. The j-th character of the i-th string is "X" if the corresponding tree is burnt and "." otherwise. It's guaranteed that the map contains at least one "X". Output In the first line print the single integer T — the maximum time the Forest was on fire. In the next n lines print the certificate: the map (n × m rectangle) where the trees that were set on fire are marked as "X" and all other trees are marked as ".". Examples Input 3 6 XXXXXX XXXXXX XXXXXX Output 1 ...... .X.XX. ...... Input 10 10 .XXXXXX... .XXXXXX... .XXXXXX... .XXXXXX... .XXXXXXXX. ...XXXXXX. ...XXXXXX. ...XXXXXX. ...XXXXXX. .......... Output 2 .......... .......... ...XX..... .......... .......... .......... .....XX... .......... .......... .......... Input 4 5 X.... ..XXX ..XXX ..XXX Output 0 X.... ..XXX ..XXX ..XXX Submitted Solution: ``` h, w = map(int, input().split()) a = [input() for i in range(h)] ruiseki = [[0]*(w+1) for i in range(h+1)] for i in range(h): for j in range(w): if a[i][j] == "X": ruiseki[i+1][j+1] = ruiseki[i+1][j] + 1 else: ruiseki[i+1][j+1] = ruiseki[i+1][j] for i in range(h): for j in range(w): ruiseki[i+1][j+1] += ruiseki[i][j+1] def solve(mid): cnt = 0 num = mid*mid visited = [[False]*w for i in range(h)] for i in range(h)[::-1]: for j in range(w)[::-1]: if i+mid < h+1 and j+mid < w+1: res = ruiseki[i+mid][j+mid] + ruiseki[i][j] - ruiseki[i+mid][j] - ruiseki[i][j+mid] if res == num: for ii in range(i,i+mid): for jj in range(j,j+mid): if visited[ii][jj]: break visited[ii][jj] = True cnt += 1 if ruiseki[h][w] == cnt: return True else: return False ok = 1 ng = 10**3 + 1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if solve(mid): ok = mid else: ng = mid ok = (ok-1) // 2 size = (ok*2+1)**2 ans = [["."]*w for i in range(h)] for i in range(h): for j in range(w): ii, jj = i - ok, j - ok iii, jjj = i + ok, j + ok if 0 <= ii < h and 0 <= jj < w and 0 <= iii < h and 0 <= jjj < w: if ruiseki[iii+1][jjj+1] + ruiseki[ii][jj] - ruiseki[iii+1][jj] - ruiseki[ii][jjj+1] == size: ans[i][j] = "X" print(ok) for i in ans: print("".join(i)) ```
instruction
0
97,082
3
194,164
No
output
1
97,082
3
194,165
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events. A destructive fire raged through the Forest, and several trees were damaged by it. Precisely speaking, you have a n × m rectangle map which represents the damaged part of the Forest. The damaged trees were marked as "X" while the remaining ones were marked as ".". You are sure that all burnt trees are shown on the map. All the trees outside the map are undamaged. The firemen quickly extinguished the fire, and now they are investigating the cause of it. The main version is that there was an arson: at some moment of time (let's consider it as 0) some trees were set on fire. At the beginning of minute 0, only the trees that were set on fire initially were burning. At the end of each minute, the fire spread from every burning tree to each of 8 neighboring trees. At the beginning of minute T, the fire was extinguished. The firemen want to find the arsonists as quickly as possible. The problem is, they know neither the value of T (how long the fire has been raging) nor the coordinates of the trees that were initially set on fire. They want you to find the maximum value of T (to know how far could the arsonists escape) and a possible set of trees that could be initially set on fire. Note that you'd like to maximize value T but the set of trees can be arbitrary. Input The first line contains two integer n and m (1 ≤ n, m ≤ 10^6, 1 ≤ n ⋅ m ≤ 10^6) — the sizes of the map. Next n lines contain the map. The i-th line corresponds to the i-th row of the map and contains m-character string. The j-th character of the i-th string is "X" if the corresponding tree is burnt and "." otherwise. It's guaranteed that the map contains at least one "X". Output In the first line print the single integer T — the maximum time the Forest was on fire. In the next n lines print the certificate: the map (n × m rectangle) where the trees that were set on fire are marked as "X" and all other trees are marked as ".". Examples Input 3 6 XXXXXX XXXXXX XXXXXX Output 1 ...... .X.XX. ...... Input 10 10 .XXXXXX... .XXXXXX... .XXXXXX... .XXXXXX... .XXXXXXXX. ...XXXXXX. ...XXXXXX. ...XXXXXX. ...XXXXXX. .......... Output 2 .......... .......... ...XX..... .......... .......... .......... .....XX... .......... .......... .......... Input 4 5 X.... ..XXX ..XXX ..XXX Output 0 X.... ..XXX ..XXX ..XXX Submitted Solution: ``` import os, sys, math import collections #res = solve('(R' + ('(R)R' * 2) + ')') if os.path.exists('testing'): name = os.path.basename(__file__) if name.endswith('.py'): name = name[:-3] src = open(name + '.in.txt', encoding='utf8') input = src.readline sy, sx = map(int, input().strip().split()) data = [ [0] * (sx + 2) ] for y in range(0, sy): data.append([0] + [ 1 if q == 'X' else 0 for q in input().strip() ] + [0]) data.append([0] * (sx + 2)) def print_data(): for y in data: print(''.join(map(str, y))) def solve(): ranges_h = [ [ (x, x) for x in range(sx + 2) ] for _ in range(sy + 2) ] ranges_w = [ [ (y, y) for _ in range(sx + 2) ] for y in range(sy + 2) ] colcount = [ 0 ] * (sx + 2) for y in range(1, sy + 1): rowcount = 0 for x in range(1, sx + 1): if data[y][x]: colcount[x] += 1 rowcount += 1 else: tmp = (y - colcount[x], y - 1) for yy in range(y - colcount[x], y): ranges_h[yy][x] = tmp tmp = (x - rowcount, x - 1) for xx in range(x - rowcount, x): ranges_w[y][xx] = tmp rowcount = 0 colcount[x] = 0 else: x += 1 tmp = (x - rowcount, x - 1) for xx in range(x - rowcount, x): ranges_w[y][xx] = tmp else: y += 1 for x in range(1, sx + 1): tmp = (y - colcount[x], y - 1) for yy in range(y - colcount[x], y): ranges_h[yy][x] = tmp max_T = 99999999 for y in range(1, sy + 1): for x in range(1, sx + 1): if data[y][x]: v = ranges_w[y][x] v = (v[1] - v[0]) // 2 if v < max_T: max_T = v v = ranges_h[y][x] v = (v[1] - v[0]) // 2 if v < max_T: max_T = v if max_T > 0: for y in range(1 + max_T, sy + 1, 1): rowcount = 0 for x in range(1, sx + 1): if data[y][x]: min_h, max_h = ranges_h[y][x] if min_h + max_T <= y <= max_h - max_T: rowcount += 1 else: rowcount = 0 if rowcount > max_T * 2: data[y][x - max_T] = 2 #print_data() return max_T T = solve() print(T) for y in range(1, sy + 1): print(''.join('X' if data[y][x] == 2 else '.' for x in range(1, sx + 1))) ```
instruction
0
97,083
3
194,166
No
output
1
97,083
3
194,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events. A destructive fire raged through the Forest, and several trees were damaged by it. Precisely speaking, you have a n × m rectangle map which represents the damaged part of the Forest. The damaged trees were marked as "X" while the remaining ones were marked as ".". You are sure that all burnt trees are shown on the map. All the trees outside the map are undamaged. The firemen quickly extinguished the fire, and now they are investigating the cause of it. The main version is that there was an arson: at some moment of time (let's consider it as 0) some trees were set on fire. At the beginning of minute 0, only the trees that were set on fire initially were burning. At the end of each minute, the fire spread from every burning tree to each of 8 neighboring trees. At the beginning of minute T, the fire was extinguished. The firemen want to find the arsonists as quickly as possible. The problem is, they know neither the value of T (how long the fire has been raging) nor the coordinates of the trees that were initially set on fire. They want you to find the maximum value of T (to know how far could the arsonists escape) and a possible set of trees that could be initially set on fire. Note that you'd like to maximize value T but the set of trees can be arbitrary. Input The first line contains two integer n and m (1 ≤ n, m ≤ 10^6, 1 ≤ n ⋅ m ≤ 10^6) — the sizes of the map. Next n lines contain the map. The i-th line corresponds to the i-th row of the map and contains m-character string. The j-th character of the i-th string is "X" if the corresponding tree is burnt and "." otherwise. It's guaranteed that the map contains at least one "X". Output In the first line print the single integer T — the maximum time the Forest was on fire. In the next n lines print the certificate: the map (n × m rectangle) where the trees that were set on fire are marked as "X" and all other trees are marked as ".". Examples Input 3 6 XXXXXX XXXXXX XXXXXX Output 1 ...... .X.XX. ...... Input 10 10 .XXXXXX... .XXXXXX... .XXXXXX... .XXXXXX... .XXXXXXXX. ...XXXXXX. ...XXXXXX. ...XXXXXX. ...XXXXXX. .......... Output 2 .......... .......... ...XX..... .......... .......... .......... .....XX... .......... .......... .......... Input 4 5 X.... ..XXX ..XXX ..XXX Output 0 X.... ..XXX ..XXX ..XXX Submitted Solution: ``` n,m = map(int,input().split()) A = ['.' + input()+'.' for i in range(n)] A = ['.' *(m+2)] + A +['.'*(m+2)] B = dict() Res = set() for i in range(n+2): for j in range(m+2): if A[i][j] == 'X': if A[i+1][j] == 'X': if (i,j) not in B.keys(): B[(i,j)] = [(i+1,j)] else: B[(i,j)].append((i+1,j)) if A[i+1][j+1] == 'X': if (i,j) not in B.keys(): B[(i,j)] = [(i+1,j+1)] else: B[(i,j)].append((i+1,j+1)) if A[i+1][j-1] == 'X': if (i,j) not in B.keys(): B[(i,j)] = [(i+1,j-1)] else: B[(i,j)].append((i+1,j-1)) if A[i][j+1] == 'X': if (i,j) not in B.keys(): B[(i,j)] = [(i,j+1)] else: B[(i,j)].append((i,j+1)) if A[i][j-1] == 'X': if (i,j) not in B.keys(): B[(i,j)] = [(i,j-1)] else: B[(i,j)].append((i,j-1)) if A[i-1][j+1] == 'X': if (i,j) not in B.keys(): B[(i,j)] = [(i-1,j+1)] else: B[(i,j)].append((i-1,j+1)) if A[i-1][j] == 'X': if (i,j) not in B.keys(): B[(i,j)] = [(i-1,j)] else: B[(i,j)].append((i-1,j)) if A[i-1][j-1] == 'X': if (i,j) not in B.keys(): B[(i,j)] = [(i-1,j-1)] else: B[(i,j)].append((i-1,j-1)) T = [[0 for i in range((m+2))]for j in range(n+2)] que = [] for i in range(n+2): for j in range(m+2): if A[i][j] == 'X': if len(B[(i,j)]) < 8: T[i][j] = 1 que.append((i,j)) while len(que) > 0: a,b = que.pop(0) k = 0 for i in B[(a,b)]: if T[i[0]][i[1]] == 0: T[i[0]][i[1]] = T[a][b] + 1 k = 1 que.append(i) if T[i[0]][i[1]] > T[a][b]: k = 1 if k == 0: Res.add(i) print(max([max(i) for i in T])-1) R = [['.' for i in range((m))]for j in range(n)] for i in Res: a,b = i R[a][b] = 'X' for i in R: for j in i: print(j,end = '') print('') ```
instruction
0
97,084
3
194,168
No
output
1
97,084
3
194,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated. Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed. Input The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons. The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj if i ≠ j. Output Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. Examples Input 4 1 9 3 1 6 1 7 4 Output 1 Input 7 1 1 2 1 3 1 4 1 5 1 6 1 7 1 Output 3 Note For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2. For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. Submitted Solution: ``` from bisect import bisect_left,bisect_right n=int(input()) positon=[] poser=[] for i in range(n): x,u=map(int,input().split()) poser.append([x,u]) positon.append(x) poser.sort() positon.sort() dp=[0 for i in range(n)] for i in range(0,n): value=bisect_left(positon,poser[i][0]-poser[i][1])-1 dp[i]=dp[value]+1 print(n-max(dp)) ```
instruction
0
97,449
3
194,898
Yes
output
1
97,449
3
194,899
Provide tags and a correct Python 3 solution for this coding contest problem. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise.
instruction
0
97,571
3
195,142
Tags: implementation Correct Solution: ``` N = int(input()) first = [] second = [] for i in range(N): first.append([s for s in input()]) for i in range(N): second.append([s for s in input()]) def rotate_90(matrix): return list(zip(*matrix[::-1])) def flip(matrix): return matrix[::-1] def compare_matrices(first, second): for i in range(N): for j in range(N): if first[i][j] != second[i][j]: return False return True def wrap(first, second): if compare_matrices(first, second) == True: return 'Yes' hold_first = first[::] for _ in range(3): first = rotate_90(first) if compare_matrices(first, second) == True: return 'Yes' first = hold_first first = flip(first) if compare_matrices(first, second) == True: return 'Yes' for _ in range(3): first = rotate_90(first) if compare_matrices(first, second) == True: return 'Yes' return 'No' print(wrap(first, second)) ```
output
1
97,571
3
195,143
Provide tags and a correct Python 3 solution for this coding contest problem. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise.
instruction
0
97,572
3
195,144
Tags: implementation Correct Solution: ``` N = int(input()) s1 = [list(input()) for i in range(N)] s2 = [list(input()) for i in range(N)] def rotate(s): ret = [[None for i in range(N)] for j in range(N)] for i in range(N): for j in range(N): ret[i][j] = s[j][N-1-i] return ret def v_mirror(s): return list(reversed(s)) def h_mirror(s): return [list(reversed(row)) for row in s] def solve(): global s1 for i in range(4): if s1 == s2: return True if v_mirror(s1) == s2: return True if h_mirror(s1) == s2: return True if v_mirror(h_mirror(s1)) == s2: return True s1 = rotate(s1) return False print('Yes' if solve() else 'No') ```
output
1
97,572
3
195,145
Provide tags and a correct Python 3 solution for this coding contest problem. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise.
instruction
0
97,573
3
195,146
Tags: implementation Correct Solution: ``` import copy n = int(input()) flg=0 mat1 = [] mat2 = [] mats = [] for i in range(0, n): mat1.append(tuple(input().strip())) for i in range(0, n): mat2.append(tuple(input().strip())) mats.append(mat2) matu = copy.copy(mat2) matv = copy.copy(mat2) matv = list(zip(*matv)) mats.append(matv) mattem = copy.copy(matu) for i in range(0, 3): mattem = list(zip(*list(reversed(mattem)))) mats.append(mattem) mattem = copy.copy(matv) for i in range(0, 3): mattem = list(zip(*list(reversed(mattem)))) mats.append(mattem) flg = 0 for cmat in mats: flg2 = 1 for ri in range(0, n): if cmat[ri]!=mat1[ri]: flg2=0 break if flg2==1: flg=1 break if flg==1: print("Yes") else: print("No") ```
output
1
97,573
3
195,147
Provide tags and a correct Python 3 solution for this coding contest problem. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise.
instruction
0
97,574
3
195,148
Tags: implementation Correct Solution: ``` n=int(input()) ns=[] for i in range(n): s=input() ns.append(s) ns2=[] for i in range(n): s=input() ns2.append(s) def rotate(i,j): return j,n-1-i def flip(i,j): return j,i def main(): same=True for i in range(n): # 0 for j in range(n): if ns[i][j]!=ns2[i][j]: same=False break if same==False: break if same: return True same=True for i in range(n): # 1 for j in range(n): a, b = rotate(i, j) if ns[i][j] != ns2[a][b]: same = False break if same == False: break if same: return True same=True for i in range(n): # 2 for j in range(n): a, b = rotate(i, j) a, b = rotate(a, b) if ns[i][j] != ns2[a][b]: same = False break if same == False: break if same: return True same=True for i in range(n): for j in range(n): # 3 a, b = rotate(i, j) a, b = rotate(a, b) a, b = rotate(a, b) if ns[i][j] != ns2[a][b]: same = False break if same == False: break if same: return True same=True for i in range(n): # 0 for j in range(n): a,b=flip(i,j) if ns[a][b]!=ns2[i][j]: same=False break if same==False: break if same: return True same=True for i in range(n): # 1 for j in range(n): a, b = rotate(i, j) a, b = flip(a, b) if ns[i][j] != ns2[a][b]: same = False break if same == False: break if same: return True same=True for i in range(n): # 2 for j in range(n): a, b = rotate(i, j) a, b = rotate(a, b) a, b = flip(a, b) if ns[i][j] != ns2[a][b]: same = False break if same == False: break if same: return True same=True for i in range(n): for j in range(n): # 3 a, b = rotate(i, j) a, b = rotate(a, b) a, b = rotate(a, b) a, b = flip(a, b) if ns[i][j] != ns2[a][b]: same = False break if same == False: break if same: return True else: return False if main(): print('Yes') else: print('No') ```
output
1
97,574
3
195,149
Provide tags and a correct Python 3 solution for this coding contest problem. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise.
instruction
0
97,575
3
195,150
Tags: implementation Correct Solution: ``` N = int(input()) m1 = [] m2 = [] ms = [] for n in range(N): m1.append(input()) for n in range(N): m2.append(input()) ms = [ m2, [x[::-1] for x in m2], [x for x in reversed(m2)], ] a = [] for m in ms: a.append(m) a.append([x[::-1] for x in reversed(m)]) a.append([''.join(m[j][i] for j in range(N - 1, -1, -1)) for i in range(N)]) a.append([''.join(m[j][i] for j in range(N)) for i in range(N - 1, -1, -1)]) ms = a print(['NO', 'YES'][m1 in ms]) ```
output
1
97,575
3
195,151
Provide tags and a correct Python 3 solution for this coding contest problem. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise.
instruction
0
97,576
3
195,152
Tags: implementation Correct Solution: ``` #!/usr/bin/python3 import copy def rotate90(n, f): return [[f[n - j - 1][i] for j in range(n)] for i in range(n)] def fliphor(n, f): return [[f[i][n - j - 1] for j in range(n)] for i in range(n)] def flipver(n, f): return [[f[n - i - 1][j] for j in range(n)] for i in range(n)] def eq(n, f, g): for i in range(n): for j in range(n): if f[i][j] != g[i][j]: return False return True n = int(input()) f = [list(input()) for i in range(n)] g = [list(input()) for i in range(n)] for doflipv in range(2): for dofliph in range(2): for nrot in range(4): h = copy.deepcopy(f) if dofliph == 1: h = fliphor(n, h) if doflipv == 1: h = flipver(n, h) for i in range(nrot): h = rotate90(n, h) if eq(n, h, g): print("Yes") exit(0) print("No") ```
output
1
97,576
3
195,153
Provide tags and a correct Python 3 solution for this coding contest problem. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise.
instruction
0
97,577
3
195,154
Tags: implementation Correct Solution: ``` from collections import deque, defaultdict, Counter from itertools import product, groupby, permutations, combinations from math import gcd, floor, inf, log2, sqrt, log10 from bisect import bisect_right, bisect_left from statistics import mode from string import ascii_uppercase cases = int(input()) matrix1 = [] for _ in range(cases): matrix1.append(list(input())) matrix2 = [] for _ in range(cases): matrix2.append(list(input())) def transpose(matrix): return [list(x) for x in zip(*matrix)] def reverse_row(matrix): return matrix[::-1] def reverse_column(matrix): return [x[::-1] for x in matrix] def rotate_90(matrix): """this is counterclockwise, which is same as 270 clockwise""" return reverse_row(transpose(matrix)) def rotate_180(matrix): """same for both clockwise and counterclockwise""" return reverse_row(reverse_column(matrix)) def rotate_270(matrix): """this is counterclockwise, which is same as 90 clockwise""" return reverse_column(transpose(matrix)) if matrix1 == matrix2 or matrix1 == reverse_row(matrix2) or matrix1 == reverse_column(matrix2) \ or matrix1 == rotate_90(matrix2) or matrix1 == rotate_180(matrix2) or matrix1 == rotate_270(matrix2): print("Yes") exit() matrix2 = reverse_row(matrix2) if matrix1 == matrix2 or matrix1 == reverse_row(matrix2) or matrix1 == reverse_column(matrix2) \ or matrix1 == rotate_90(matrix2) or matrix1 == rotate_180(matrix2) or matrix1 == rotate_270(matrix2): print("Yes") exit() matrix2 = reverse_column(matrix2) if matrix1 == matrix2 or matrix1 == reverse_row(matrix2) or matrix1 == reverse_column(matrix2) \ or matrix1 == rotate_90(matrix2) or matrix1 == rotate_180(matrix2) or matrix1 == rotate_270(matrix2): print("Yes") exit() matrix2 = transpose(matrix2) if matrix1 == matrix2 or matrix1 == reverse_row(matrix2) or matrix1 == reverse_column(matrix2) \ or matrix1 == rotate_90(matrix2) or matrix1 == rotate_180(matrix2) or matrix1 == rotate_270(matrix2): print("Yes") exit() else: print("No") ```
output
1
97,577
3
195,155
Provide tags and a correct Python 3 solution for this coding contest problem. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise.
instruction
0
97,578
3
195,156
Tags: implementation Correct Solution: ``` def check(x, y): return ''.join([''.join(s) for s in x]) == ''.join([''.join(s) for s in y]) re = int(input()) a = [list(input()) for i in range(re)] b = [list(input()) for i in range(re)] for i in range(4): for j in range(2): if check(a, b): print('Yes') exit(0) b = b[::-1] for j in range(2): if check(a, b): print('Yes') exit(0) b = [s[::-1] for s in b] c = [['' for t in range(re)] for u in range(re)] for t in range(re): for u in range(re): c[t][u] = b[u][re - t - 1] b = c[:] if check(a, b): print('Yes') exit(0) print('No') ```
output
1
97,578
3
195,157
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise. Submitted Solution: ``` from sys import stdin n = int(stdin.readline()) def eq(m1, m2): for i in range(n): if m1[i] != m2[i]: return False return True def fleq(m1, m2): return eq(m1, m2) or eq(m1, fliph(m2)) or eq(m1, flipv(m2)) def fliph(m): return [row[::-1] for row in m] def flipv(m): return m[::-1] def rot(m): mr = ['' for _ in range(n)] for i in range(n): x = '' for j in range(n): x = x + m[j][n-i-1] mr[i] = x return mr u = [stdin.readline()[:-1] for _ in range(n)] v = [stdin.readline()[:-1] for _ in range(n)] v90 = rot(v) v180 = rot(v90) v270 = rot(v180) if fleq(u, v) or fleq(u, v90) or fleq(u, v180) or fleq(u, v270): print('Yes') else: print('No') ```
instruction
0
97,579
3
195,158
Yes
output
1
97,579
3
195,159
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise. Submitted Solution: ``` N = int(input()) map1 = [] map2 = [] for _ in range(N): map1 += [input()] for _ in range(N): map2 += [input()] equal1 = True equal2 = True equal3 = True equal4 = True equal5 = True equal6 = True equal7 = True equal8 = True for i in range(N): for j in range(N): if map1[i][j] != map2[i][j]: equal1 = False if map1[i][j] != map2[j][N - i - 1]: equal2 = False if map1[i][j] != map2[N - i - 1][N - j - 1]: equal3 = False if map1[i][j] != map2[N - j - 1][N - i - 1]: equal4 = False if map1[i][j] != map2[i][N - j - 1]: equal5 = False if map1[i][j] != map2[N - i - 1][j]: equal6 = False if map1[i][j] != map2[N - j - 1][i]: equal7 = False if map1[i][j] != map2[j][i]: equal8 = False if equal1 or equal2 or equal3 or equal4 or equal5 or equal6 or equal7 or equal8: print('yes') else: print('no') ```
instruction
0
97,580
3
195,160
Yes
output
1
97,580
3
195,161
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise. Submitted Solution: ``` n=int(input()) a=[] b=[] for i in range(n): a.append(input()) for i in range(n): b.append(input()) def h(d): c=[] for i in range(n): c.append(d[n-i-1]) return c def r(d): c=[] for i in range(n): temp="" for j in range(n): temp+=d[j][n-i-1] c.append(temp) return c yes=0 for i in range(4): if a==b: print('YES') yes=1 break a=r(a) if yes==0: a=h(a) for i in range(4): if a==b: print('YES') yes=1 break a=r(a) if yes==0: print('NO') ```
instruction
0
97,581
3
195,162
Yes
output
1
97,581
3
195,163
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise. Submitted Solution: ``` def solve(board): n=len(board) ans=0 for i in range(n): for j in range(n): if board[i][j] is 'X': ans+=2**(i*n+j) return ans def reverse_array(arr): for i in range(len(arr)): arr[i].reverse() def rotate(matrix, degree): if degree == 0: return matrix elif degree > 0: return rotate(zip(*matrix[::-1]), degree-90) else: return rotate(zip(*matrix)[::-1], degree+90) def make_list(board): board=list(board) arr=[] for i in range(len(list(board))): arr.append(list(board[i])) return arr def add_rotations(board,st): for i in range(4): st.add(solve(board)) reverse_array(board) st.add(solve(board)) reverse_array(board) board=make_list(rotate(board, 90)) n=int(input()) arr1=[] arr2=[] for _ in range(n): arr1.append(list(input().strip())) for _ in range(n): arr2.append(list(input().strip())) s=set() s.add(solve(arr1)) add_rotations(arr1,s) l1=len(s) #print(s,arr1,arr2) s.add(solve(arr2)) add_rotations(arr2,s) #print(s) l2=len(s) if l1==l2: print("Yes") else: print("No") ```
instruction
0
97,582
3
195,164
Yes
output
1
97,582
3
195,165
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise. Submitted Solution: ``` n = int(input()) def rot(l): return [list(reversed(x)) for x in zip(*l)] def reflect_h(new_l): l = new_l for i in range(len(l)): o = len(l[i]) for j in range(o // 2): temp = l[i][j] l[i][j] = l[i][o - j - 1] l[i][o - j - 1] = temp return l def reflect_v(new_l): l = new_l p = len(l) // 2 for i in range(p): temp = l[i] l[i] = l[p - i - 1] l[p - i - 1] = temp return l grid_1 = [] grid_2 = [] for i in range(n): grid_1.append([a for a in input()]) for i in range(n): grid_2.append([a for a in input()]) if grid_2 in [grid_1,rot(grid_1),rot(rot(grid_1)),rot(rot(rot(grid_1))),reflect_v(grid_1),rot(reflect_v(grid_1)),rot(rot(reflect_v(grid_1))),rot(rot(rot(reflect_v(grid_1)))),reflect_h(grid_1),rot(reflect_h(grid_1)),rot(rot(reflect_h(grid_1))),rot(rot(rot(reflect_h(grid_1))))]: print("Yes") else: print("No") print(grid_1) ```
instruction
0
97,583
3
195,166
No
output
1
97,583
3
195,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise. Submitted Solution: ``` ##https://codeforces.com/problemset/problem/958/A1 from copy import deepcopy def GenerateMap(n): positions = [] for i in range(0,n): positions.append([]) return positions def Rotate(a, times): rotated = [] for i in range(0,n): rotated.append([]) counter = len(a) for i in rotated: counter-=1 for j in a: i.append(j[counter]) for i in (0, times-1): counter = len(a) x = deepcopy(rotated) for j in rotated: j.clear() counter-=1 for k in x: j.append(k[counter]) return rotated def Flip(a): flipped = [] for i in reversed(a): flipped.append(i) return flipped def CheckMaps(a,b): if a == b: return "Yes" elif Rotate(a, 1) == b: return "Yes" elif Rotate(a, 2) == b: return "Yes" elif Rotate(a, 3) == b: return "Yes" elif Flip(a) == b: return "Yes" elif Flip(Rotate(a, 1)) == b: return "Yes" elif Flip(Rotate(a, 2)) == b: return "Yes" elif Flip(Rotate(a, 3)) == b: return "Yes" else: return "No" n = int(input()) a = GenerateMap(n) b = GenerateMap(n) for i in range(0,n): x = [] x[:] = input() a[i] = x for i in range(0,n): x = [] x[:] = input() b[i] = x print(CheckMaps(a,b)) ```
instruction
0
97,584
3
195,168
No
output
1
97,584
3
195,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise. Submitted Solution: ``` def vf(mtrx): mtrx = mtrx.copy() n = len(mtrx) for row in mtrx: for i in range(n // 2): tmp = row[n - i - 1] row[n - i - 1] = row[i] row[i] = tmp return mtrx def hf(mtrx): mtrx = mtrx.copy() n = len(mtrx) for j in range(n): for i in range(n // 2): tmp = mtrx[n - i - 1][j] mtrx[n - i - 1][j] = mtrx[i][j] mtrx[i][j] = tmp return mtrx def rotate(mtrx): n = len(mtrx) rmtrx = [] for i in range(n): row = [] for j in range(n): row.append(mtrx[j][i]) rmtrx.append(row) return rmtrx if __name__ == '__main__': n = int(input()) m1 = [] for _ in range(n): m1.append(list(input())) m2 = [] for _ in range(n): m2.append(list(input())) poss = False for i in range(4): if m1 == m2 or vf(m1) == m2 or hf(m1) == m2 or vf(hf(m1)) == m2: poss = True break m1 = rotate(m1) print('Yes' if poss else 'No') ```
instruction
0
97,585
3
195,170
No
output
1
97,585
3
195,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information. Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. Input The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format. Output The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. Examples Input 4 XOOO XXOO OOOO XXXX XOOO XOOO XOXO XOXX Output Yes Input 2 XX OO XO OX Output No Note In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise. Submitted Solution: ``` n = int(input()) def rot(l): return [list(reversed(x)) for x in zip(*l)] def reflect_h(new_l): for g in new_l: g = g[::-1] return new_l def reflect_v(new_l): l = new_l p = len(l) // 2 for i in range(p): temp = l[i] l[i] = l[p - i - 1] l[p - i - 1] = temp return l grid_1 = [] grid_2 = [] for i in range(n): r = list(input()) print(r) grid_1.append(r) for i in range(n): grid_2.append(list(input())) v = reflect_v(grid_1) h = reflect_h(grid_1) if grid_2 in [grid_1,rot(grid_1),rot(rot(grid_1)),rot(rot(rot(grid_1))),v,rot(v),rot(rot(v)),rot(rot(rot(v))),h,rot(h),rot(rot(h)),rot(rot(rot(h)))]: print("Yes") else: print("No") ```
instruction
0
97,586
3
195,172
No
output
1
97,586
3
195,173
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The campus has m rooms numbered from 0 to m - 1. Also the x-mouse lives in the campus. The x-mouse is not just a mouse: each second x-mouse moves from room i to the room i ⋅ x mod{m} (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of the x-mouse is unknown. You are responsible to catch the x-mouse in the campus, so you are guessing about minimum possible number of traps (one trap in one room) you need to place. You are sure that if the x-mouse enters a trapped room, it immediately gets caught. And the only observation you made is GCD (x, m) = 1. Input The only line contains two integers m and x (2 ≤ m ≤ 10^{14}, 1 ≤ x < m, GCD (x, m) = 1) — the number of rooms and the parameter of x-mouse. Output Print the only integer — minimum number of traps you need to install to catch the x-mouse. Examples Input 4 3 Output 3 Input 5 2 Output 2 Note In the first example you can, for example, put traps in rooms 0, 2, 3. If the x-mouse starts in one of this rooms it will be caught immediately. If x-mouse starts in the 1-st rooms then it will move to the room 3, where it will be caught. In the second example you can put one trap in room 0 and one trap in any other room since x-mouse will visit all rooms 1..m-1 if it will start in any of these rooms. Submitted Solution: ``` line = input().split() m = int(line[0]) x = int(line[1]) print(x) ```
instruction
0
97,834
3
195,668
No
output
1
97,834
3
195,669
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The campus has m rooms numbered from 0 to m - 1. Also the x-mouse lives in the campus. The x-mouse is not just a mouse: each second x-mouse moves from room i to the room i ⋅ x mod{m} (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of the x-mouse is unknown. You are responsible to catch the x-mouse in the campus, so you are guessing about minimum possible number of traps (one trap in one room) you need to place. You are sure that if the x-mouse enters a trapped room, it immediately gets caught. And the only observation you made is GCD (x, m) = 1. Input The only line contains two integers m and x (2 ≤ m ≤ 10^{14}, 1 ≤ x < m, GCD (x, m) = 1) — the number of rooms and the parameter of x-mouse. Output Print the only integer — minimum number of traps you need to install to catch the x-mouse. Examples Input 4 3 Output 3 Input 5 2 Output 2 Note In the first example you can, for example, put traps in rooms 0, 2, 3. If the x-mouse starts in one of this rooms it will be caught immediately. If x-mouse starts in the 1-st rooms then it will move to the room 3, where it will be caught. In the second example you can put one trap in room 0 and one trap in any other room since x-mouse will visit all rooms 1..m-1 if it will start in any of these rooms. Submitted Solution: ``` m, x = map(int, input().split()) o = 1 cx = (x * x) % m while cx != x: o += 1 cx = (cx * x) % m print(2 + (m-2) // o) ```
instruction
0
97,836
3
195,672
No
output
1
97,836
3
195,673
Provide tags and a correct Python 3 solution for this coding contest problem. You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a r × c grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Beingawesomeism, who do good for the sake of being good. The other religion is called Pushingittoofarism, who do murders for the sake of being bad. Oh, and you are actually not really all-powerful. You just have one power, which you can use infinitely many times! Your power involves missionary groups. When a missionary group of a certain country, say a, passes by another country b, they change the dominant religion of country b to the dominant religion of country a. In particular, a single use of your power is this: * You choose a horizontal 1 × x subgrid or a vertical x × 1 subgrid. That value of x is up to you; * You choose a direction d. If you chose a horizontal subgrid, your choices will either be NORTH or SOUTH. If you choose a vertical subgrid, your choices will either be EAST or WEST; * You choose the number s of steps; * You command each country in the subgrid to send a missionary group that will travel s steps towards direction d. In each step, they will visit (and in effect convert the dominant religion of) all s countries they pass through, as detailed above. * The parameters x, d, s must be chosen in such a way that any of the missionary groups won't leave the grid. The following image illustrates one possible single usage of your power. Here, A represents a country with dominant religion Beingawesomeism and P represents a country with dominant religion Pushingittoofarism. Here, we've chosen a 1 × 4 subgrid, the direction NORTH, and s = 2 steps. <image> You are a being which believes in free will, for the most part. However, you just really want to stop receiving murders that are attributed to your name. Hence, you decide to use your powers and try to make Beingawesomeism the dominant religion in every country. What is the minimum number of usages of your power needed to convert everyone to Beingawesomeism? With god, nothing is impossible. But maybe you're not god? If it is impossible to make Beingawesomeism the dominant religion in all countries, you must also admit your mortality and say so. Input The first line of input contains a single integer t (1 ≤ t ≤ 2⋅ 10^4) denoting the number of test cases. The first line of each test case contains two space-separated integers r and c denoting the dimensions of the grid (1 ≤ r, c ≤ 60). The next r lines each contains c characters describing the dominant religions in the countries. In particular, the j-th character in the i-th line describes the dominant religion in the country at the cell with row i and column j, where: * "A" means that the dominant religion is Beingawesomeism; * "P" means that the dominant religion is Pushingittoofarism. It is guaranteed that the grid will only contain "A" or "P" characters. It is guaranteed that the sum of the r ⋅ c in a single file is at most 3 ⋅ 10^6. Output For each test case, output a single line containing the minimum number of usages of your power needed to convert everyone to Beingawesomeism, or the string "MORTAL" (without quotes) if it is impossible to do so. Example Input 4 7 8 AAPAAAAA PPPPAAAA PPPPAAAA APAAPPPP APAPPAPP AAAAPPAP AAAAPPAA 6 5 AAAAA AAAAA AAPAA AAPAP AAAPP AAAPP 4 4 PPPP PPPP PPPP PPPP 3 4 PPPP PAAP PPPP Output 2 1 MORTAL 4 Note In the first test case, it can be done in two usages, as follows: Usage 1: <image> Usage 2: <image> In the second test case, it can be done with just one usage of the power. In the third test case, it is impossible to convert everyone to Beingawesomeism, so the answer is "MORTAL".
instruction
0
97,986
3
195,972
Tags: implementation, math Correct Solution: ``` # not my code, just an edit of https://codeforces.com/contest/1281/submission/66929709 import sys input = lambda: sys.stdin.readline().rstrip() for i in ' '*int(input()): a,b=map(int,input().split()) L=[] M=['']*b A=False P=False for j in ' '*a: s=input() if 'A' in s:A=True if 'P' in s:P=True for k in range(b): M[k]+=s[k] L.append(s) if not A: print('MORTAL') continue if not P: print(0) continue ss=L[0]+L[-1]+M[0]+M[-1] if 'P' not in L[0] or 'P' not in L[-1] or 'P' not in M[0] or 'P' not in M[-1]: print(1) continue if L[0][0]=='A' or L[0][-1]=='A' or L[-1][0]=='A' or L[-1][-1]=='A': print(2) continue A2=False for j in L: if 'P' not in j: A2=True for j in M: if 'P' not in j: A2=True if A2: print(2) continue if 'A' in ss:print(3) else:print(4) ```
output
1
97,986
3
195,973
Provide tags and a correct Python 3 solution for this coding contest problem. You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a r × c grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Beingawesomeism, who do good for the sake of being good. The other religion is called Pushingittoofarism, who do murders for the sake of being bad. Oh, and you are actually not really all-powerful. You just have one power, which you can use infinitely many times! Your power involves missionary groups. When a missionary group of a certain country, say a, passes by another country b, they change the dominant religion of country b to the dominant religion of country a. In particular, a single use of your power is this: * You choose a horizontal 1 × x subgrid or a vertical x × 1 subgrid. That value of x is up to you; * You choose a direction d. If you chose a horizontal subgrid, your choices will either be NORTH or SOUTH. If you choose a vertical subgrid, your choices will either be EAST or WEST; * You choose the number s of steps; * You command each country in the subgrid to send a missionary group that will travel s steps towards direction d. In each step, they will visit (and in effect convert the dominant religion of) all s countries they pass through, as detailed above. * The parameters x, d, s must be chosen in such a way that any of the missionary groups won't leave the grid. The following image illustrates one possible single usage of your power. Here, A represents a country with dominant religion Beingawesomeism and P represents a country with dominant religion Pushingittoofarism. Here, we've chosen a 1 × 4 subgrid, the direction NORTH, and s = 2 steps. <image> You are a being which believes in free will, for the most part. However, you just really want to stop receiving murders that are attributed to your name. Hence, you decide to use your powers and try to make Beingawesomeism the dominant religion in every country. What is the minimum number of usages of your power needed to convert everyone to Beingawesomeism? With god, nothing is impossible. But maybe you're not god? If it is impossible to make Beingawesomeism the dominant religion in all countries, you must also admit your mortality and say so. Input The first line of input contains a single integer t (1 ≤ t ≤ 2⋅ 10^4) denoting the number of test cases. The first line of each test case contains two space-separated integers r and c denoting the dimensions of the grid (1 ≤ r, c ≤ 60). The next r lines each contains c characters describing the dominant religions in the countries. In particular, the j-th character in the i-th line describes the dominant religion in the country at the cell with row i and column j, where: * "A" means that the dominant religion is Beingawesomeism; * "P" means that the dominant religion is Pushingittoofarism. It is guaranteed that the grid will only contain "A" or "P" characters. It is guaranteed that the sum of the r ⋅ c in a single file is at most 3 ⋅ 10^6. Output For each test case, output a single line containing the minimum number of usages of your power needed to convert everyone to Beingawesomeism, or the string "MORTAL" (without quotes) if it is impossible to do so. Example Input 4 7 8 AAPAAAAA PPPPAAAA PPPPAAAA APAAPPPP APAPPAPP AAAAPPAP AAAAPPAA 6 5 AAAAA AAAAA AAPAA AAPAP AAAPP AAAPP 4 4 PPPP PPPP PPPP PPPP 3 4 PPPP PAAP PPPP Output 2 1 MORTAL 4 Note In the first test case, it can be done in two usages, as follows: Usage 1: <image> Usage 2: <image> In the second test case, it can be done with just one usage of the power. In the third test case, it is impossible to convert everyone to Beingawesomeism, so the answer is "MORTAL".
instruction
0
97,987
3
195,974
Tags: implementation, math Correct Solution: ``` #qn given an arr of size n for every i position find a min j such that j>i and arr[j]>arr[i] #it prints the position of the nearest . import sys input = sys.stdin.readline #qn given an arr of size n for every i position find a min j such that j>i and arr[j]>arr[i] #it prints the position of the nearest . # import sys import heapq import copy import math #heapq.heapify(li) # #heapq.heappush(li,4) # #heapq.heappop(li) # # & Bitwise AND Operator 10 & 7 = 2 # | Bitwise OR Operator 10 | 7 = 15 # ^ Bitwise XOR Operator 10 ^ 7 = 13 # << Bitwise Left Shift operator 10<<2 = 40 # >> Bitwise Right Shift Operator '''############ ---- Input Functions ---- #######Start#####''' def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ############ ---- Input Functions ---- #######End # ##### class Node: def _init_(self,val): self.data = val self.left = None self.right = None ##to initialize wire : object_name= node(val)##to create a new node ## can also be used to create linked list class fen_tree: """Implementation of a Binary Indexed Tree (Fennwick Tree)""" #def __init__(self, list): # """Initialize BIT with list in O(n*log(n))""" # self.array = [0] * (len(list) + 1) # for idx, val in enumerate(list): # self.update(idx, val) def __init__(self, list): """"Initialize BIT with list in O(n)""" self.array = [0] + list for idx in range(1, len(self.array)): idx2 = idx + (idx & -idx) if idx2 < len(self.array): self.array[idx2] += self.array[idx] def prefix_query(self, idx): """Computes prefix sum of up to including the idx-th element""" # idx += 1 result = 0 while idx: result += self.array[idx] idx -= idx & -idx return result def prints(self): print(self.array) return # for i in self.array: # print(i,end = " ") # return def range_query(self, from_idx, to_idx): """Computes the range sum between two indices (both inclusive)""" return self.prefix_query(to_idx) - self.prefix_query(from_idx - 1) def update(self, idx, add): """Add a value to the idx-th element""" # idx += 1 while idx < len(self.array): self.array[idx] += add idx += idx & -idx def pre_sum(arr): #"""returns the prefix sum inclusive ie ith position in ans represent sum from 0 to ith position""" p = [0] for i in arr: p.append(p[-1] + i) p.pop(0) return p def pre_back(arr): #"""returns the prefix sum inclusive ie ith position in ans represent sum from 0 to ith position""" p = [0] for i in arr: p.append(p[-1] + i) p.pop(0) return p def bin_search(arr,l,r,val):#strickly greater if arr[r] <= val: return r+1 if r-l < 2: if arr[l]>val: return l else: return r mid = int((l+r)/2) if arr[mid] <= val: return bin_search(arr,mid,r,val) else: return bin_search(arr,l,mid,val) def search_leftmost(arr,val): def helper(arr,l,r,val): # print(arr) print(l,r) if arr[l] == val: return l if r -l <=1: if arr[r] == val: return r else: print("not found") return mid = int((r+l)/2) if arr[mid] >= val: return helper(arr,l,mid,val) else: return helper(arr,mid,r,val) return helper(arr,0,len(arr)-1,val) def search_rightmost(arr,val): def helper(arr,l,r,val): # print(arr) print(l,r) if arr[r] == val: return r if r -l <=1: if arr[l] == val: return r else: print("not found") return mid = int((r+l)/2) if arr[mid] > val: return helper(arr,l,mid,val) else: return helper(arr,mid,r,val) return helper(arr,0,len(arr)-1,val) def pr_list(a): print(*a, sep=" ") def main(): tests = inp() # tests = 1 mod = 1000000007 limit = 10**18 # print(limit) # if tests == 4: # # for i in range(4): # [r,c] = inlt() # grid = [] # for i in range(r): # grid.append(insr()) # print(2) # [r,c] = inlt() # grid = [] # for i in range(r): # grid.append(insr()) # print(1) # [r,c] = inlt() # grid = [] # for i in range(r): # grid.append(insr()) # print("MORTAL") # [r,c] = inlt() # grid = [] # for i in range(r): # grid.append(insr()) # print(4) # return for test in range(tests): [r,c] = inlt() grid = [] for i in range(r): grid.append(insr()) rows = [0 for i in range(r)] col = [ 0 for i in range(c)] for i in range(r): for j in range(c): if grid[i][j] == 'A': rows[i]+=1 col[j]+=1 # print(test) # if test == 11: # for i in grid: # print(i) # return # print(rows,col) if max(rows)==0: print("MORTAL") elif sum(rows) == r*c: print(0) elif rows[0] == c or col[0] == r or rows[-1]==c or col[-1] == r: print(1) # elif rows[0]!=0 or col[0]!=0 or rows[-1] != 0 or col[-1]!= 0: elif grid[0][0] == 'A' or grid[-1][0] == 'A' or grid[0][-1] == 'A' or grid[-1][-1] == 'A'or max(rows) == c or max(col) == r: print(2) elif rows[0] != 0 or col[0] !=0 or col[-1]!=0 or rows[-1]!=0: print(3) else: print(4) # print(x_values) # for i in range(x): # if int(x_values[i])!=1: # n_new = i+1 + (n-i-1)*int(x_values[i]) # n = n_new%mod # print(n) if __name__== "__main__": main() ```
output
1
97,987
3
195,975
Provide tags and a correct Python 3 solution for this coding contest problem. You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a r × c grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Beingawesomeism, who do good for the sake of being good. The other religion is called Pushingittoofarism, who do murders for the sake of being bad. Oh, and you are actually not really all-powerful. You just have one power, which you can use infinitely many times! Your power involves missionary groups. When a missionary group of a certain country, say a, passes by another country b, they change the dominant religion of country b to the dominant religion of country a. In particular, a single use of your power is this: * You choose a horizontal 1 × x subgrid or a vertical x × 1 subgrid. That value of x is up to you; * You choose a direction d. If you chose a horizontal subgrid, your choices will either be NORTH or SOUTH. If you choose a vertical subgrid, your choices will either be EAST or WEST; * You choose the number s of steps; * You command each country in the subgrid to send a missionary group that will travel s steps towards direction d. In each step, they will visit (and in effect convert the dominant religion of) all s countries they pass through, as detailed above. * The parameters x, d, s must be chosen in such a way that any of the missionary groups won't leave the grid. The following image illustrates one possible single usage of your power. Here, A represents a country with dominant religion Beingawesomeism and P represents a country with dominant religion Pushingittoofarism. Here, we've chosen a 1 × 4 subgrid, the direction NORTH, and s = 2 steps. <image> You are a being which believes in free will, for the most part. However, you just really want to stop receiving murders that are attributed to your name. Hence, you decide to use your powers and try to make Beingawesomeism the dominant religion in every country. What is the minimum number of usages of your power needed to convert everyone to Beingawesomeism? With god, nothing is impossible. But maybe you're not god? If it is impossible to make Beingawesomeism the dominant religion in all countries, you must also admit your mortality and say so. Input The first line of input contains a single integer t (1 ≤ t ≤ 2⋅ 10^4) denoting the number of test cases. The first line of each test case contains two space-separated integers r and c denoting the dimensions of the grid (1 ≤ r, c ≤ 60). The next r lines each contains c characters describing the dominant religions in the countries. In particular, the j-th character in the i-th line describes the dominant religion in the country at the cell with row i and column j, where: * "A" means that the dominant religion is Beingawesomeism; * "P" means that the dominant religion is Pushingittoofarism. It is guaranteed that the grid will only contain "A" or "P" characters. It is guaranteed that the sum of the r ⋅ c in a single file is at most 3 ⋅ 10^6. Output For each test case, output a single line containing the minimum number of usages of your power needed to convert everyone to Beingawesomeism, or the string "MORTAL" (without quotes) if it is impossible to do so. Example Input 4 7 8 AAPAAAAA PPPPAAAA PPPPAAAA APAAPPPP APAPPAPP AAAAPPAP AAAAPPAA 6 5 AAAAA AAAAA AAPAA AAPAP AAAPP AAAPP 4 4 PPPP PPPP PPPP PPPP 3 4 PPPP PAAP PPPP Output 2 1 MORTAL 4 Note In the first test case, it can be done in two usages, as follows: Usage 1: <image> Usage 2: <image> In the second test case, it can be done with just one usage of the power. In the third test case, it is impossible to convert everyone to Beingawesomeism, so the answer is "MORTAL".
instruction
0
97,988
3
195,976
Tags: implementation, math Correct Solution: ``` import heapq import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline M = mod = 10**9 + 7 def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))) def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip('\n').split(' ')] def st():return input().rstrip('\n') def val():return int(input()) def li2():return [i for i in input().rstrip('\n').split(' ')] for _ in range(val()): n, m = li() l = [] for i in range(n):l.append(st()) l1 = [set() for i in range(n)] l2 = [set() for i in range(m)] ans = -1 ans2 = -1 for i in range(n): for j in l[i]: if j == 'A': ans = 4 else: ans2 = 1 if ans == -1: print('MORTAL') continue if ans2 == -1: print(0) continue for i in range(n): for j in range(m): if l[i][j] == 'A': l1[i].add(j) l2[j].add(i) ans = 4 if len(l1[0]) == m or len(l1[-1]) == m or len(l2[0]) == n or len(l2[-1])== n: print(1) continue if (0 in l1[0] or 0 in l1[-1] or 0 in l2[0] or 0 in l2[-1] or m-1 in l1[0] or m-1 in l1[-1] or n-1 in l2[0] or n-1 in l2[-1]): print(2) continue for i in range(n): if len(l1[i]) == m: ans = 2 break for j in range(m): if len(l2[j]) == n: ans = 2 break if ans == 2: print(2) continue for i in range(n): if 0 in l1[i] or m-1 in l1[i]: ans = 3 break for j in range(m): if 0 in l2[j] or n-1 in l2[j]: ans = 3 break print(ans) ```
output
1
97,988
3
195,977
Provide tags and a correct Python 3 solution for this coding contest problem. You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a r × c grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Beingawesomeism, who do good for the sake of being good. The other religion is called Pushingittoofarism, who do murders for the sake of being bad. Oh, and you are actually not really all-powerful. You just have one power, which you can use infinitely many times! Your power involves missionary groups. When a missionary group of a certain country, say a, passes by another country b, they change the dominant religion of country b to the dominant religion of country a. In particular, a single use of your power is this: * You choose a horizontal 1 × x subgrid or a vertical x × 1 subgrid. That value of x is up to you; * You choose a direction d. If you chose a horizontal subgrid, your choices will either be NORTH or SOUTH. If you choose a vertical subgrid, your choices will either be EAST or WEST; * You choose the number s of steps; * You command each country in the subgrid to send a missionary group that will travel s steps towards direction d. In each step, they will visit (and in effect convert the dominant religion of) all s countries they pass through, as detailed above. * The parameters x, d, s must be chosen in such a way that any of the missionary groups won't leave the grid. The following image illustrates one possible single usage of your power. Here, A represents a country with dominant religion Beingawesomeism and P represents a country with dominant religion Pushingittoofarism. Here, we've chosen a 1 × 4 subgrid, the direction NORTH, and s = 2 steps. <image> You are a being which believes in free will, for the most part. However, you just really want to stop receiving murders that are attributed to your name. Hence, you decide to use your powers and try to make Beingawesomeism the dominant religion in every country. What is the minimum number of usages of your power needed to convert everyone to Beingawesomeism? With god, nothing is impossible. But maybe you're not god? If it is impossible to make Beingawesomeism the dominant religion in all countries, you must also admit your mortality and say so. Input The first line of input contains a single integer t (1 ≤ t ≤ 2⋅ 10^4) denoting the number of test cases. The first line of each test case contains two space-separated integers r and c denoting the dimensions of the grid (1 ≤ r, c ≤ 60). The next r lines each contains c characters describing the dominant religions in the countries. In particular, the j-th character in the i-th line describes the dominant religion in the country at the cell with row i and column j, where: * "A" means that the dominant religion is Beingawesomeism; * "P" means that the dominant religion is Pushingittoofarism. It is guaranteed that the grid will only contain "A" or "P" characters. It is guaranteed that the sum of the r ⋅ c in a single file is at most 3 ⋅ 10^6. Output For each test case, output a single line containing the minimum number of usages of your power needed to convert everyone to Beingawesomeism, or the string "MORTAL" (without quotes) if it is impossible to do so. Example Input 4 7 8 AAPAAAAA PPPPAAAA PPPPAAAA APAAPPPP APAPPAPP AAAAPPAP AAAAPPAA 6 5 AAAAA AAAAA AAPAA AAPAP AAAPP AAAPP 4 4 PPPP PPPP PPPP PPPP 3 4 PPPP PAAP PPPP Output 2 1 MORTAL 4 Note In the first test case, it can be done in two usages, as follows: Usage 1: <image> Usage 2: <image> In the second test case, it can be done with just one usage of the power. In the third test case, it is impossible to convert everyone to Beingawesomeism, so the answer is "MORTAL".
instruction
0
97,989
3
195,978
Tags: implementation, math Correct Solution: ``` import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ def solve(): r,c = map(int, input().split()) board = [[int(j == "A") for j in input()] for i in range(r)] board2 = [list(x) for x in zip(*board)] s = sum(sum(board[i]) for i in range(r)) if s == 0: print("MORTAL") return elif s == r*c: print(0) return else: if any(sum(board[i])==c for i in [0,r-1]) or any(sum(board2[i])==r for i in [0,c-1]): print(1) return if board[0][0]+board[0][-1]+board[-1][0]+board[-1][-1]>0: print(2) return if any(sum(board[i])==c for i in range(r)) or any(sum(board2[i])==r for i in range(c)): print(2) return if any(sum(board[i])>0 for i in [0,r-1]) or any(sum(board2[i])>0 for i in [0, c-1]): print(3) return print(4) return t = int(input()) for i in range(t): solve() ```
output
1
97,989
3
195,979
Provide tags and a correct Python 3 solution for this coding contest problem. You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a r × c grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Beingawesomeism, who do good for the sake of being good. The other religion is called Pushingittoofarism, who do murders for the sake of being bad. Oh, and you are actually not really all-powerful. You just have one power, which you can use infinitely many times! Your power involves missionary groups. When a missionary group of a certain country, say a, passes by another country b, they change the dominant religion of country b to the dominant religion of country a. In particular, a single use of your power is this: * You choose a horizontal 1 × x subgrid or a vertical x × 1 subgrid. That value of x is up to you; * You choose a direction d. If you chose a horizontal subgrid, your choices will either be NORTH or SOUTH. If you choose a vertical subgrid, your choices will either be EAST or WEST; * You choose the number s of steps; * You command each country in the subgrid to send a missionary group that will travel s steps towards direction d. In each step, they will visit (and in effect convert the dominant religion of) all s countries they pass through, as detailed above. * The parameters x, d, s must be chosen in such a way that any of the missionary groups won't leave the grid. The following image illustrates one possible single usage of your power. Here, A represents a country with dominant religion Beingawesomeism and P represents a country with dominant religion Pushingittoofarism. Here, we've chosen a 1 × 4 subgrid, the direction NORTH, and s = 2 steps. <image> You are a being which believes in free will, for the most part. However, you just really want to stop receiving murders that are attributed to your name. Hence, you decide to use your powers and try to make Beingawesomeism the dominant religion in every country. What is the minimum number of usages of your power needed to convert everyone to Beingawesomeism? With god, nothing is impossible. But maybe you're not god? If it is impossible to make Beingawesomeism the dominant religion in all countries, you must also admit your mortality and say so. Input The first line of input contains a single integer t (1 ≤ t ≤ 2⋅ 10^4) denoting the number of test cases. The first line of each test case contains two space-separated integers r and c denoting the dimensions of the grid (1 ≤ r, c ≤ 60). The next r lines each contains c characters describing the dominant religions in the countries. In particular, the j-th character in the i-th line describes the dominant religion in the country at the cell with row i and column j, where: * "A" means that the dominant religion is Beingawesomeism; * "P" means that the dominant religion is Pushingittoofarism. It is guaranteed that the grid will only contain "A" or "P" characters. It is guaranteed that the sum of the r ⋅ c in a single file is at most 3 ⋅ 10^6. Output For each test case, output a single line containing the minimum number of usages of your power needed to convert everyone to Beingawesomeism, or the string "MORTAL" (without quotes) if it is impossible to do so. Example Input 4 7 8 AAPAAAAA PPPPAAAA PPPPAAAA APAAPPPP APAPPAPP AAAAPPAP AAAAPPAA 6 5 AAAAA AAAAA AAPAA AAPAP AAAPP AAAPP 4 4 PPPP PPPP PPPP PPPP 3 4 PPPP PAAP PPPP Output 2 1 MORTAL 4 Note In the first test case, it can be done in two usages, as follows: Usage 1: <image> Usage 2: <image> In the second test case, it can be done with just one usage of the power. In the third test case, it is impossible to convert everyone to Beingawesomeism, so the answer is "MORTAL".
instruction
0
97,990
3
195,980
Tags: implementation, math Correct Solution: ``` # ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------- fast io -------------------- from math import gcd, ceil def prod(a, mod=10**9+7): ans = 1 for each in a: ans = (ans * each) % mod return ans def lcm(a, b): return a * b // gcd(a, b) def binary(x, length=16): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y for _ in range(int(input()) if True else 1): #n = int(input()) n, m = map(int, input().split()) #a, b = map(int, input().split()) #c, d = map(int, input().split()) #a = list(map(int, input().split())) #b = list(map(int, input().split())) #s = input() a = [] for i in range(n): a += [[k for k in input()]] pos = False has = False for i in range(n): for j in range(m): if a[i][j] == 'A': pos=True else: has = True if not pos: print("MORTAL") continue if not has: print(0) continue first_row = a[0] last_row = a[-1] first_col = [a[k][0] for k in range(n)] last_col = [a[k][-1] for k in range(n)] if first_row == ['A'] * m or last_row == ['A']*m or first_col == ['A']*n or last_col == ['A']*n: print(1) continue pos = False for i in a: if i == ['A']*m: pos=True break for j in range(m): if [a[i][j] for i in range(n)] == ['A']*n: pos = True break if 'A' in [a[0][0], a[0][-1], a[-1][0], a[-1][-1]] or min(n,m) == 1 or pos: print(2) continue if 'A' in first_row+first_col+last_col+last_row: print(3) continue print(4) ```
output
1
97,990
3
195,981
Provide tags and a correct Python 3 solution for this coding contest problem. You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a r × c grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Beingawesomeism, who do good for the sake of being good. The other religion is called Pushingittoofarism, who do murders for the sake of being bad. Oh, and you are actually not really all-powerful. You just have one power, which you can use infinitely many times! Your power involves missionary groups. When a missionary group of a certain country, say a, passes by another country b, they change the dominant religion of country b to the dominant religion of country a. In particular, a single use of your power is this: * You choose a horizontal 1 × x subgrid or a vertical x × 1 subgrid. That value of x is up to you; * You choose a direction d. If you chose a horizontal subgrid, your choices will either be NORTH or SOUTH. If you choose a vertical subgrid, your choices will either be EAST or WEST; * You choose the number s of steps; * You command each country in the subgrid to send a missionary group that will travel s steps towards direction d. In each step, they will visit (and in effect convert the dominant religion of) all s countries they pass through, as detailed above. * The parameters x, d, s must be chosen in such a way that any of the missionary groups won't leave the grid. The following image illustrates one possible single usage of your power. Here, A represents a country with dominant religion Beingawesomeism and P represents a country with dominant religion Pushingittoofarism. Here, we've chosen a 1 × 4 subgrid, the direction NORTH, and s = 2 steps. <image> You are a being which believes in free will, for the most part. However, you just really want to stop receiving murders that are attributed to your name. Hence, you decide to use your powers and try to make Beingawesomeism the dominant religion in every country. What is the minimum number of usages of your power needed to convert everyone to Beingawesomeism? With god, nothing is impossible. But maybe you're not god? If it is impossible to make Beingawesomeism the dominant religion in all countries, you must also admit your mortality and say so. Input The first line of input contains a single integer t (1 ≤ t ≤ 2⋅ 10^4) denoting the number of test cases. The first line of each test case contains two space-separated integers r and c denoting the dimensions of the grid (1 ≤ r, c ≤ 60). The next r lines each contains c characters describing the dominant religions in the countries. In particular, the j-th character in the i-th line describes the dominant religion in the country at the cell with row i and column j, where: * "A" means that the dominant religion is Beingawesomeism; * "P" means that the dominant religion is Pushingittoofarism. It is guaranteed that the grid will only contain "A" or "P" characters. It is guaranteed that the sum of the r ⋅ c in a single file is at most 3 ⋅ 10^6. Output For each test case, output a single line containing the minimum number of usages of your power needed to convert everyone to Beingawesomeism, or the string "MORTAL" (without quotes) if it is impossible to do so. Example Input 4 7 8 AAPAAAAA PPPPAAAA PPPPAAAA APAAPPPP APAPPAPP AAAAPPAP AAAAPPAA 6 5 AAAAA AAAAA AAPAA AAPAP AAAPP AAAPP 4 4 PPPP PPPP PPPP PPPP 3 4 PPPP PAAP PPPP Output 2 1 MORTAL 4 Note In the first test case, it can be done in two usages, as follows: Usage 1: <image> Usage 2: <image> In the second test case, it can be done with just one usage of the power. In the third test case, it is impossible to convert everyone to Beingawesomeism, so the answer is "MORTAL".
instruction
0
97,991
3
195,982
Tags: implementation, math Correct Solution: ``` def fastio(): import sys from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) from math import gcd from collections import defaultdict as dd t, = I() while t: t -= 1 n, m = I() g = [] c = [[] for i in range(m)] p = False a = False for i in range(n): g.append(input()) s = g[-1] for j in range(m): if s[j] == 'A': a = True else: p = True c[j].append(s[j]) if not p: print(0) continue if not a: print('MORTAL') continue ans = 4 for i in range(n): if 'P' not in g[i]: if i == 0 or i == n-1: ans = 1 break else: ans = min(ans, 2) for i in range(m): if 'P' not in c[i]: if i == 0 or i == m-1: ans = 1 break else: ans = min(ans, 2) if 'A' in [g[0][0], g[0][-1], g[-1][0], g[-1][-1]]: ans = min(ans, 2) for i in range(m): if g[0][i] == 'A' or g[-1][i] == 'A': ans = min(ans, 3) break for i in range(n): if g[i][0] == 'A' or g[i][-1] == 'A': ans = min(ans, 3) print(ans) ```
output
1
97,991
3
195,983
Provide tags and a correct Python 3 solution for this coding contest problem. You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a r × c grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Beingawesomeism, who do good for the sake of being good. The other religion is called Pushingittoofarism, who do murders for the sake of being bad. Oh, and you are actually not really all-powerful. You just have one power, which you can use infinitely many times! Your power involves missionary groups. When a missionary group of a certain country, say a, passes by another country b, they change the dominant religion of country b to the dominant religion of country a. In particular, a single use of your power is this: * You choose a horizontal 1 × x subgrid or a vertical x × 1 subgrid. That value of x is up to you; * You choose a direction d. If you chose a horizontal subgrid, your choices will either be NORTH or SOUTH. If you choose a vertical subgrid, your choices will either be EAST or WEST; * You choose the number s of steps; * You command each country in the subgrid to send a missionary group that will travel s steps towards direction d. In each step, they will visit (and in effect convert the dominant religion of) all s countries they pass through, as detailed above. * The parameters x, d, s must be chosen in such a way that any of the missionary groups won't leave the grid. The following image illustrates one possible single usage of your power. Here, A represents a country with dominant religion Beingawesomeism and P represents a country with dominant religion Pushingittoofarism. Here, we've chosen a 1 × 4 subgrid, the direction NORTH, and s = 2 steps. <image> You are a being which believes in free will, for the most part. However, you just really want to stop receiving murders that are attributed to your name. Hence, you decide to use your powers and try to make Beingawesomeism the dominant religion in every country. What is the minimum number of usages of your power needed to convert everyone to Beingawesomeism? With god, nothing is impossible. But maybe you're not god? If it is impossible to make Beingawesomeism the dominant religion in all countries, you must also admit your mortality and say so. Input The first line of input contains a single integer t (1 ≤ t ≤ 2⋅ 10^4) denoting the number of test cases. The first line of each test case contains two space-separated integers r and c denoting the dimensions of the grid (1 ≤ r, c ≤ 60). The next r lines each contains c characters describing the dominant religions in the countries. In particular, the j-th character in the i-th line describes the dominant religion in the country at the cell with row i and column j, where: * "A" means that the dominant religion is Beingawesomeism; * "P" means that the dominant religion is Pushingittoofarism. It is guaranteed that the grid will only contain "A" or "P" characters. It is guaranteed that the sum of the r ⋅ c in a single file is at most 3 ⋅ 10^6. Output For each test case, output a single line containing the minimum number of usages of your power needed to convert everyone to Beingawesomeism, or the string "MORTAL" (without quotes) if it is impossible to do so. Example Input 4 7 8 AAPAAAAA PPPPAAAA PPPPAAAA APAAPPPP APAPPAPP AAAAPPAP AAAAPPAA 6 5 AAAAA AAAAA AAPAA AAPAP AAAPP AAAPP 4 4 PPPP PPPP PPPP PPPP 3 4 PPPP PAAP PPPP Output 2 1 MORTAL 4 Note In the first test case, it can be done in two usages, as follows: Usage 1: <image> Usage 2: <image> In the second test case, it can be done with just one usage of the power. In the third test case, it is impossible to convert everyone to Beingawesomeism, so the answer is "MORTAL".
instruction
0
97,992
3
195,984
Tags: implementation, math Correct Solution: ``` import sys input = sys.stdin.readline def getInt(): return int(input()) def getVars(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getStr(): return input().strip() ## ------------------------------- t = getInt() for _ in range(t): rows, columns = getVars() allA = True firstARow = False firstAColumn1 = True firstAColumn2 = True inCorner = False rowA = False oneInFirst = False one = False d = [1]*(max(columns-2, 0)) for r in range(rows): s = getStr() if allA and s != 'A' * len(s): allA = False if ((r == 0) or r == (rows-1)) and s == 'A' * len(s): firstARow = True if firstAColumn1 and s[0] != 'A': firstAColumn1 = False if firstAColumn2 and s[-1] != 'A': firstAColumn2 = False if ((r == 0) or r == (rows-1)) and (s[0] == 'A' or s[-1] == 'A'): inCorner = True if (not rowA) and (s == 'A' * len(s)): rowA = True for j in range(columns-2): if d[j] == 1 and s[j+1] == 'P': d[j] = 0 if ((r == 0) or r == (rows-1)) and s != 'P' * len(s): oneInFirst = True if (not oneInFirst) and (s[0] == 'A' or s[-1] == 'A'): oneInFirst = True if (not one) and s != 'P' * len(s): one = True if allA: print(0) elif firstARow or firstAColumn1 or firstAColumn2: print(1) elif inCorner or rowA or (len(d) > 0 and max(d) == 1):print(2) elif oneInFirst: print(3) elif one:print(4) else: print('MORTAL') ```
output
1
97,992
3
195,985