結果

問題 No.340 雪の足跡
ユーザー chocoruskchocorusk
提出日時 2020-09-23 02:20:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 462 ms / 1,000 ms
コード長 1,190 bytes
コンパイル時間 1,704 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 196,488 KB
最終ジャッジ日時 2023-09-09 10:21:11
合計ジャッジ時間 10,596 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,204 KB
testcase_01 AC 74 ms
71,508 KB
testcase_02 AC 74 ms
71,296 KB
testcase_03 AC 75 ms
71,284 KB
testcase_04 AC 71 ms
71,440 KB
testcase_05 AC 71 ms
71,200 KB
testcase_06 AC 72 ms
71,424 KB
testcase_07 AC 72 ms
71,472 KB
testcase_08 AC 73 ms
71,476 KB
testcase_09 AC 73 ms
71,204 KB
testcase_10 AC 72 ms
71,284 KB
testcase_11 AC 98 ms
76,732 KB
testcase_12 AC 96 ms
76,704 KB
testcase_13 AC 97 ms
77,260 KB
testcase_14 AC 126 ms
84,024 KB
testcase_15 AC 134 ms
84,312 KB
testcase_16 AC 117 ms
79,672 KB
testcase_17 AC 138 ms
86,948 KB
testcase_18 AC 134 ms
85,884 KB
testcase_19 AC 137 ms
87,136 KB
testcase_20 AC 308 ms
133,332 KB
testcase_21 AC 161 ms
77,432 KB
testcase_22 AC 146 ms
116,028 KB
testcase_23 AC 370 ms
195,616 KB
testcase_24 AC 266 ms
119,688 KB
testcase_25 AC 283 ms
126,580 KB
testcase_26 AC 120 ms
77,612 KB
testcase_27 AC 91 ms
76,716 KB
testcase_28 AC 123 ms
81,140 KB
testcase_29 AC 363 ms
142,776 KB
testcase_30 AC 297 ms
123,156 KB
testcase_31 AC 417 ms
181,232 KB
testcase_32 AC 462 ms
196,172 KB
testcase_33 AC 413 ms
193,888 KB
testcase_34 AC 457 ms
196,488 KB
testcase_35 AC 367 ms
195,696 KB
testcase_36 AC 368 ms
195,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.buffer.readline
w, h, n=map(int, readline().split())
s1=[[0]*w for i in range(h)]
s2=[[0]*h for i in range(w)]
for i in range(n):
    m=int(readline())
    b=list(map(int, readline().split()))
    for j in range(m):
        x1, y1=divmod(b[j], w)
        x2, y2=divmod(b[j+1], w)
        if x1==x2:
            if y1>y2:y1, y2=y2, y1
            s1[x1][y1]+=1
            s1[x1][y2]-=1
        else:
            if x1>x2:x1, x2=x2, x1
            s2[y1][x1]+=1
            s2[y1][x2]-=1
from itertools import accumulate
for i in range(h):s1[i]=list(accumulate(s1[i]))
for i in range(w):s2[i]=list(accumulate(s2[i]))
INF=10**9
d=[INF]*(h*w)
d[0]=0
que=[0]
for p in que:
    x, y=divmod(p, w)
    d0=d[p]
    p1, p2, p3, p4=(x-1)*w+y, (x+1)*w+y, x*w+y-1, x*w+y+1
    if x-1>=0 and s2[y][x-1]>0 and d[p1]>d0+1:
        d[p1]=d0+1
        que.append(p1)
    if x+1<h and s2[y][x]>0 and d[p2]>d0+1:
        d[p2]=d0+1
        que.append(p2)
    if y-1>=0 and s1[x][y-1]>0 and d[p3]>d0+1:
        d[p3]=d0+1
        que.append(p3)
    if y+1<w and s1[x][y]>0 and d[p4]>d0+1:
        d[p4]=d0+1
        que.append(p4)
print(d[-1] if d[-1]<INF else "Odekakedekinai..")
0