結果

問題 No.340 雪の足跡
ユーザー maspymaspy
提出日時 2020-03-21 13:52:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 715 ms / 1,000 ms
コード長 1,430 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 225,692 KB
最終ジャッジ日時 2023-08-23 12:52:49
合計ジャッジ時間 11,068 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
70,988 KB
testcase_01 AC 69 ms
71,108 KB
testcase_02 AC 70 ms
71,208 KB
testcase_03 AC 70 ms
71,080 KB
testcase_04 AC 69 ms
71,324 KB
testcase_05 AC 70 ms
71,284 KB
testcase_06 AC 70 ms
71,312 KB
testcase_07 AC 70 ms
71,100 KB
testcase_08 AC 70 ms
70,984 KB
testcase_09 AC 69 ms
71,324 KB
testcase_10 AC 71 ms
71,104 KB
testcase_11 AC 98 ms
76,408 KB
testcase_12 AC 96 ms
76,348 KB
testcase_13 AC 99 ms
76,792 KB
testcase_14 AC 133 ms
81,680 KB
testcase_15 AC 135 ms
80,544 KB
testcase_16 AC 128 ms
80,128 KB
testcase_17 AC 157 ms
90,880 KB
testcase_18 AC 156 ms
90,556 KB
testcase_19 AC 157 ms
90,508 KB
testcase_20 AC 351 ms
165,380 KB
testcase_21 AC 136 ms
80,356 KB
testcase_22 AC 145 ms
134,352 KB
testcase_23 AC 434 ms
225,692 KB
testcase_24 AC 260 ms
151,860 KB
testcase_25 AC 320 ms
174,204 KB
testcase_26 AC 131 ms
79,896 KB
testcase_27 AC 89 ms
76,168 KB
testcase_28 AC 138 ms
84,484 KB
testcase_29 AC 490 ms
166,420 KB
testcase_30 AC 394 ms
144,664 KB
testcase_31 AC 644 ms
212,416 KB
testcase_32 AC 715 ms
225,156 KB
testcase_33 AC 686 ms
221,316 KB
testcase_34 AC 713 ms
225,296 KB
testcase_35 AC 650 ms
224,608 KB
testcase_36 AC 653 ms
224,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

W, H, Q = map(int, readline().split())
query = readlines()

if H == W == 1:
    print(0)
    exit()

N = H * W
horizonal_max = list(range(N))
vertical_max = list(range(N))

for line in query[1::2]:
    B = map(int, line.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
visited = [False] * N
q = [0]
goal = N - 1
d = 0
while q:
    qq = []
    d += 1
    for v in q:
        for w in graph[v]:
            if visited[w]:
                continue
            if w == goal:
                print(d)
                exit()
            visited[w] = True
            qq.append(w)
    q = qq

print('Odekakedekinai..')
0