結果

問題 No.340 雪の足跡
ユーザー maspymaspy
提出日時 2020-03-21 13:26:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 738 ms / 1,000 ms
コード長 1,330 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 218,252 KB
最終ジャッジ日時 2023-08-23 12:37:26
合計ジャッジ時間 14,042 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,520 KB
testcase_01 AC 88 ms
71,820 KB
testcase_02 AC 86 ms
71,772 KB
testcase_03 AC 87 ms
71,640 KB
testcase_04 AC 87 ms
71,832 KB
testcase_05 AC 88 ms
71,780 KB
testcase_06 AC 88 ms
71,664 KB
testcase_07 AC 88 ms
71,520 KB
testcase_08 AC 87 ms
71,520 KB
testcase_09 AC 89 ms
71,832 KB
testcase_10 AC 88 ms
71,820 KB
testcase_11 AC 116 ms
77,924 KB
testcase_12 AC 115 ms
78,152 KB
testcase_13 AC 117 ms
78,024 KB
testcase_14 AC 158 ms
86,040 KB
testcase_15 AC 169 ms
84,696 KB
testcase_16 AC 145 ms
82,996 KB
testcase_17 AC 160 ms
83,916 KB
testcase_18 AC 164 ms
84,944 KB
testcase_19 AC 162 ms
84,240 KB
testcase_20 AC 349 ms
149,352 KB
testcase_21 AC 167 ms
77,816 KB
testcase_22 AC 171 ms
138,300 KB
testcase_23 AC 441 ms
210,172 KB
testcase_24 AC 258 ms
131,728 KB
testcase_25 AC 345 ms
166,904 KB
testcase_26 AC 152 ms
78,272 KB
testcase_27 AC 112 ms
77,400 KB
testcase_28 AC 150 ms
79,612 KB
testcase_29 AC 500 ms
156,280 KB
testcase_30 AC 408 ms
138,000 KB
testcase_31 AC 658 ms
203,664 KB
testcase_32 AC 738 ms
217,616 KB
testcase_33 AC 688 ms
215,796 KB
testcase_34 AC 725 ms
217,760 KB
testcase_35 AC 653 ms
218,012 KB
testcase_36 AC 655 ms
218,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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)
0