Submission #64537128
Source Code Expand
Copy
h, w = map(int, input().split())from heapq import *q = []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 << 60ans = [[inf] * w for _ in range(h)]heappush(q, (0, a, b))while q:cost, y, x = heappop(q)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:heappush(q, (cost, ny, nx))ans[ny][nx] = costelif s[ny][nx] == "#" and ans[ny][nx] >= cost + 1:heappush(q, (cost + 1, ny, nx))ans[ny][nx] = cost + 1
h, w = map(int, input().split())
from heapq import *
q = []
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)]
heappush(q, (0, a, b))
while q:
cost, y, x = heappop(q)
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:
heappush(q, (cost, ny, nx))
ans[ny][nx] = cost
elif s[ny][nx] == "#" and ans[ny][nx] >= cost + 1:
heappush(q, (cost + 1, ny, nx))
ans[ny][nx] = cost + 1
nny, nnx = ny + dxy[i], nx + dxy[i + 1]
if 0 <= nny < h and 0 <= nnx < w:
heappush(q, (cost + 1, nny, nnx))
ans[nny][nnx] = cost + 1
print(ans[c][d])
#print(ans[c])
Submission Info
| Submission Time | |
|---|---|
| Task | D - Takahashi the Wall Breaker |
| User | juten |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 0 |
| Code Size | 938 Byte |
| Status | TLE |
| Exec Time | 2227 ms |
| Memory | 376816 KB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 400 | ||||||
| Status |
|
|
| 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 | 61 ms | 76472 KB |
| example_01.txt | AC | 60 ms | 76632 KB |
| example_02.txt | AC | 61 ms | 76584 KB |
| example_03.txt | AC | 79 ms | 82572 KB |
| hand_00.txt | TLE | 2225 ms | 313964 KB |
| hand_01.txt | TLE | 2215 ms | 165988 KB |
| hand_02.txt | TLE | 2217 ms | 196752 KB |
| hand_03.txt | TLE | 2223 ms | 316760 KB |
| hand_04.txt | TLE | 2218 ms | 212016 KB |
| hand_05.txt | TLE | 2222 ms | 314292 KB |
| hand_06.txt | TLE | 2222 ms | 313960 KB |
| hand_07.txt | TLE | 2227 ms | 376816 KB |
| hand_08.txt | AC | 992 ms | 95760 KB |
| hand_09.txt | AC | 65 ms | 76792 KB |
| random_00.txt | AC | 1602 ms | 111208 KB |
| random_01.txt | AC | 1632 ms | 112964 KB |
| random_02.txt | TLE | 2217 ms | 190896 KB |
| random_03.txt | TLE | 2216 ms | 171560 KB |
| random_04.txt | TLE | 2223 ms | 322108 KB |
| random_05.txt | TLE | 2223 ms | 322248 KB |
| random_06.txt | TLE | 2223 ms | 324436 KB |
| random_07.txt | TLE | 2222 ms | 326168 KB |
| random_08.txt | TLE | 2223 ms | 289632 KB |
| random_09.txt | TLE | 2224 ms | 324316 KB |
| random_10.txt | TLE | 2222 ms | 325492 KB |
| random_11.txt | TLE | 2225 ms | 322612 KB |
| random_12.txt | TLE | 2215 ms | 160396 KB |
| random_13.txt | TLE | 2216 ms | 173260 KB |
| random_14.txt | TLE | 2215 ms | 158524 KB |
| random_15.txt | TLE | 2215 ms | 165628 KB |
| random_16.txt | TLE | 2215 ms | 160792 KB |
| random_17.txt | TLE | 2223 ms | 321340 KB |
| random_18.txt | TLE | 2227 ms | 365116 KB |
| random_19.txt | TLE | 2222 ms | 320268 KB |