Submission #64537711


Source Code Expand

Copy
h, w = map(int, input().split())
from collections import deque
q = deque()
s = [input() for _ in range(h)]
a, b, c, d = map(lambda x: int(x) - 1, input().split())
dxy = [0, 1, 0, -1, 0]
inf = 1 << 60
ans = [[inf] * w for _ in range(h)]
q.append((a, b, 0))
while q:
y, x, cost = q.popleft()
#print(y, x, cost)
if y == c and x == d:
exit(print(cost))
for i in range(4):
ny, nx = y + dxy[i], x + dxy[i + 1]
if 0 <= ny < h and 0 <= nx < w:
if s[ny][nx] == "." and ans[ny][nx] > cost:
q.appendleft((ny, nx, cost))
ans[ny][nx] = cost
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
h, w = map(int, input().split())
from collections import deque

q = deque()
s = [input() for _ in range(h)]
a, b, c, d = map(lambda x: int(x) - 1, input().split())
dxy = [0, 1, 0, -1, 0]
inf = 1 << 60
ans = [[inf] * w for _ in range(h)]
q.append((a, b, 0))
while q:
    y, x, cost = q.popleft()
    #print(y, x, cost)
    if y == c and x == d:
        exit(print(cost))
    for i in range(4):
        ny, nx = y + dxy[i], x + dxy[i + 1]
        if 0 <= ny < h and 0 <= nx < w:
            if s[ny][nx] == "." and ans[ny][nx] > cost:
                q.appendleft((ny, nx, cost))
                ans[ny][nx] = cost
            elif s[ny][nx] == "#" and ans[ny][nx] >= cost + 1:
                q.append((ny, nx, cost + 1))
                # print(y, x, cost)
                ans[ny][nx] = cost + 1
                nny, nnx = ny + dxy[i], nx + dxy[i + 1]
                if 0 <= nny < h and 0 <= nnx < w and ans[nny][nnx] > cost + 1:
                    q.append((nny, nnx, cost + 1))
                    ans[nny][nnx] = cost + 1

Submission Info

Submission Time
Task D - Takahashi the Wall Breaker
User juten
Language Python (PyPy 3.10-v7.3.12)
Score 400
Code Size 1056 Byte
Status AC
Exec Time 495 ms
Memory 259964 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 34
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt, example_03.txt
All example_00.txt, example_01.txt, example_02.txt, example_03.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 84 ms 77140 KB
example_01.txt AC 83 ms 77084 KB
example_02.txt AC 84 ms 76940 KB
example_03.txt AC 90 ms 81728 KB
hand_00.txt AC 297 ms 109612 KB
hand_01.txt AC 223 ms 99764 KB
hand_02.txt AC 221 ms 100128 KB
hand_03.txt AC 262 ms 107084 KB
hand_04.txt AC 297 ms 109916 KB
hand_05.txt AC 276 ms 119372 KB
hand_06.txt AC 272 ms 119412 KB
hand_07.txt AC 495 ms 259964 KB
hand_08.txt AC 236 ms 139760 KB
hand_09.txt AC 84 ms 77024 KB
random_00.txt AC 185 ms 97052 KB
random_01.txt AC 106 ms 84476 KB
random_02.txt AC 176 ms 95544 KB
random_03.txt AC 195 ms 98396 KB
random_04.txt AC 251 ms 101904 KB
random_05.txt AC 114 ms 84524 KB
random_06.txt AC 196 ms 123536 KB
random_07.txt AC 196 ms 123240 KB
random_08.txt AC 280 ms 162332 KB
random_09.txt AC 300 ms 179584 KB
random_10.txt AC 227 ms 135756 KB
random_11.txt AC 197 ms 127820 KB
random_12.txt AC 132 ms 92720 KB
random_13.txt AC 333 ms 107128 KB
random_14.txt AC 168 ms 94332 KB
random_15.txt AC 214 ms 99840 KB
random_16.txt AC 174 ms 94696 KB
random_17.txt AC 182 ms 96328 KB
random_18.txt AC 195 ms 98672 KB
random_19.txt AC 316 ms 108876 KB


2025-04-07 (Mon)
15:44:38 +09:00