結果

問題 No.340 雪の足跡
ユーザー maspymaspy
提出日時 2020-03-21 13:53:57
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 766 ms / 1,000 ms
コード長 1,410 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 225,712 KB
最終ジャッジ日時 2023-08-23 12:54:04
合計ジャッジ時間 11,848 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,016 KB
testcase_01 AC 71 ms
71,240 KB
testcase_02 AC 72 ms
71,008 KB
testcase_03 AC 71 ms
71,504 KB
testcase_04 AC 72 ms
71,232 KB
testcase_05 AC 70 ms
71,016 KB
testcase_06 AC 71 ms
71,012 KB
testcase_07 AC 72 ms
71,320 KB
testcase_08 AC 74 ms
71,236 KB
testcase_09 AC 72 ms
71,500 KB
testcase_10 AC 71 ms
71,568 KB
testcase_11 AC 103 ms
76,728 KB
testcase_12 AC 96 ms
76,576 KB
testcase_13 AC 101 ms
76,428 KB
testcase_14 AC 138 ms
82,236 KB
testcase_15 AC 138 ms
81,460 KB
testcase_16 AC 127 ms
80,516 KB
testcase_17 AC 159 ms
91,356 KB
testcase_18 AC 156 ms
90,944 KB
testcase_19 AC 160 ms
90,936 KB
testcase_20 AC 364 ms
165,944 KB
testcase_21 AC 144 ms
80,256 KB
testcase_22 AC 147 ms
134,608 KB
testcase_23 AC 450 ms
225,712 KB
testcase_24 AC 271 ms
152,068 KB
testcase_25 AC 335 ms
174,256 KB
testcase_26 AC 133 ms
80,164 KB
testcase_27 AC 89 ms
76,212 KB
testcase_28 AC 145 ms
85,124 KB
testcase_29 AC 537 ms
166,456 KB
testcase_30 AC 421 ms
144,552 KB
testcase_31 AC 699 ms
212,544 KB
testcase_32 AC 757 ms
225,496 KB
testcase_33 AC 727 ms
221,308 KB
testcase_34 AC 766 ms
225,340 KB
testcase_35 AC 693 ms
224,616 KB
testcase_36 AC 683 ms
224,852 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
            visited[w] = True
            qq.append(w)
    if visited[goal]:
        print(d)
        exit()
    q = qq

print('Odekakedekinai..')
0