結果

問題 No.340 雪の足跡
ユーザー convexineqconvexineq
提出日時 2021-01-14 08:16:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 401 ms / 1,000 ms
コード長 1,225 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 110,972 KB
最終ジャッジ日時 2023-08-15 13:12:53
合計ジャッジ時間 8,973 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,828 KB
testcase_01 AC 85 ms
71,828 KB
testcase_02 AC 85 ms
71,732 KB
testcase_03 AC 83 ms
71,876 KB
testcase_04 AC 84 ms
71,508 KB
testcase_05 AC 81 ms
71,512 KB
testcase_06 AC 81 ms
71,660 KB
testcase_07 AC 81 ms
71,352 KB
testcase_08 AC 83 ms
71,656 KB
testcase_09 AC 86 ms
71,648 KB
testcase_10 AC 85 ms
71,720 KB
testcase_11 AC 111 ms
78,564 KB
testcase_12 AC 103 ms
77,780 KB
testcase_13 AC 106 ms
78,604 KB
testcase_14 AC 132 ms
79,748 KB
testcase_15 AC 142 ms
80,316 KB
testcase_16 AC 123 ms
78,928 KB
testcase_17 AC 149 ms
81,228 KB
testcase_18 AC 144 ms
80,284 KB
testcase_19 AC 144 ms
80,904 KB
testcase_20 AC 279 ms
103,500 KB
testcase_21 AC 166 ms
78,876 KB
testcase_22 AC 119 ms
97,120 KB
testcase_23 AC 312 ms
105,788 KB
testcase_24 AC 247 ms
103,956 KB
testcase_25 AC 264 ms
106,296 KB
testcase_26 AC 128 ms
78,368 KB
testcase_27 AC 99 ms
78,192 KB
testcase_28 AC 131 ms
79,480 KB
testcase_29 AC 323 ms
94,696 KB
testcase_30 AC 281 ms
90,696 KB
testcase_31 AC 373 ms
107,328 KB
testcase_32 AC 401 ms
110,024 KB
testcase_33 AC 366 ms
110,772 KB
testcase_34 AC 392 ms
109,860 KB
testcase_35 AC 319 ms
110,772 KB
testcase_36 AC 308 ms
110,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
w,h,n = map(int,input().split())

b1 = [[0]*w for _ in range(h)]
b2 = [[0]*h for _ in range(w)]

for _ in range(n):
    m = int(readline())
    t = list(map(int,input().split()))
    for i in range(m):
        x,y = t[i],t[i+1]
        if x > y: x,y = y,x
        if y-x < w:
            b1[x//w][x%w] += 1
            b1[y//w][y%w] -= 1
        else:
            b2[x%w][x//w] += 1
            b2[y%w][y//w] -= 1

for i in range(h):
    for j in range(1,w):
        b1[i][j] += b1[i][j-1]
for j in range(w):
    for i in range(1,h):
        b2[j][i] += b2[j][i-1]

from collections import deque
q = deque([(0,0)])
b = [[-1]*w for _ in range(h)]
b[0][0] = 0
while q:
    vi,vj = q.popleft()
    d = b[vi][vj]
    if vj and b1[vi][vj-1] and b[vi][vj-1]==-1:
        b[vi][vj-1] = d+1
        q.append((vi,vj-1))
    if vj+1<w and b1[vi][vj] and b[vi][vj+1]==-1:
        b[vi][vj+1] = d+1
        q.append((vi,vj+1))
    if vi and b2[vj][vi-1] and b[vi-1][vj]==-1:
        b[vi-1][vj] = d+1
        q.append((vi-1,vj))
    if vi+1<h and b2[vj][vi] and b[vi+1][vj]==-1:
        b[vi+1][vj] = d+1
        q.append((vi+1,vj))
print(b[h-1][w-1] if b[h-1][w-1] != -1 else "Odekakedekinai..")
0