output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s255143275
Runtime Error
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
from collections import deque def main(H, W, C, D, S): def inside(x, y): return (0 <= x and x < H) and (0 <= y and y < W) def isroad(x, y): return S[x][y] == "." C, D = list(map(lambda x: [x[0] - 1, x[1] - 1], [C, D])) # python方式に直す """ 上:up 下:down 右:right 左:left """ next = {tuple(C)} masu = [[-1 for _ in range(W)] for __ in range(H)] def moverange(x, y): return inside(x, y) and masu[x][y] == -1 and isroad(x, y) def up(x, y): return [x - 1, y] def down(x, y): return [x + 1, y] def right(x, y): return [x, y + 1] def left(x, y): return [x, y - 1] def func(now, direction, kaisu): while True: canmove = direction(*now) if moverange(*canmove): que.append(canmove) masu[canmove[0]][canmove[1]] = kaisu print(masu, direction) else: break def make_lst(x, y): return [[x + i, y + j] for i in range(-2, 3) for j in range(-2, 3)] kaisu = -1 while masu[D[0]][D[1]] == -1 and len(next) != 0: kaisu += 1 que = deque(next) next = set() while que: now = que.popleft() if moverange(*now): masu[now[0]][now[1]] = kaisu func(now, up, kaisu) func(now, down, kaisu) func(now, right, kaisu) func(now, left, kaisu) for canmove in make_lst(*now): if moverange(*canmove): next.add(tuple(canmove)) ans = masu[D[0]][D[1]] print(ans) if __name__ == "__main__": H, W = list(map(int, input().split())) C = list(map(int, input().split())) D = list(map(int, input().split())) S = [] for _ in range(H): S.append(input()) main(H, W, C, D, S)
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s412669693
Wrong Answer
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
H, W = map(int, input().split()) Ch, Cw = map(int, input().split()) Dh, Dw = map(int, input().split()) S = [] for _ in range(H): S.append(list(input())) # from collections import defaultdict from queue import Queue path = dict() cache = set() Cur = (Cw - 1, Ch - 1) Q = Queue() Q.put(Cur) cache.add(Cur) path[Cur] = 0 G = (Dw - 1, Dh - 1) dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] wdx = [] wdy = [] while not Q.empty(): node = Q.get() cx, cy = node # move for di in range(4): nx = cx + dx[di] ny = cy + dy[di] if W > nx >= 0 and H > ny >= 0: nt = (nx, ny) if S[ny][nx] == ".": if nt not in cache: # 移動可能 Q.put(nt) cache.add(nt) path[nt] = path[node] elif nt in path.keys() and path[node] < path[nt]: path[nt] = path[node] # warp for wdx in range(-2, 3, 1): for wdy in range(-2, 3, 1): nx = cx + wdx ny = cy + wdy nt = (nx, ny) if W > nx >= 0 and H > ny >= 0 and S[ny][nx] == ".": if nt not in cache: Q.put(nt) cache.add(nt) path[nt] = path[node] + 1 elif nt in path.keys() and path[node] + 1 < path[nt]: path[nt] = path[node] + 1 print(path[G] if G in path.keys() else -1)
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s145802367
Accepted
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
# by the authority of GOD author: manhar singh sachdev # import os, sys from io import BytesIO, IOBase from collections import deque, defaultdict def main(): h, w = map(int, input().split()) x1, y1 = map(int, input().split()) a1, b1 = map(int, input().split()) arr = [list(input().strip()) for _ in range(h)] dp = [[0] * w for _ in range(h)] se = set() for i in range(h): for j in range(w): if arr[i][j] != "#": se.add((i, j)) reg = 1 while len(se): x = se.pop() curr = deque([x]) while len(curr): y = curr.popleft() z = (y[0] + 1, y[1]) dp[y[0]][y[1]] = reg if z[0] < h and z[1] < w and z in se and arr[z[0]][z[1]] != "#": curr.append(z) se.remove(z) dp[z[0]][z[1]] = reg z = (y[0], y[1] + 1) if z[0] < h and z[1] < w and z in se and arr[z[0]][z[1]] != "#": curr.append(z) se.remove(z) dp[z[0]][z[1]] = reg z = (y[0] - 1, y[1]) if z[0] >= 0 and z[1] >= 0 and z in se and arr[z[0]][z[1]] != "#": curr.append(z) se.remove(z) dp[z[0]][z[1]] = reg z = (y[0], y[1] - 1) if z[0] >= 0 and z[1] >= 0 and z in se and arr[z[0]][z[1]] != "#": curr.append(z) se.remove(z) dp[z[0]][z[1]] = reg reg += 1 path = defaultdict(set) for i in range(h): for j in range(w): if arr[i][j] == "#": continue for r in range(-2, 3): for q in range(-2, 3): if ( 0 <= i + r < h and 0 <= j + q < w and dp[i][j] != dp[i + r][j + q] and dp[i + r][j + q] ): path[dp[i][j]].add(dp[i + r][j + q]) st = dp[x1 - 1][y1 - 1] en = dp[a1 - 1][b1 - 1] curr = deque([st]) visi = {st} ans = fl = 0 val = 1 tar = 0 val1 = 0 while len(curr): x = curr.popleft() tar += 1 if x == en: fl = 1 break for i in path[x]: if i not in visi: visi.add(i) curr.append(i) val1 += 1 if tar == val: tar = 0 val = val1 val1 = 0 ans += 1 if fl: print(ans) else: print(-1) # Fast IO Region 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") if __name__ == "__main__": main()
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s417432429
Accepted
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
from heapq import heappush, heappop, heapify rep = range R = range def Golf(): n, *t = map(int, open(0).read().split()) def I(): return int(input()) def S_(): return input() def IS(): return input().split() def LS(): return [i for i in input().split()] def MI(): return map(int, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i) - 1 for i in input().split()] def NI(n): return [int(input()) for i in range(n)] def NI_(n): return [int(input()) - 1 for i in range(n)] def StoLI(): return [ord(i) - 97 for i in input()] def ItoS(n): return chr(n + 97) def LtoS(ls): return "".join([chr(i + 97) for i in ls]) def GI(V, E, ls=None, Directed=False, index=1): org_inp = [] g = [[] for i in range(V)] FromStdin = True if ls == None else False for i in range(E): if FromStdin: inp = LI() org_inp.append(inp) else: inp = ls[i] if len(inp) == 2: a, b = inp c = 1 else: a, b, c = inp if index == 1: a -= 1 b -= 1 aa = (a, c) bb = (b, c) g[a].append(bb) if not Directed: g[b].append(aa) return g, org_inp def GGI( h, w, search=None, replacement_of_found=".", mp_def={"#": 1, ".": 0}, boundary=1 ): # h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage mp = [boundary] * (w + 2) found = {} for i in R(h): s = input() for char in search: if char in s: found[char] = (i + 1) * (w + 2) + s.index(char) + 1 mp_def[char] = mp_def[replacement_of_found] mp += [boundary] + [mp_def[j] for j in s] + [boundary] mp += [boundary] * (w + 2) return h + 2, w + 2, mp, found mo = 10**9 + 7 FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)] EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)] compas = dict(zip("WENS", FourNb)) cursol = dict(zip("LRUD", FourNb)) import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline input = lambda: sys.stdin.readline().rstrip() inf = 1 << 20 def dijkstra(edge, st): n = len(edge) d = [(0 if st == i else inf) for i in range(n)] q = [(0, st)] heapify(q) v = [False] * n while q: dist, cur = heappop(q) if v[cur]: continue v[cur] = True for x in edge[cur]: dst, dist = x >> 1, x % 2 alt = d[cur] + dist if alt < d[dst]: d[dst] = alt heappush(q, (alt, dst)) return d show_flg = False show_flg = True ans = 0 h, w = LI() sh, sw = LI() gh, gw = LI() w += 2 m = [1] * w for i in range(h): s = input() m += [1] + [i == "#" for i in s] + [1] m += [1] * w h += 2 n = h * w v = [-1] * w * h nbw = [ -2 * w + 1, -2 * w + 2, -w + 1, -w + 2, 2, 2 * w + 1, 2 * w + 2, w + 1, w + 2, +2 * w, -2 * w, -2 * w - 1, -2 * w - 2, -w - 1, -w - 2, -2, 2 * w - 1, 2 * w - 2, w - 1, w - 2, ] nbw = [ 2, 2 * w + 1, 2 * w + 2, w + 1, w + 2, +2 * w, 2 * w - 1, 2 * w - 2, w - 1, w - 2, ] nb = [1, -1, w, -w] nb = [1, w] d = [-1] * n g = [[] for i in range(n)] for i in range(n): if m[i] == 1: continue for di in nbw: nx = i + di if 0 <= nx < n and m[nx] != 1: g[i] += ((nx * 2 + 1),) g[nx] += ((i * 2 + 1),) for di in nb: nx = i + di if 0 <= nx < n and m[nx] != 1: g[i] += ((nx * 2),) g[nx] += ((i * 2),) d = dijkstra(g, sh * w + sw) ans = d[gh * w + gw] if ans == inf: ans = -1 print(ans)
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s646521881
Accepted
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
def d_wizard_in_maze(): from collections import deque H, W = [int(i) for i in input().split()] Start_row, Start_col = [int(i) - 1 for i in input().split()] Goal_row, Goal_col = [int(i) - 1 for i in input().split()] Grid = [input() for _ in range(H)] warp_count = [[-1] * W for i in range(H)] neighbor_4 = [(-1, 0), (1, 0), (0, -1), (0, 1)] neighbor_25 = [(i, j) for i in range(-2, 3) for j in range(-2, 3)] queue = deque([(Start_row, Start_col, 0)]) # コスト 0 の移動は左詰めする while queue: row, col, count = queue.popleft() if warp_count[row][col] != -1: continue warp_count[row][col] = count for dr, dc in neighbor_4: nr, nc = row + dr, col + dc if 0 <= nr < H and 0 <= nc < W and Grid[nr][nc] == ".": if warp_count[nr][nc] == -1: queue.appendleft((nr, nc, count)) for dr, dc in neighbor_25: nr, nc = row + dr, col + dc if 0 <= nr < H and 0 <= nc < W and Grid[nr][nc] == ".": queue.append((nr, nc, count + 1)) return warp_count[Goal_row][Goal_col] print(d_wizard_in_maze())
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s210425802
Accepted
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
import zlib, base64 exec( zlib.decompress( base64.b85decode( "c-l2k%Wi`(5WMphj;e}XSdx$`mw@vl76$_+EaG9nDM`P+j+!2JMw*?~Xtr6VK~z)Uo67Mtu7U?UEiMY6r40#IavmGHp)}vRhj7pqcyz?0y*t4DYJ2vK6h>bd3{=Y>wh;Z9;q4-oq(!v7Of6zC%i7F$0}9q8CFkde1qNHoy%F;z5KnqgCFi}JEMOqG5w&_2>QUrJzZK222rYONiym(VPG`JmDy2Rg&dG`Nr^k$?j-Od4%lMJKk7bp$SH31`-sRg)4vGua71!`1+)2>o3L4`Vm6)G)K3!XD#u|XBqslk@S9;U9w;HGD``E>Q1Zvgzmg?pKe*wqdW>^" ) ) )
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s284675680
Runtime Error
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
#!/usr/bin/env python3 import heapq h,w=map(int,input().split()) sy,sx=map(int,input().split()) sy-=1 sx-=1 gy,gx=map(int,input().split()) gy-=1 gx-=1 board='' for _ in range(h): board+=input() costs=[10**18]*(w*h) costs[sy*w+sx]=0 q=[] heapq.heappush(q,(0,sy,sx)) while len(q)!=0: cost,y,x=heapq.heappop(q) cur_pos=y*w+x for dy,dx in [[-1,0],[1,0],[0,-1],[0,1]]: next_pos=cur_pos+dy*w+dx if 1<=y+dy<=h and 1<=x+dx<=w and board[next_pos]=='.' and costs[next_pos]>costs[cur_pos]: costs[next_pos]=costs[cur_pos] heapq.heappush(q,(cost,y+dy,x+dx)) for dy in range(-2,3): for dx in range(-2,3): if dy==0 and dx==0: continue next_pos=cur_pos+dy*w+dx if 1<=y+dy<=h and 1<=x+dx<=w and board[next_pos]=='.' and costs[next_pos]>costs[cur_pos]+1: costs[next_pos]=costs[cur_pos]+1 heapq.heappush(q,(cost+1,y+dy,x+dx)) if costs[gy*w+gx]==10**18: print(-1) else: print(costs[gy*w+gx])
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s088563756
Runtime Error
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
# -*- coding: utf-8 -*- h, w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) dh, dw = list(map(int, input().split())) d = [["#", "#"] + list(input()) + ["#", "#"] for i in range(h)] d = [["#"] * (w + 4)] * 2 + d + [["#"] * (w + 4)] * 2 def bfs(h, w, cnt=0): if d[h][w] == ".": d[h][w] = cnt bfs(h + 1, w, cnt) bfs(h - 1, w, cnt) bfs(h, w + 1, cnt) bfs(h, w - 1, cnt) cnt = 0 for i in range(h + 4): for j in range(w + 4): if d[i][j] == ".": bfs(i, j, cnt) cnt += 1 can_move_area = [set() for _ in range(cnt)] for i in range(h + 2): for j in range(w + 2): a = d[i][j] if a != "#": b = d[i - 2][j + 1] if b != "#" and b != a: can_move_area[a].add(b) b = d[i - 2][j + 2] if b != "#" and b != a: can_move_area[a].add(b) b = d[i - 1][j + 1] if b != "#" and b != a: can_move_area[a].add(b) b = d[i - 1][j + 2] if b != "#" and b != a: can_move_area[a].add(b) b = d[i][j + 2] if b != "#" and b != a: can_move_area[a].add(b) b = d[i + 1][j + 1] if b != "#" and b != a: can_move_area[a].add(b) b = d[i + 1][j + 2] if b != "#" and b != a: can_move_area[a].add(b) b = d[i + 2][j] if b != "#" and b != a: can_move_area[a].add(b) b = d[i + 2][j + 1] if b != "#" and b != a: can_move_area[a].add(b) b = d[i + 2][j + 2] if b != "#" and b != a: can_move_area[a].add(b) from copy import copy can_move = copy(can_move_area) for i, v in enumerate(can_move_area): for j in v: can_move[j].add(i) start_area = d[ch + 1][cw + 1] goal_area = d[dh + 1][dw + 1] cost_from_start_area = [-1] * cnt cost_from_start_area[start_area] = 0 def area_bfs(area_id, cost): global cost_from_start_area next_areas = can_move[area_id] next_b = [] for ai in next_areas: if cost_from_start_area[ai] == -1: cost_from_start_area[ai] = cost + 1 next_b.append(ai) for ai in next_b: area_bfs(ai, cost + 1) area_bfs(start_area, 0) print(cost_from_start_area[goal_area])
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s418453685
Accepted
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
import sys def _s(): return sys.stdin.readline().strip() def _ia(): return map(int, sys.stdin.readline().strip().split()) def walk(s, w1, h1, x, y, cur, v1, v2): if s[y][x] is not None: return s[y][x] = cur v1.add((x, y)) for hi in range(max(0, y - 2), min(h1, y + 2) + 1): for wi in range(max(0, x - 2), min(w1, x + 2) + 1): if s[hi][wi] is None: v2.add((wi, hi)) if x > 0: walk(s, w1, h1, x - 1, y, cur, v1, v2) if x < w1: walk(s, w1, h1, x + 1, y, cur, v1, v2) if y > 0: walk(s, w1, h1, x, y - 1, cur, v1, v2) if y < h1: walk(s, w1, h1, x, y + 1, cur, v1, v2) def main(): h, w = _ia() sh, sw = map(lambda x: x - 1, _ia()) gh, gw = map(lambda x: x - 1, _ia()) s = [[0] * w for _ in range(h)] for hi in range(h): for wi, c in enumerate(_s()): if c == ".": s[hi][wi] = None else: s[hi][wi] = -1 p = [(sw, sh)] c = 0 h1, w1 = h - 1, w - 1 while len(p) > 0: v1 = set() v2 = set() for pi in p: walk(s, w1, h1, *pi, c, v1, v2) p = v2 - v1 c += 1 ans = s[gh][gw] return ans if ans is not None else -1 if __name__ == "__main__": print(main())
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s420303834
Accepted
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
import sys input = sys.stdin.readline from collections import deque def main(): h, w = map(int, input().split()) ch, cw = map(int, input().split()) dh, dw = map(int, input().split()) ls = [input() for _ in range(h)] widou = [] for i in range(-2, 3): for j in range(-2, 3): widou.append((i, j)) widou.remove((0, 0)) widou.remove((1, 0)) widou.remove((0, 1)) widou.remove((-1, 0)) widou.remove((0, -1)) start = (ch - 1, cw - 1) goal = (dh - 1, dw - 1) explored = set() tempexplored = set() ytemp = deque() ytemp.append(start) wap = 0 while ytemp: now = ytemp.popleft() if now == goal: print(wap) exit(0) x = now[0] y = now[1] explored.add((x, y)) tempexplored.add((x, y)) idou = [(1, 0), (0, 1), (0, -1), (-1, 0)] for i, j in idou: a = x + i b = y + j if 0 <= a < h and 0 <= b < w: if ls[a][b] == ".": if (a, b) not in explored: ytemp.append((a, b)) explored.add((a, b)) tempexplored.add((a, b)) if len(ytemp) == 0: wap += 1 tempx = set() for s, t in tempexplored: for i, j in widou: a = s + i b = t + j if 0 <= a < h and 0 <= b < w: if ls[a][b] == ".": if (a, b) not in explored: ytemp.append((a, b)) explored.add((a, b)) tempx = set() tempexplored = tempx print("-1") if __name__ == "__main__": main()
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s486694313
Wrong Answer
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
import sys H, W = map(int, input().split()) Ch, Cw = map(int, input().split()) Dh, Dw = map(int, input().split()) S = [list(map(str, list(input()))) for i in range(H)] floor = [[0] * W for i in range(H)] floor[Ch - 1][Cw - 1] = 1 def water(x, y): if floor[y][x] != 0: # 上 if y + 1 < H: if S[y + 1][x] != "#" and floor[y + 1][x] == 0: floor[y + 1][x] = floor[y][x] water(x, y + 1) # 下 if y - 1 >= 0: if S[y - 1][x] != "#" and floor[y - 1][x] == 0: floor[y - 1][x] = floor[y][x] water(x, y - 1) # 右 if x + 1 < W: if S[y][x + 1] != "#" and floor[y][x + 1] == 0: floor[y][x + 1] = floor[y][x] water(x + 1, y) # 左 if x - 1 >= 0: if S[y][x - 1] != "#" and floor[y][x - 1] == 0: floor[y][x - 1] = floor[y][x] water(x - 1, y) def warp(x, y, i): for Y in range(max(y - 2, 0), min(y + 2, H - 1) + 1): for X in range(max(x - 2, 0), min(x + 2, W - 1) + 1): if S[Y][X] != "#" and floor[Y][X] == 0: floor[Y][X] = i + 1 water(X, Y) # スタート地点に水を流す water(Cw - 1, Ch - 1) print(floor) # ワープ回数 for i in range(1, 100): for y in range(H): for x in range(W): if floor[y][x] == i: warp(x, y, i) water(x, y) if floor[Dh - 1][Dw - 1] != 0: print(floor[Dh - 1][Dw - 1] - 1) print(floor) sys.exit() print("-1")
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s918743301
Wrong Answer
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
H, W = map(int, input().split()) Ch, Cw = map(int, input().split()) Dh, Dw = map(int, input().split()) S = [["#"] * (W + 4), ["#"] * (W + 4)] for h in range(H): temp = list(input()) S.append(["#", "#"] + temp + ["#", "#"]) S.append(["#"] * (W + 4)) S.append(["#"] * (W + 4)) que = [[Ch + 1, Cw + 1, 0]] que_ = [[Ch + 1, Cw + 1, 0]] while len(que) > 0: temp = que.pop(0) h, w, cnt = temp[0], temp[1], temp[2] if S[h + 1][w] == ".": S[h + 1][w] = str(cnt) que.append([h + 1, w, cnt]) que_.append([h + 1, w, cnt]) if S[h - 1][w] == ".": S[h - 1][w] = str(cnt) que.append([h - 1, w, cnt]) que_.append([h - 1, w, cnt]) if S[h][w + 1] == ".": S[h][w + 1] = str(cnt) que.append([h, w + 1, cnt]) que_.append([h, w + 1, cnt]) if S[h][w - 1] == ".": S[h][w - 1] = str(cnt) que.append([h, w - 1, cnt]) que_.append([h, w - 1, cnt]) while len(que_) > 0: temp = que_.pop(0) h, w, cnt = temp[0], temp[1], temp[2] + 1 for h_ in range(-2, 3): for w_ in range(-2, 3): if S[h + h_][w + w_] == ".": S[h + h_][w + w_] = str(cnt) que_.append([h + h_, w + w_, cnt]) if S[h + h_][w + w_].isdecimal(): if int(S[h + h_][w + w_]) > int(cnt): S[h + h_][w + w_] = str(cnt) que_.append([h + h_, w + w_, cnt]) print("-1" if S[Dh + 1][Dw + 1] == "." else S[Dh + 1][Dw + 1])
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s922452169
Accepted
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
from collections import deque def main(): def bfs(h1, w1, dp): """ -1 - unsearched -2 - candidate for warp -3 - wall '#' """ queue = deque() queue_warp = deque() queue.append([h1, w1]) now = 0 while queue: h1, w1 = queue.popleft() fl_up = False fl_left = False fl_down = False fl_right = False if h1 > 0: if dp[h1 - 1][w1] == -1 or dp[h1 - 1][w1] == -2: if m[h1 - 1][w1] == ".": dp[h1 - 1][w1] = now queue.append([h1 - 1, w1]) else: dp[h1 - 1][w1] = -3 if dp[h1 - 1][w1] == -3: fl_up = True if h1 > 1: if dp[h1 - 2][w1] == -1: if m[h1 - 2][w1] == ".": dp[h1 - 2][w1] = -2 queue_warp.append([h1 - 2, w1]) else: dp[h1 - 2][w1] = -3 if w1 > 0: if dp[h1][w1 - 1] == -1 or dp[h1][w1 - 1] == -2: if m[h1][w1 - 1] == ".": dp[h1][w1 - 1] = now queue.append([h1, w1 - 1]) else: dp[h1][w1 - 1] = -3 if dp[h1][w1 - 1] == -3: fl_left = True if w1 > 1: if dp[h1][w1 - 2] == -1: if m[h1][w1 - 2] == ".": dp[h1][w1 - 2] = -2 queue_warp.append([h1, w1 - 2]) else: dp[h1][w1 - 2] = -3 if h1 < h - 1: if dp[h1 + 1][w1] == -1 or dp[h1 + 1][w1] == -2: if m[h1 + 1][w1] == ".": dp[h1 + 1][w1] = now queue.append([h1 + 1, w1]) else: dp[h1 + 1][w1] = -3 if dp[h1 + 1][w1] == -3: fl_down = True if h1 < h - 2: if dp[h1 + 2][w1] == -1: if m[h1 + 2][w1] == ".": dp[h1 + 2][w1] = -2 queue_warp.append([h1 + 2, w1]) else: dp[h1 + 2][w1] = -3 if w1 < w - 1: if dp[h1][w1 + 1] == -1 or dp[h1][w1 + 1] == -2: if m[h1][w1 + 1] == ".": dp[h1][w1 + 1] = now queue.append([h1, w1 + 1]) else: dp[h1][w1 + 1] = -3 if dp[h1][w1 + 1] == -3: fl_right = True if w1 < w - 2: if dp[h1][w1 + 2] == -1: if m[h1][w1 + 2] == ".": dp[h1][w1 + 2] = -2 queue_warp.append([h1, w1 + 2]) else: dp[h1][w1 + 2] = -3 if fl_up and fl_left: for i in range(max(0, h1 - 2), h1): for j in range(max(0, w1 - 2), w1): if dp[i][j] == -1: if m[i][j] == ".": dp[i][j] = -2 queue_warp.append([i, j]) else: dp[i][j] = -3 if fl_left and fl_down: for i in range(h1 + 1, min(h, h1 + 3)): for j in range(max(0, w1 - 2), w1): if dp[i][j] == -1: if m[i][j] == ".": dp[i][j] = -2 queue_warp.append([i, j]) else: dp[i][j] = -3 if fl_down and fl_right: for i in range(h1 + 1, min(h, h1 + 3)): for j in range(w1 + 1, min(w, w1 + 3)): if dp[i][j] == -1: if m[i][j] == ".": dp[i][j] = -2 queue_warp.append([i, j]) else: dp[i][j] = -3 if fl_right and fl_up: for i in range(max(0, h1 - 2), h1): for j in range(w1 + 1, min(w, w1 + 3)): if dp[i][j] == -1: if m[i][j] == ".": dp[i][j] = -2 queue_warp.append([i, j]) else: dp[i][j] = -3 if not queue: now += 1 while queue_warp: h1, w1 = queue_warp.popleft() if dp[h1][w1] == -2: dp[h1][w1] = now queue.append([h1, w1]) if dp[dh - 1][dw - 1] >= 0: return dp[dh - 1][dw - 1] return dp[dh - 1][dw - 1] h, w = map(int, input().split()) ch, cw = map(int, input().split()) dh, dw = map(int, input().split()) m = [[] for i in range(h)] dp = [[-1] * w for i in range(h)] dp[ch - 1][cw - 1] = 0 for i in range(h): m[i] = input() ans = bfs(ch - 1, cw - 1, dp) print(ans) main()
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s048690865
Accepted
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
#! /usr/bin/env python3 def main(): H, W = map(int, input().split()) CH, CW = map(int, input().split()) DH, DW = map(int, input().split()) G = [] for i in range(H): G += [[[0, 1][x == "#"] for x in input()]] dx = [0, 1, 0, -1] dy = [-1, 0, 1, 0] dy2 = [] dx2 = [] for y in range(-2, 3): for x in range(-2, 3): if abs(y) + abs(x) > 1: dy2 += [y] dx2 += [x] dl = len(dx2) q = [(CH - 1, CW - 1)] a = [(CH - 1, CW - 1)] f = True c = 0 ans = -1 while f: f = False while q: t = [] for y, x in q: G[y][x] = 2 for d in range(4): px = x + dx[d] py = y + dy[d] if 0 <= px < W and 0 <= py < H and G[py][px] == 0: G[py][px] = 2 t += [(py, px)] a += [(py, px)] q = t b = [] s = set() for y, x in a: for d in range(dl): px = x + dx2[d] py = y + dy2[d] if 0 <= px < W and 0 <= py < H and G[py][px] == 0 and (py, px) not in s: s.add((py, px)) b += [(py, px)] q += [(py, px)] # for i in G: # print(i) # print() if G[DH - 1][DW - 1] == 2: ans = c break c += 1 a = b if b: f = True print(ans) main()
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s677812199
Wrong Answer
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
h = 0 w = 0 reached = [] maze = [] dh = 0 dw = 0 def main(): global h global w global dh global dw h, w = map(int, input().split()) # 迷路 ch, cw = map(int, input().split()) # 魔法使い位置 dh, dw = map(int, input().split()) # ゴール for i in range(h): maze.append(list(input())) # for (i, row) in enumerate(maze, 1): # print('{}: {}'.format(i, row)) warp_count = 0 while True: if walk_to(ch, cw): # 到達 # print('Goal!') print(warp_count) break else: # 行ったことのある場所からワープ mch, mcw = most_close() # print('一番近かったのは {},{}'.format(mch, mcw)) warped_hw = warp_from(mch, mcw) if warped_hw is not None: warp_count += 1 ch, cw = warped_hw else: # 到達不能 # print('到達不能') print(-1) break def warp_from(mch, mcw): start_h = max(mch - 2, 1) end_h = min(mch + 2, h) start_w = max(mcw - 2, 1) end_w = min(mcw + 2, w) min_distance = None min_hw = None for i in range(start_h, end_h + 1): for j in range(start_w, end_w + 1): # print(i, j) if get_block(i, j) == "." and yet(i, j): # print('{},{}にはワープできるね'.format(i, j)) distance = abs(dh - i) + abs(dw - j) if min_distance is None or distance < min_distance: min_distance = distance min_hw = [i, j] return min_hw def most_close(): min_hw = [] min_distance = None for r in reached: distance = max(abs(dh - r[0]), abs(dw - r[1])) if min_distance is None or distance < min_distance: min_distance = distance min_hw = [r[0], r[1]] return min_hw def walk_to(current_h, current_w): reached.append([current_h, current_w]) # 到達済み if current_h == dh and current_w == dw: return True # ↑ if ( current_h > 1 and get_block(current_h - 1, current_w) == "." and yet(current_h - 1, current_w) ): # print('現在{},{}: 上に行けるよ'.format(current_h, current_w)) return walk_to(current_h - 1, current_w) # → if ( current_w < w and get_block(current_h, current_w + 1) == "." and yet(current_h, current_w + 1) ): # print('現在{},{}: 右に行けるよ'.format(current_h, current_w)) return walk_to(current_h, current_w + 1) # ↓ if ( current_h < h and get_block(current_h + 1, current_w) == "." and yet(current_h + 1, current_w) ): # print('現在{},{}: 下に行けるよ'.format(current_h, current_w)) return walk_to(current_h + 1, current_w) # ← if ( current_w > 1 and get_block(current_h, current_w - 1) == "." and yet(current_h, current_w - 1) ): # print('現在{},{}: 左に行けるよ'.format(current_h, current_w)) return walk_to(current_h, current_w - 1) # print('現在{},{}: どこにも行けない'.format(current_h, current_w)) return False def get_block(target_h, target_w): return maze[target_h - 1][target_w - 1] def yet(check_h, check_w): for r in reached: if check_h == r[0] and check_w == r[1]: return False return True if __name__ == "__main__": main()
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s788527872
Wrong Answer
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
H, W = map(int, input().split()) C_h, C_w = map(int, input().split()) D_h, D_w = map(int, input().split()) S = [] C_h -= 1 C_w -= 1 D_h -= 1 D_w -= 1 for h in range(H): tmp = [x for x in input()] S.append(tmp) ans = 0 while D_h != C_h or D_w != C_w: if D_h - C_h > 0: dir_h = 1 else: dir_h = -1 if D_w - C_w > 0: dir_w = 1 else: dir_w = -1 while True: if D_h == C_h: break if S[C_h + dir_h][C_w] == "#": break C_h += dir_h if C_h + dir_h == H or C_h + dir_h < 0: dir_h = 0 while True: if D_w == C_w: break if S[C_h][C_w + dir_w] == "#": break C_w += dir_w if C_w + dir_w == W or C_w + dir_w < 0: dir_w = 0 if D_h == C_h and D_w == C_w: break flag = 0 for h in reversed(range(1, 3)): if flag == 0: for w in reversed(range(1, 3)): if 0 < C_h + h * dir_h < H and 0 < C_w + w * dir_w < W: if S[C_h + h * dir_h][C_w + w * dir_w] == ".": ans += 1 C_h += h * dir_h C_w += w * dir_w flag = 1 break else: break if flag == 0: ans = -1 break print(ans)
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s180123927
Runtime Error
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
h, w = input().split() x, y = input().split() x_target, y_target = input().split() h = int(h) w = int(w) x = int(x) - 1 y = int(y) - 1 x_target = int(x_target) - 1 y_target = int(y_target) - 1 square = [] for i in range(h): square.append(list(input())) print(square) wizard_loc = square[x][y] destination = square[x_target][y_target] print(wizard_loc) print(destination) if ( square[x - 2 : x + 3][y - 2 : y + 3] | square[x_target - 2 : x_target + 3][y_target - 2 : y_target + 3] ): print(1) else: print(-1)
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s846954627
Accepted
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
import numpy as np from numba import njit i4 = np.int32 i8 = np.int64 INF = 1000000000 @njit def solve(s, ch, cw): H = s.shape[0] W = s.shape[1] - 1 ah = H + 4 aw = W + 4 a = np.full((ah, aw), -1, i4) for i in range(H): for j in range(W): if s[i, j] == 46: a[i + 2, j + 2] = INF sh1 = np.empty(1000000, i4) sw1 = np.empty(1000000, i4) p1 = 0 sh2 = np.empty(1000000, i4) sw2 = np.empty(1000000, i4) p2 = 0 def push2(h2, w2, dis2): nonlocal p2, sh2, sw2 dis = 0 a[ch + 1, cw + 1] = dis sh1[p1] = ch + 1 sw1[p1] = cw + 1 p1 += 1 while True: while p1 > 0: p1 -= 1 h = sh1[p1] w = sw1[p1] for i in range(-2, 3): for j in range(-2, 3): if ((i == 1 or i == -1) and j == 0) or ( i == 0 and (j == 1 or j == -1) ): if a[h + i, w + j] > dis: a[h + i, w + j] = dis sh1[p1] = h + i sw1[p1] = w + j p1 += 1 else: if a[h + i, w + j] > dis + 1: push2(h + i, w + j, dis + 1) a[h + i, w + j] = dis + 1 sh2[p2] = h + i sw2[p2] = w + j p2 += 1 dis += 1 for i in range(p2): if a[sh2[i], sw2[i]] == dis: sh1[p1] = sh2[i] sw1[p1] = sw2[i] p1 += 1 p2 = 0 if p1 == 0: break return a def main(in_file): stdin = open(in_file) H, W = [int(x) for x in stdin.readline().split()] ch, cw = [int(x) for x in stdin.readline().split()] dh, dw = [int(x) for x in stdin.readline().split()] s = np.frombuffer(np.array(stdin.read()), i4).reshape((H, W + 1)) a = solve(s, ch, cw) ans = a[dh + 1, dw + 1] if ans == INF: print(-1) else: print(ans) main("/dev/stdin")
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s852524928
Wrong Answer
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
from collections import deque H, W = [int(x) for x in input().split()] Ch, Cw = [int(x) - 1 for x in input().split()] Dh, Dw = [int(x) - 1 for x in input().split()] warp_list = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)] maze = [] warp_count = [] for _ in range(H): line = list([x for x in input()]) maze.append(line) warp_count.append([-1] * W) queue = deque() warp_queue = deque() queue.appendleft((Ch, Cw, 0)) warp_count[Ch][Cw] = 0 answer = -1 while queue: def maze_check(h, w, use_magic): if h < 0 or H <= h: return False if w < 0 or W <= w: return False if maze[h][w] == '#': return False if warp_count[h][w] == -1: return True if warp_count[h][w] <= use_magic: return False return True now_h, now_w, use_magic = queue.pop() if now_h == Dh and now_w == Dw: if answer == -1: answer = use_magic elif answer > use_magic: answer = use_magic continue # 上下左右に移動 do_warp = True if maze_check(now_h+1, now_w, use_magic): queue.appendleft((now_h + 1, now_w, use_magic)) warp_count[now_h + 1][now_w] = use_magic do_warp = False if maze_check(now_h-1, now_w, use_magic): queue.appendleft((now_h - 1, now_w, use_magic)) warp_count[now_h - 1][now_w] = use_magic do_warp = False if maze_check(now_h, now_w+1, use_magic): queue.appendleft((now_h, now_w + 1, use_magic)) warp_count[now_h][now_w + 1] = use_magic do_warp = False if maze_check(now_h, now_w-1, use_magic): queue.appendleft((now_h, now_w - 1, use_magic)) warp_count[now_h][now_w - 1] = use_magic do_warp = False if do_warp: warp_queue.appendleft((now_h, now_w, use_magic)) if not queue: while warp_queue: now_h, now_w, use_magic = warp_queue.pop() for y, x in warp_list: warp_h = now_h + y warp_w = now_w + x if maze_check(warp_h, warp_w, use_magic+1): queue.append((warp_h, warp_w, use_magic+1)) warp_count[warp_h][warp_w] = use_magic + 1 print(answer)
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s688731104
Accepted
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
H, W = map(int, input().split()) Ch, Cw = map(int, input().split()) Dh, Dw = map(int, input().split()) S = [0 for i in range(H + 4)] S[0] = "#" * (W + 4) S[1] = "#" * (W + 4) S[H + 2] = "#" * (W + 4) S[H + 3] = "#" * (W + 4) for i in range(2, H + 2): S[i] = "##" + input() + "##" B = [[-1 for i in range(W + 4)] for i in range(H + 4)] def search(i, j, c): global B B[i][j] = c L = [(-1, 0), (1, 0), (0, -1), (0, 1)] for X in L: if S[i + X[0]][j + X[1]] == "." and B[i + X[0]][j + X[1]] < 0: search(i + X[0], j + X[1], c) # <01>[2--H+1]<H+2,3># c = 0 for i in range(2, H + 2): for j in range(2, W + 2): if S[i][j] == "." and B[i][j] < 0: search(i, j, c) c += 1 Cc = B[Ch + 1][Cw + 1] Dc = B[Dh + 1][Dw + 1] dic = {i: set() for i in range(c)} for i in range(2, H + 2): for j in range(2, W + 2): if B[i][j] >= 0: for x in range(-2, 3): for y in range(-2, 3): if S[i + x][j + y] == "." and B[i][j] != B[i + x][j + y]: dic[B[i][j]].add(B[i + x][j + y]) ans = [-1 for i in range(c)] ans[Cc] = 0 not_check = [1 for i in range(c)] not_check[Cc] = 0 next_check = {Cc} # t = 0 while len(next_check): t += 1 tmp = set() for i in next_check: for j in dic[i]: if not_check[j]: not_check[j] = 0 ans[j] = t tmp.add(j) next_check = {i for i in tmp} # print(ans[Dc])
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s522240322
Wrong Answer
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
from sys import stdin import collections input = stdin.readline Y, X = map(int, input().split()) sy, sx = map(int, input().split()) sy -= 1 sx -= 1 ey, ex = map(int, input().split()) ey -= 1 ex -= 1 grid = [[c for c in inp] for inp in stdin.read().splitlines()] dis = [[1000] * X for _ in range(Y)] Q = collections.deque() Q.append( ( sy, sx, ) ) dis[sy][sx] = 0 while Q: cy, cx = Q.popleft() for ny, nx in [(cy + 1, cx), (cy - 1, cx), (cy, cx + 1), (cy, cx - 1)]: if ( 0 <= ny < Y and 0 <= nx < X and grid[ny][nx] == "." and dis[ny][nx] > dis[cy][cx] ): Q.appendleft((ny, nx)) dis[ny][nx] = dis[cy][cx] for dy in range(-2, 3): for dx in range(-2, 3): ny = cy + dy nx = cx + dx if ( 0 <= ny < Y and 0 <= nx < X and grid[ny][nx] == "." and dis[ny][nx] > dis[cy][cx] + 1 ): Q.append((ny, nx)) dis[ny][nx] = dis[cy][cx] + 1 print(dis[ey][ex] if dis[ey][ex] != 1000 else -1)
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead. * * *
s598822774
Accepted
p02579
Input is given from Standard Input in the following format: H W C_h C_w D_h D_w S_{11}\ldots S_{1W} \vdots S_{H1}\ldots S_{HW}
import os import sys import numpy as np from heapq import heappop, heappush def solve(h, w, s, t, field): WARP = ( -(w * 2 + 10), -(w * 2 + 9), -(w * 2 + 8), -(w * 2 + 7), -(w * 2 + 6), -(w + 6), -(w + 5), -(w + 3), -(w + 2), -2, 2, w + 2, w + 3, w + 5, w + 6, w * 2 + 6, w * 2 + 7, w * 2 + 8, w * 2 + 9, w * 2 + 10, ) WALK = (-(w + 4), -1, 1, w + 4) q = [(0, s)] visited = np.zeros((h + 4) * (w + 4), np.int8) while q: cost, v = heappop(q) if v == t: return cost if visited[v]: continue visited[v] = 1 for d in WALK: if field[v + d] or visited[v + d]: continue heappush(q, (cost, d + v)) for d in WARP: if field[v + d] or visited[v + d]: continue heappush(q, (cost + 1, d + v)) return -1 if sys.argv[-1] == "ONLINE_JUDGE": from numba.pycc import CC cc = CC("my_module") cc.export("solve", "(i8,i8,i8,i8,i1[:],)")(solve) cc.compile() exit() if os.name == "posix": # noinspection PyUnresolvedReferences from my_module import solve else: from numba import njit solve = njit("(i8,i8,i8,i8,i1[:],)", cache=True)(solve) print("compiled", file=sys.stderr) h, w = map(int, sys.stdin.readline().split()) ch, cw = map(int, sys.stdin.readline().split()) dh, dw = map(int, sys.stdin.readline().split()) field = np.ones((h + 4) * (w + 4), dtype=np.int8) for i in range(h): line = sys.stdin.readline().strip() field[(i + 2) * (w + 4) + 2 : (i + 2) * (w + 4) + w + 2] = list( map(".#".index, line) ) s = (ch + 1) * (w + 4) + cw + 1 t = (dh + 1) * (w + 4) + dw + 1 ans = solve(h, w, s, t, field) print(ans)
Statement A maze is composed of a grid of H \times W squares - H vertical, W horizontal. The square at the i-th row from the top and the j-th column from the left - (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`. There is a magician in (C_h,C_w). He can do the following two kinds of moves: * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in. * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in. In either case, he cannot go out of the maze. At least how many times does he need to use the magic to reach (D_h, D_w)?
[{"input": "4 4\n 1 1\n 4 4\n ..#.\n ..#.\n .#..\n .#..", "output": "1\n \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n 1 4\n 4 1\n .##.\n ####\n ####\n .##.", "output": "-1\n \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n 2 2\n 3 3\n ....\n ....\n ....\n ....", "output": "0\n \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n 1 2\n 2 5\n #.###\n ####.\n #..##\n #..##", "output": "2"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s818718099
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
a = int(input()) b = int(input()) print('GREATER'if a > b 'EQUAL' elif a == b else 'LESS')
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s832615925
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
A, B = int(input()) for i in range(2) print("GREATER" if A>B else "EQOUL" if A=B else "LESS")
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s434233589
Wrong Answer
p03738
Input is given from Standard Input in the following format: A B
#!usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n): l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n): l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n): l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n): l[i] = SR() return l mod = 1000000007 # A """ s = LS() print(s[0][0].upper()+s[1][0].upper()+s[2][0].upper()) """ # B a, b = IR(2) if a > b: print("LESS") elif a == b: print("EQUAL") else: print("GREATER") # C """ n = I() a = LI() b = [a[i] for i in range(n)] ans = 0 k = a[0] if a[0] == 0: a[0] = 1 ans = 1 k = 1 for i in range(1,n): if k*(k+a[i]) >= 0: if k < 0: ans += abs(1-k-a[i]) a[i] = 1-k k = 1 else: ans += abs(-1-k-a[i]) a[i] = -1-k k = -1 else: k += a[i] if b[0] >= 0: ans2 = b[0]+1 k = -1 b[0] = -1 else: ans2 = 1-b[0] k = 1 b[0] = 1 for i in range(1,n): if k*(k+b[i]) >= 0: if k < 0: ans2 += abs(1-k-b[i]) b[i] = 1-k k = 1 else: ans2 += abs(-1-k-b[i]) b[i] = -1-k k = -1 else: k += b[i] print(min(ans,ans2)) """ # D """ x,y = LI() if abs(x-y) <= 1: print("Brown") else: print("Alice") """ # E # F # G # H # I # J # K # L # M # N # O # P # Q # R # S # T
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s877183249
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
a=int(input()) b=int(input()) import math if math.sqrt(a)==math.sqrt(b): print("EQUAL") elif math.sqrt(a)>math.sqrt(b): print("GREATER") math.sqrt(a)<math.sqrt(b): print("LESS")
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s929587249
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
num=[] for i in [0]*2: num.append(int(input())) if num[0]>num[1]: print("GREATER") elif num[0]=num[1]: print("EQUAL") else: print("LESS")
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s372651354
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
import sys, re from math import ceil, floor, sqrt, pi, factorial, gcd from copy import deepcopy from collections import Counter, deque from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left, bisect_right from functools import reduce from decimal import Decimal, getcontext # input = sys.stdin.readline def i_input(): return int(input()) def i_map(): return map(int, input().split()) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_str(N): return [s_list() for _ in range(N)] def s_row_list(N): return [list(s_input()) for _ in range(N)] def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10 ** 6) INF = float('inf') MOD = 10 ** 9 + 7 num_list = [] str_list = [] def main(): a = i_input() b = i_input() if a == b: print('EQUAL') else: a > b: print('GREATER') else: print('LESS') if __name__ == '__main__': main()
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s280493466
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
a = int(input()) b = int(input()) if a < b: print('LESS'): elif a > b: print('GREATER') else: print('EQUAL')
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s055025648
Accepted
p03738
Input is given from Standard Input in the following format: A B
p = input a = int(p()) - int(p()) print(a > 0 and "GREATER" or "ELQEUSASL"[a < 0 :: 2])
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s352009899
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
a = int(input()) b = int(input()) print('GREATER' if a>b else 'EQUAL' if a==b else 'LESS' if a<b)
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s566459859
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
A = int(input()) B = int(input()) print('LESS' if A < B else 'GREATER' A > B else 'EQUAL')
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s516824920
Wrong Answer
p03738
Input is given from Standard Input in the following format: A B
a, b = [int(input()) for i in range(2)] print("GRATER" if a > b else "LESS" if a < b else "EQUAL")
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s855342263
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
a=int(input()) b=int(input()) if a>b: print("GREATER") else if a==b: print("LESS") else: print("EQUAL")
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s383795579
Wrong Answer
p03738
Input is given from Standard Input in the following format: A B
a = input().split() b = input().split() print("GREATER" if a > b else "LESS")
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s952830386
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
fn main() { let a = read::<String>().chars().collect::<Vec<_>>(); let b = read::<String>().chars().collect::<Vec<_>>(); if a.len() > b.len() { println!("GREATER"); return; } else if a.len() < b.len() { println!("LESS"); return; } else { for i in 0..a.len() { if a[i] > b[i] { println!("GREATER"); return; } else if a[i] < b[i] { println!("LESS"); return; } else { continue; } } } println!("EQUAL"); } #[allow(dead_code)] fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } #[allow(dead_code)] fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } #[allow(dead_code)] fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> { (0..n).map(|_| read_vec()).collect() } #[allow(dead_code)] fn yn(result: bool) { if result { println!("Yes"); } else { println!("No"); } }
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s177831224
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
#include <bits/stdc++.h> #define rep(i, n) for (int i=0; i<n; ++i) #define rep1(i, n) for (int i=1; i<=n; ++i) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) using namespace std; typedef long long ll; typedef pair<ll, ll> P; constexpr ll MOD = (1e9+7); constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } ll factorial(ll n, ll m=2) { // calculate n! m = max(2LL, m); ll rtn = 1; for (ll i=m; i<=n; i++) { rtn = (rtn * i) % MOD; } return rtn; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll modpow(ll a, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(0); string a, b; cin >> a >> b; if (a.size() > b.size()) { cout << "GREATER" << endl; } else if (a.size() < b.size()) { cout << "LESS" << endl; } else { rep(i, a.size()) { if (a[i] > b[i]) {puts("GREATER"); return 0;} else if (a[i] < b[i]) {puts("LESS"); return 0;} } puts("EQUAL"); } return 0; }
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s068355797
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
n = int(input()) a = [int(i) for i in input().split()] s0 = a[0] count = 0 if a[0] == 0: s0 += 1 count += 1 for i in range(1, n): s1 = s0 + a[i] if s0 * s1 >= 0: if s1 > 0: a[i] -= abs(s1) + 1 count += abs(s1) + 1 elif s1 < 0: a[i] += abs(s1) + 1 count += abs(s1) + 1 elif s1 == 0: if s0 > 0: a[i] -= 1 count += 1 elif s0 < 0: a[i] += 1 count += 1 else: break s0 += a[i] print(count)
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s954462829
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
# -*- coding: utf-8 -*- A = int(input()) B = int(input()) S = A-B if S > 0: print("GREATER") elif S = 0: print("EQUAL") else: print("LESS")
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s909960057
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
a=int(input()) b=int(input()) if a>b: print("GREATER") else if a<b: print("LESS") else if a==b: print("EQUAL")
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s293505207
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
a = int(input()) b = int(input()) if a > b: ans = 'GREATER' elif a < b: ans = 'LESS' else: ans = 'EQUAL print(ans)
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s689500538
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
a, b = map(int(input().split()) if a > b: print("GREATER") elif a < b: print("LESS") elif a == b: print("EQUAL")
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s009279642
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
A = int(input()) B = int(input()) if A > B: print("GREATER") eiif A == B: print("EQUAL") else: print("LESS")
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s600377180
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
A = int(input()) B = int(input()) if A > B: print("GREATER") elif A = B: print("EQUAL") else A < B: print("LESS")
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B. * * *
s864950565
Runtime Error
p03738
Input is given from Standard Input in the following format: A B
a = int(input()) b = int(input()) if a > b: print('GREATER') elif a = b: print('EQUAL') else: print('LESS')
Statement You are given two positive integers A and B. Compare the magnitudes of these numbers.
[{"input": "36\n 24", "output": "GREATER\n \n\nSince 36>24, print `GREATER`.\n\n* * *"}, {"input": "850\n 3777", "output": "LESS\n \n\n* * *"}, {"input": "9720246\n 22516266", "output": "LESS\n \n\n* * *"}, {"input": "123456789012345678901234567890\n 234567890123456789012345678901", "output": "LESS"}]
For each data set, if it includes sufficient information to classify all the inhabitants, print the identification numbers of all the divine ones in ascending order, one in a line. In addition, following the output numbers, print "end" in a line. Otherwise, i.e., if a given data set does not include sufficient information to identify all the divine members, print "no" in a line.
s542804803
Wrong Answer
p00817
The input consists of multiple data sets, each in the following format: _n_ _p_ 1 _p_ 2 _x_ 1 _y_ 1 _a_ 1 _x_ 2 _y_ 2 _a_ 2 ... _x_ _i_ _y_ _i_ _a_ _i_ ... _x_ _n_ _y_ _n_ _a_ _n_ The first line has three non-negative integers _n_ , _p_ 1, and _p_ 2. _n_ is the number of questions Akira asked. _p_ 1 and _p_ 2 are the populations of the divine and devilish tribes, respectively, in the legend. Each of the following _n_ lines has two integers _x i_, _y i_ and one word _a i_. _x i_ and _y i_ are the identification numbers of inhabitants, each of which is between 1 and _p_ 1 \+ _p_ 2, inclusive. _a i_ is either "yes", if the inhabitant _x i_ said that the inhabitant _y i_ was a member of the divine tribe, or "no", otherwise. Note that _x i_ and _y i_ can be the same number since "are you a member of the divine tribe?" is a valid question. Note also that two lines may have the same _x_ 's and _y_ 's since Akira was very upset and might have asked the same question to the same one more than once. You may assume that _n_ is less than 1000 and that _p_ 1 and _p_ 2 are less than 300. A line with three zeros, i.e., "0 0 0", represents the end of the input. You can assume that each data set is consistent and no contradictory answers are included.
from collections import defaultdict class UnionFind: def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n def find(self, x): if self.parent[x] == x: return x else: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): x, y = self.find(x), self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.parent[x] = y else: self.parent[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 while True: n, p1, p2 = (int(s) for s in input().split()) if not n: break p = p1 + p2 tree = UnionFind(p * 2) unions = defaultdict(list) for i in range(n): xs, ys, a = input().split() x, y = int(xs) - 1, int(ys) - 1 if a == "yes": tree.unite(x, y) tree.unite(x + p, y + p) else: tree.unite(x, y + p) tree.unite(x + p, y) for i in range(p): unions[tree.find(i)].append(i) roots = [] sides = [] diffs = [] rest = p1 for i in range(p): if i in unions: member_len, backside_len = len(unions[i]), len(unions[i + p]) if member_len == backside_len: rest = -1 break elif member_len < backside_len: diff = backside_len - member_len rest -= member_len sides.append(0) else: diff = member_len - backside_len sides.append(1) rest -= backside_len roots.append(i) diffs.append(diff) if rest < 0: print("no") continue dp = [[1] + [0] * rest for i in range(len(roots) + 1)] for i in reversed(range(len(roots))): for j in range(1, rest + 1): if j < diffs[i]: if dp[i + 1][j]: dp[i][j] = 1 else: dp[i][j] = 0 else: if dp[i + 1][j] and dp[i + 1][j - diffs[i]]: dp[i][j] = 3 elif dp[i + 1][j - diffs[i]]: dp[i][j] = 2 elif dp[i + 1][j]: dp[i][j] = 1 else: dp[i][j] = 0 divines = [] for i in range(len(roots)): if dp[i][rest] == 1: divines.extend(unions[roots[i] + p * sides[i]]) elif dp[i][rest] == 2: divines.extend(unions[roots[i] + p * (1 - sides[i])]) rest -= diffs[i] else: print("no") break else: divines.sort() for divine in divines: print(divine + 1) print("end")
G: True Liars After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despaired, he was still fortunate to remember a legend of the foggy island, which he had heard from patriarchs in his childhood. This must be the island in the legend. In the legend, two tribes have inhabited the island, one is divine and the other is devilish; once members of the divine tribe bless you, your future is bright and promising, and your soul will eventually go to Heaven; in contrast, once members of the devilish tribe curse you, your future is bleak and hopeless, and your soul will eventually fall down to Hell. In order to prevent the worst-case scenario, Akira should distinguish the devilish from the divine. But how? They looked exactly alike and he could not distinguish one from the other solely by their appearances. He still had his last hope, however. The members of the divine tribe are truth-tellers, that is, they always tell the truth and those of the devilish tribe are liars, that is, they always tell a lie. He asked some of the whether or not some are divine. They knew one another very much and always responded to him "faithfully" according to their individual natures (i.e., they always tell the truth or always a lie). He did not dare to ask any other forms of questions, since the legend says that a devilish member would curse a person forever when he did not like the question. He had another piece of useful information: the legend tells the populations of both tribes. These numbers in the legend are trustworthy since everyone living on this island is immortal and none have ever been born at least these millennia. You are a good computer programmer and so requested to help Akira by writing a program that classifies the inhabitants according to their answers to his inquiries.
[{"input": "1 1\n 1 2 no\n 2 1 no\n 3 2 1\n 1 1 yes\n 2 2 yes\n 3 3 yes\n 2 2 1\n 1 2 yes\n 2 3 no\n 5 4 3\n 1 2 yes\n 1 3 no\n 4 5 yes\n 5 6 yes\n 6 7 no\n 0 0 0", "output": "no\n no\n 1\n 2\n end\n 3\n 4\n 5\n 6\n end"}]
Print the number of different grids that can be made, modulo 998244353. * * *
s871024637
Wrong Answer
p02980
Input is given from Standard Input in the following format: N M
def p(i): ans = 1 while i != 1: ans *= i i -= 1 return ans def comb_dp_sub(n, r): global comb_table if r == 0 or n == r: return 1 else: return comb_table[n - 1][r] + comb_table[n - 1][r - 1] def comb_dp(n, r): global comb_table comb_table = [[0] * (n + 1) for _ in range(n + 1)] for i in range(n + 1): for j in range(i + 1): comb_table[i][j] = comb_dp_sub(i, j) return comb_table[n][r] n, m = map(int, input().split()) st = ((n + 1) ** m) * ((m + 1) ** n) general = 0 for i in range(1, min(n, m) + 1): general += comb_dp(n, i) * comb_dp(m, i) * p(i) print(st - general)
Statement We have a square grid with N rows and M columns. Takahashi will write an integer in each of the squares, as follows: * First, write 0 in every square. * For each i=1,2,...,N, choose an integer k_i (0\leq k_i\leq M), and add 1 to each of the leftmost k_i squares in the i-th row. * For each j=1,2,...,M, choose an integer l_j (0\leq l_j\leq N), and add 1 to each of the topmost l_j squares in the j-th column. Now we have a grid where each square contains 0, 1, or 2. Find the number of different grids that can be made this way, modulo 998244353. We consider two grids different when there exists a square with different integers.
[{"input": "1 2", "output": "8\n \n\nLet (a,b) denote the grid where the square to the left contains a and the\nsquare to the right contains b. Eight grids can be made:\n(0,0),(0,1),(1,0),(1,1),(1,2),(2,0),(2,1), and (2,2).\n\n* * *"}, {"input": "2 3", "output": "234\n \n\n* * *"}, {"input": "10 7", "output": "995651918\n \n\n* * *"}, {"input": "314159 265358", "output": "70273732"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s406650200
Accepted
p03387
Input is given from Standard Input in the following format: A B C
A, B, C = map(int, input().split()) m = max(A, B, C) * 3 s = A + B + C ans = m - s if ans % 2 == 1: ans += 3 print(ans // 2)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s497443902
Accepted
p03387
Input is given from Standard Input in the following format: A B C
L1 = list(map(int, input().split())) L1.sort() L2 = [L1[-1] - L1[i] for i in range(2)] L2.sort() P = L2[0] Q = L2[1] ans = P Q -= P ans += Q // 2 Q %= 2 ans += Q * 2 print(ans)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s061985791
Accepted
p03387
Input is given from Standard Input in the following format: A B C
l = sorted(map(int, input().split())) a = (l[2] - l[0]) // 2 b = (l[2] - l[1]) // 2 l[0] += a * 2 l[1] += b * 2 if sum(l) == l[2] * 3: print(a + b) elif sum(l) == l[2] * 3 - 1: print(a + b + 2) elif sum(l) == l[2] * 3 - 2: print(a + b + 1)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s981197721
Accepted
p03387
Input is given from Standard Input in the following format: A B C
a, b, c = map(int, input().split()) p = a % 2 != b % 2 or b % 2 != c % 2 a, b, c = [ a + ((a % 2 == b % 2) ^ (a % 2 == c % 2)), b + ((b % 2 == a % 2) ^ (b % 2 == c % 2)), c + ((c % 2 == a % 2) ^ (c % 2 == b % 2)), ] a, b, c = sorted([a, b, c]) print((c - a) // 2 + (c - b) // 2 + p)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s350720617
Accepted
p03387
Input is given from Standard Input in the following format: A B C
a = list(map(int, input().split())) a = sorted(a) A = a[0] B = a[1] C = a[2] if A % 2 == 0 and B % 2 == 0 and C % 2 == 0: ans = (C - A) / 2 + (C - B) / 2 elif A % 2 == 0 and B % 2 == 0 and C % 2 == 1: ans = (C - A - 1) / 2 + (C - B - 1) / 2 + 1 elif A % 2 == 0 and B % 2 == 1 and C % 2 == 0: ans = (C - A) / 2 + (C - B + 1) / 2 + 1 elif A % 2 == 1 and B % 2 == 0 and C % 2 == 0: ans = (C - A + 1) / 2 + (C - B) / 2 + 1 elif A % 2 == 1 and B % 2 == 1 and C % 2 == 0: ans = (C - A - 1) / 2 + (C - B - 1) / 2 + 1 elif A % 2 == 1 and B % 2 == 1 and C % 2 == 1: ans = (C - A) / 2 + (C - B) / 2 elif A % 2 == 1 and B % 2 == 0 and C % 2 == 1: ans = (C - A) / 2 + (C - B + 1) / 2 + 1 elif A % 2 == 0 and B % 2 == 1 and C % 2 == 1: ans = (C - A + 1) / 2 + (C - B) / 2 + 1 print(int(ans))
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s710314095
Accepted
p03387
Input is given from Standard Input in the following format: A B C
s = [int(i) for i in input().split()] s.sort(reverse=True) if s[0] == s[1] and s[1] == s[2]: print(0) elif s[0] == s[1]: if (s[0] - s[2]) % 2 == 0: print((s[0] - s[2]) // 2) else: print(1 + (s[0] + 1 - s[2]) // 2) elif s[1] == s[2]: print(s[0] - s[2]) else: if (s[1] - s[2]) % 2 == 0: print(s[0] - s[1] + (s[1] - s[2]) // 2) else: print(s[0] - s[1] + 1 + (s[1] - s[2] + 1) // 2)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s323385048
Wrong Answer
p03387
Input is given from Standard Input in the following format: A B C
n = list(map(int, input().split())) n.sort(reverse=True) a = n[0] - n[1] b = n[0] - n[2] if a == 0 and b == 0: print(0) if a != 0 and b == 0: if a % 2 == 0: print(a / 2) elif a == 1: print(2) elif a % 2 != 0: print(2 + (a - 1) / 2) if a == 0 and b != 0: if b % 2 == 0: print(b / 2) elif b == 1: print(2) elif b % 2 != 0: print(2 + (b - 1) / 2) if a != 0 and b != 0: if a == 1 and b == 1: print(1) elif a % 2 == 0 and b % 2 == 0: print(a / 2 + b / 2) elif a % 2 != 0 and b % 2 == 0: print(2 + (a - 1) / 2 + b / 2) elif a % 2 == 0 and b % 2 != 0: print(2 + a / 2 + (b - 1) / 2) elif a % 2 != 0 and b % 2 != 0: print(1 + (a - 1) / 2 + (b - 1) / 2)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s275066319
Accepted
p03387
Input is given from Standard Input in the following format: A B C
L = sorted(map(int, input().split())) if L[0] == L[2]: print(0) exit() if L[0] == L[1]: print(L[2] - L[0]) exit() if L[1] == L[2]: t = L[2] - L[0] print(t // 2 if t % 2 == 0 else 2 + t // 2) exit() count = L[2] - L[1] t = L[2] - L[0] - count print(count + t // 2 if t % 2 == 0 else count + 2 + t // 2)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s139152939
Wrong Answer
p03387
Input is given from Standard Input in the following format: A B C
As = [int(i) for i in input(">> ").split()] As.sort() As.reverse() o = 0 diff = As[0] - As[1] div, mod = divmod(diff, 2) o += div if mod == 1: As[2] += 1 o += 1 diff = As[0] - As[2] div, mod = divmod(diff, 2) o += div if mod == 1: o += 1 o += mod print(o)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s627897251
Wrong Answer
p03387
Input is given from Standard Input in the following format: A B C
A, B, C = map(int, input().split()) ABC = sorted([A, B, C]) counter = 0 for i in range(ABC[1], ABC[2]): ABC[0] += 1 ABC[1] += 1 counter += 1 while ABC[0] + 2 <= ABC[1]: ABC[0] += 2 counter += 1 if ABC[0] != ABC[1]: ABC[1] += 1 ABC[2] += 1 counter += 1 ABC[0] += 2 counter += 1 ABC, counter
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s158519500
Wrong Answer
p03387
Input is given from Standard Input in the following format: A B C
l = sorted(map(int, input().split())) c = 0 if (l[0] % 2 == 0 and l[1] % 2 == 1) or (l[0] % 2 == 1 and l[1] % 2 == 0): l[0] += 1 l[2] += 1 c = 1 c += (l[2] - l[0]) // 2 c += (l[2] - l[1]) // 2 l[0] += (l[2] - l[0]) // 2 * 2 l[1] += (l[2] - l[1]) // 2 * 2 c += l[2] - l[0] c += l[2] - l[1] print(c)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s404618874
Accepted
p03387
Input is given from Standard Input in the following format: A B C
s = sorted(list(map(int, input().split()))) a = s[2] - s[1] c = s[2] - s[0] - a if c % 2 == 0: print(c // 2 + a) else: print(c // 2 + a + 2)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s460784991
Accepted
p03387
Input is given from Standard Input in the following format: A B C
A, B, C = sorted(list(map(int, input().split(" ")))) if (C - A) % 2 == (C - B) % 2: print(C - (A + B) // 2) else: print(C - (A + B) // 2 + 1)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s731025489
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
2 6 3
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s041948041
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
item = list(map(int, input().split())).sorted() print(item)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s527007154
Wrong Answer
p03387
Input is given from Standard Input in the following format: A B C
A, B, C = sorted(map(int, input().split())) if C % 2 == 0: C += 1 print((2 * C - A - B) // 2 + (2 * C - A - B) % 2)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s990445178
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
A,B,C=map(int,input().split()) total=abs(max(A,B,C)-A)+abs(max(A,B,C)-B)+abs(max(A,B,C)-C) if total%2==0: print(total//2) else: print((total+1)//2+
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s932004745
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
L = list(map(int, input().split())).sort(reverse=True) m = (L[0] - L[1]) % 2 - (L[0] - L[2]) % 2 if m == 0: print(L[0] + (-L[1] - L[2]) // 2) else: print(L[0] + (-L[1] - L[2] + 3) // 2)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s759386329
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
Bottom = min(A, B, C) Middle = A + B + C - Top - Bottom if (Middle - Bottom) % 2 != 0: Top += 1 Bottom += 1 Answer = (Top - Middle) + (Middle - Bottom) // 2 + 1 else: Answer = (Top - Middle) + (Middle - Bottom) // 2 print(Answer)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s500711116
Wrong Answer
p03387
Input is given from Standard Input in the following format: A B C
n_list = list(map(int, input().split())) n_list.sort num = 2 * n_list[2] dummy = num - (n_list[0] + n_list[1]) a, b = divmod(dummy, 2) if b == 0: print(a) else: print(a + 2)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s436434522
Wrong Answer
p03387
Input is given from Standard Input in the following format: A B C
temp = input() a, b, c = temp.split() a = int(a) b = int(b) c = int(c) inp = [a, b, c] inp = sorted(inp) print(inp) dif = inp[2] - inp[0] + inp[2] - inp[1] if dif % 2 == 0: print(dif // 2) else: print((dif + 3) // 2)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s603145375
Accepted
p03387
Input is given from Standard Input in the following format: A B C
def c_same_integers(A, B, C): # A,B,Cの和と、これらのうち最大のもの(Mとする)との偶奇が一致するなら、 # 最終的に3つの整数はMとなる # 偶奇が一致しないなら、最終的に3つの整数はM+1となる m = max(A, B, C) parity = 3 * max(A, B, C) % 2 == (A + B + C) % 2 max_value = m if parity else m + 1 # 3数の和は1回の操作で2増えるため,ans回の操作が必要 ans = (3 * max_value - (A + B + C)) // 2 return ans A, B, C = [int(i) for i in input().split()] print(c_same_integers(A, B, C))
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s169427270
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
T = list(map(int, input().split())) T.sort() T.reverse() ope = 0 while T[1]!=T[0]: ope += 1 T[1] += 1 T[2] += 1 while T[2]<T[0]: ope += 1 T[2] += 2 if T[0]==T[2]: print(ope) else:print(ope+1)T = list(map(int, input().split())) T.sort() T.reverse() ope = 0 while T[1]!=T[0]: ope += 1 T[1] += 1 T[2] += 1 while T[2]<T[0]: ope += 1 T[2] += 2 if T[0]==T[2]: print(ope) else:print(ope+1)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s326376851
Accepted
p03387
Input is given from Standard Input in the following format: A B C
a, b, c = map(int, input().split()) num1 = max(a, b, c) if num1 == a: num2 = a - b num3 = a - c elif num1 == b: num2 = b - a num3 = b - c else: num2 = c - a num3 = c - b num4 = abs(num2 - num3) if num4 % 2 == 0: print((num2 + num3) // 2) else: print((num2 + num3) // 2 + 2)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s902348550
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
import java.util.*; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); int sum = 0; int max = 0; for(int i = 0;i < 3; ++i){ int input = Integer.parseInt(scan.next()); sum += input; max = Math.max(max,input); } int ans = 0; while(sum < max*3 || sum%3 != 0){ sum += 2; ++ans; } System.out.print(ans); } }
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s018512134
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
ABC = [int(i) for i in input().split()] m = sorted(ABC) count = 0 if m[2]%2 == 0: m[2] += 1 if m[0]%2 == 0: m[0] += 1 else : m[1] + = 1 count += 1 n = m[1] - m[0] l = m[2] - m[1] print(n//2 + l + count)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s705117515
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
a,b,c=map(int,input().split()) ans=0 ma=max(a,b,c) mi=min(a,b,c) mj=a+b+c-ma-mi ans+=(ma-mi)//2 mi+==((ma-mi)//2)*2 ans+=(ma-mj)//2 mj+=((ma-mj)//2)*2 if ma==mi==mj: print(ans) elif ma==mi+1 and ma==mj+1: print(ans+1) else: print(ans+2)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s405949109
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
ABC = [int(i) for i in input().split()] m = sorted(ABC) count = 0 if m[2]%2 == 0: m[2] += 1 if m[0]%2 == 0: m[0] += 1 else: m[1] + = 1 count += 1 n = m[1] - m[0] l = m[2] - m[1] print(n//2 + l + count)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s039346649
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
# coding:utf-8 import sys def main(): input_list = list(map(int, input().split())) input_list.sort(reverse=True) diff = input_list[0] - input_list][1] + input_list[0] - input_list[2] ans = diff /2 if diff % 2 == True: ans += 2 print(ans) if __name__ == '__main__' : main()
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s373705836
Wrong Answer
p03387
Input is given from Standard Input in the following format: A B C
L = list(map(int, input().split())) L.sort(reverse=True) # print(L) ans = 0 if all(L[i] % 2 == 1 for i in range(3)) or all(L[i] % 2 == 0 for i in range(3)): print((L[0] - L[1]) // 2 + (L[0] - L[2]) // 2) elif L[0] % 2 == 1 and L[1] % 2 == 1 and L[2] % 2 == 0: print((L[0] + 1 - L[2]) // 2 + (L[1] + 1 - L[2]) // 2 + 1) elif L[0] % 2 == 1 and L[1] % 2 == 0 and L[2] % 2 == 0: print(abs(L[1] + 1 - L[0]) // 2 + abs(L[2] + 1 - L[0]) // 2 + 1) elif L[0] % 2 == 1 and L[1] % 2 == 0 and L[2] % 2 == 1: print((L[0] + 1 - L[1]) // 2 + (L[0] + 1 - L[1]) // 2 + 1) elif L[0] % 2 == 0 and L[1] % 2 == 0 and L[2] % 2 == 1: print((L[0] + 1 - L[2]) // 2 + (L[0] + 1 - L[2]) // 2 + 1) elif L[0] % 2 == 0 and L[1] % 2 == 1 and L[2] % 2 == 0: print((L[0] + 1 - L[1]) // 2 + (L[0] + 1 - L[2]) // 2 + 1) elif L[0] % 2 == 0 and L[1] % 2 == 1 and L[2] % 2 == 1: print(abs((L[1] + 1 - L[0]) // 2) + abs(L[2] + 1 - L[0]) // 2 + 1)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s257968182
Accepted
p03387
Input is given from Standard Input in the following format: A B C
A, B, C = map(int, input().split()) a = max(A, B, C) c = min(A, B, C) b = A + B + C - a - c ans = a - b if (b - c) % 2 == 0: print(ans + (b - c) // 2) else: print(2 + ans + (b - c) // 2)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s885203455
Wrong Answer
p03387
Input is given from Standard Input in the following format: A B C
(*A,) = sorted(map(int, input().split())) print( (A[2] - A[1]) + int(-~(A[1] - A[0]) / 2) if (A[1] - A[0]) % 2 == 0 else A[1] + A[2] - 2 * A[0] )
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s253001007
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
if __name__ == '__main__':
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s278200499
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
def resolve(): a,b,c=sorted(list(map(int,input().split()))) ans=c-b a+=c-b b=c if (c-a)%2==0: print(ans+(c-a)//2) else: print(ans+2+(c-a)//2) resolve(
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print the minimum number of operations required to make A, B and C all equal. * * *
s756338244
Runtime Error
p03387
Input is given from Standard Input in the following format: A B C
# https://atcoder.jp/contests/abc093/tasks/arc094_a a, b, c = map(int, input().split()) nums = [a, b, c] nums.sort() ans = 0 if (nums[1] - nums[0]) % 2 == 1: # 小さい2つの差が奇数の場合、偶数になるように # 小さい2つの数字両方にならないように、1を足す。 # ここでは、二番目に大きいのと、最大の数に1を足す。 nums[1] += 1 nums[2] += 1 ans += 1 ans += (nums[1] - nums[0]) // 2 # 一番小さい数が、二番目に大きい数に追いつくようにする。それには2ずつ足すのが良い。 ans += (nums[2] - nums[1]) # 一番目も二番目も同じかずになったので、両方に1つづ足していき、最大の数と同じになる様にする。 print(ans)
Statement You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
[{"input": "2 5 4", "output": "2\n \n\nWe can make A, B and C all equal by the following operations:\n\n * Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.\n * Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.\n\n* * *"}, {"input": "2 6 3", "output": "5\n \n\n* * *"}, {"input": "31 41 5", "output": "23"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s338013192
Runtime Error
p04012
The input is given from Standard Input in the following format: w
w = input() X = [0 for i in range(26)] for i in range(len(w)): X[ord(w[i]) - 97] ^= 1 if sum(X) == 0: print("Yes") else: print("No)
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s059686949
Runtime Error
p04012
The input is given from Standard Input in the following format: w
w = input() for i in w: if w.count(i)%2! = 0: ans = "No" break else: ans = "Yes" print(ans)
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s310180785
Runtime Error
p04012
The input is given from Standard Input in the following format: w
print("Yes" if all(input().count(i) % 2 == 0 for i in set(s)) else "No")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s123754811
Runtime Error
p04012
The input is given from Standard Input in the following format: w
w = input() for i in w: if w.count(i)%2! = 0: print("No") break else: print("Yes")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s283050959
Runtime Error
p04012
The input is given from Standard Input in the following format: w
w = input() for i in w: if w.count(i)%2! = 0: ans = "No" break else: ans = "Yes" print(ans)
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s844195697
Runtime Error
p04012
The input is given from Standard Input in the following format: w
w = input() for i in w: if w.count(i)%2! = 0: print("No") break else: print("Yes")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s925018198
Accepted
p04012
The input is given from Standard Input in the following format: w
text = input() print("No" if any([text.count(x) & 1 for x in set(text)]) else "Yes")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s437773252
Runtime Error
p04012
The input is given from Standard Input in the following format: w
n = input() ans = 0 for i ih set(n): if n.count(i) % 2 == 0: ans += 1 if ans == len(set(n)): print("Yes") else: print("No")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s384414749
Runtime Error
p04012
The input is given from Standard Input in the following format: w
s = input() d = {} for i in s: if i in d: d[i] += 1 else: d[i] = 1 for key in d: if d[key] %2 != 0 print("No") break
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s686970665
Accepted
p04012
The input is given from Standard Input in the following format: w
# #    ⋀_⋀ #    (・ω・) # ./ U ∽ U\ # │* 合 *│ # │* 格 *│ # │* 祈 *│ # │* 願 *│ # │*   *│ #  ̄ # import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline from math import floor, ceil, sqrt, factorial, log # log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter, defaultdict, deque from itertools import ( accumulate, permutations, combinations, product, combinations_with_replacement, ) from bisect import bisect_left, bisect_right from copy import deepcopy inf = float("inf") mod = 10**9 + 7 def pprint(*A): for a in A: print(*a, sep="\n") def INT_(n): return int(n) - 1 def MI(): return map(int, input().split()) def MF(): return map(float, input().split()) def MI_(): return map(INT_, input().split()) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n: int): return [I() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split())) for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace("\n", "") def main(): S = ST() d = defaultdict(int) for s in S: d[s] += 1 for v in d.values(): if v & 1: print("No") exit() print("Yes") if __name__ == "__main__": main()
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s237881373
Runtime Error
p04012
The input is given from Standard Input in the following format: w
s = input() d = {} for i in s: d.get(i, 0) += 1 for i in set(s): if i % 2 == 1: print("No") break else: print("Yes")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s690574764
Accepted
p04012
The input is given from Standard Input in the following format: w
W = str(input()) if W.count("a") % 2 == 0: if W.count("b") % 2 == 0: if W.count("c") % 2 == 0: if W.count("d") % 2 == 0: if W.count("e") % 2 == 0: if W.count("f") % 2 == 0: if W.count("g") % 2 == 0: if W.count("h") % 2 == 0: if W.count("i") % 2 == 0: if W.count("j") % 2 == 0: if W.count("k") % 2 == 0: if W.count("l") % 2 == 0: if W.count("m") % 2 == 0: if W.count("n") % 2 == 0: if W.count("o") % 2 == 0: if W.count("p") % 2 == 0: if ( W.count("q") % 2 == 0 ): if ( W.count("r") % 2 == 0 ): if ( W.count("s") % 2 == 0 ): if ( W.count( "t" ) % 2 == 0 ): if ( W.count( "u" ) % 2 == 0 ): if ( W.count( "v" ) % 2 == 0 ): if ( W.count( "w" ) % 2 == 0 ): if ( W.count( "x" ) % 2 == 0 ): if ( W.count( "y" ) % 2 == 0 ): if ( W.count( "z" ) % 2 == 0 ): print( "Yes" ) exit() print("No")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s215648507
Runtime Error
p04012
The input is given from Standard Input in the following format: w
S = str(input()) s_list = "abcdefghijklmnopqrstuvwxyz" n_list = [] for i in range(26): n_list.append(0) for i in range(len(S)): n_list.index(S[i]) = n_list.index(S[i]) + 1 num = 1 for i in range(26): num = num * (n_list[i] + 1) if num % 2 == 1: print("Yes") else: print("No")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s599294775
Runtime Error
p04012
The input is given from Standard Input in the following format: w
s = input() t = input() letters = [] count = [] for i in range(len(s)): if s[i] in letters: count[letters.index(s[i])].append(i) else: count.append([i]) letters.append(s[i]) failflag = 0 for i in count: r = t[i[0]] for j in i: if t[j] != r: failflag = 1 letters = [] count = [] for i in range(len(s)): if t[i] in letters: count[letters.index(t[i])].append(i) else: count.append([i]) letters.append(t[i]) for i in count: r = s[i[0]] for j in i: if s[j] != r: failflag = 1 if failflag == 0: print("Yes") else: print("No")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s503918472
Runtime Error
p04012
The input is given from Standard Input in the following format: w
from collections import Counter r = 0 cnt = Counter(input()): for c in cnt: r += cnt[c] % 2 if r == 0: print("Yes") else: print("No")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s210261719
Wrong Answer
p04012
The input is given from Standard Input in the following format: w
w1 = [s for s in input()] w2 = [w1.count(a) for a in list(set(w1))] w3 = [w for w in w2 if w % 2 == 0] print(("YES" if len(w3) == len(w2) else "NO"))
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s440786595
Runtime Error
p04012
The input is given from Standard Input in the following format: w
w = input() a = "abcdefghijklmnopqrstuvwxyz" co = 0 ch = True for i in a: for j in w: if i = j: co += 1: if co % 2: ch = False break co = 0 if ch: print("yes") else: print("No")
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]
Print `Yes` if w is beautiful. Print `No` otherwise. * * *
s977639160
Runtime Error
p04012
The input is given from Standard Input in the following format: w
#include <iostream> #include <string> #include <map> #include <cfenv> #include <cmath> #include <vector> #include<cstdio> #include <iterator> #include <sstream> #include <algorithm> #include <numeric> using namespace std; typedef long long ll; int main() { string s; cin >> s; vector<int> c(26,0); for (int a = 0; a < s.size(); a++) { c[s[a] - 97]++; } bool f = true; for (int a = 0; a < c.size(); a++) { if (c[a] % 2 == 1)f = false; } cout <<(f?"Yes":"No")<< endl; }
Statement Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
[{"input": "abaccaba", "output": "Yes\n \n\n`a` occurs four times, `b` occurs twice, `c` occurs twice and the other\nletters occur zero times.\n\n* * *"}, {"input": "hthth", "output": "No"}]