結果
| 問題 | No.340 雪の足跡 |
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-21 13:26:37 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 679 ms / 1,000 ms |
| コード長 | 1,330 bytes |
| コンパイル時間 | 426 ms |
| コンパイル使用メモリ | 82,368 KB |
| 実行使用メモリ | 214,016 KB |
| 最終ジャッジ日時 | 2024-12-21 15:38:43 |
| 合計ジャッジ時間 | 10,951 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 32 |
ソースコード
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
W, H, Q = map(int, readline().split())
N = H * W
horizonal_max = list(range(N))
vertical_max = list(range(N))
for _ in range(Q):
M = int(readline())
B = map(int, readline().split())
x = next(B)
for y in B:
a, b = x, y
if a > b:
a, b = b, a
if b - a < W:
if horizonal_max[a] < b:
horizonal_max[a] = b
else:
if vertical_max[a] < b:
vertical_max[a] = b
x = y
graph = [[] for _ in range(N)]
for i in range(N):
h = horizonal_max[i]
if h > i:
if horizonal_max[i + 1] < h:
horizonal_max[i + 1] = h
graph[i].append(i + 1)
graph[i + 1].append(i)
v = vertical_max[i]
if v > i:
if vertical_max[i + W] < v:
vertical_max[i + W] = v
graph[i].append(i + W)
graph[i + W].append(i)
INF = N + 10
dist = [INF] * N
dist[0] = 0
q = deque([0])
while q:
v = q.popleft()
dw = dist[v] + 1
for w in graph[v]:
if dist[w] <= dw:
continue
dist[w] = dw
q.append(w)
x = dist[-1]
if x == INF:
x = 'Odekakedekinai..'
print(x)
maspy