結果

問題 No.340 雪の足跡
ユーザー chocoruskchocorusk
提出日時 2020-09-23 01:52:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 460 ms / 1,000 ms
コード長 1,418 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 129,076 KB
最終ジャッジ日時 2023-09-09 09:41:01
合計ジャッジ時間 11,807 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,552 KB
testcase_01 AC 93 ms
71,692 KB
testcase_02 AC 94 ms
71,724 KB
testcase_03 AC 94 ms
71,576 KB
testcase_04 AC 93 ms
71,532 KB
testcase_05 AC 93 ms
71,500 KB
testcase_06 AC 94 ms
71,556 KB
testcase_07 AC 94 ms
71,332 KB
testcase_08 AC 93 ms
71,768 KB
testcase_09 AC 94 ms
71,624 KB
testcase_10 AC 92 ms
71,720 KB
testcase_11 AC 118 ms
78,436 KB
testcase_12 AC 117 ms
77,996 KB
testcase_13 AC 118 ms
78,432 KB
testcase_14 AC 152 ms
81,480 KB
testcase_15 AC 157 ms
82,168 KB
testcase_16 AC 141 ms
79,572 KB
testcase_17 AC 169 ms
84,480 KB
testcase_18 AC 165 ms
84,036 KB
testcase_19 AC 169 ms
84,456 KB
testcase_20 AC 338 ms
121,104 KB
testcase_21 AC 182 ms
78,296 KB
testcase_22 AC 169 ms
119,312 KB
testcase_23 AC 349 ms
120,192 KB
testcase_24 AC 299 ms
120,068 KB
testcase_25 AC 323 ms
120,600 KB
testcase_26 AC 147 ms
78,376 KB
testcase_27 AC 113 ms
78,380 KB
testcase_28 AC 154 ms
79,952 KB
testcase_29 AC 373 ms
103,068 KB
testcase_30 AC 309 ms
99,108 KB
testcase_31 AC 430 ms
125,384 KB
testcase_32 AC 460 ms
126,388 KB
testcase_33 AC 430 ms
129,076 KB
testcase_34 AC 457 ms
126,288 KB
testcase_35 AC 377 ms
126,216 KB
testcase_36 AC 374 ms
126,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

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
import itertools
for i in range(h):
    s1[i]=list(itertools.accumulate(s1[i]))
for i in range(w):
    s2[i]=list(itertools.accumulate(s2[i]))
INF=10**9
d=[[INF]*w for i in range(h)]
d[0][0]=0
from collections import deque
que=deque()
que.append(0)
while que:
    p=que.popleft()
    x, y=divmod(p, w)
    d0=d[x][y]
    if x-1>=0 and s2[y][x-1]>0 and d[x-1][y]>d0+1:
        d[x-1][y]=d0+1
        que.append((x-1)*w+y)
    if x+1<h and s2[y][x]>0 and d[x+1][y]>d0+1:
        d[x+1][y]=d0+1
        que.append((x+1)*w+y)
    if y-1>=0 and s1[x][y-1]>0 and d[x][y-1]>d0+1:
        d[x][y-1]=d0+1
        que.append(x*w+y-1)
    if y+1<w and s1[x][y]>0 and d[x][y+1]>d0+1:
        d[x][y+1]=d0+1
        que.append(x*w+y+1)
if d[h-1][w-1]==INF:
    print("Odekakedekinai..")
else:
    print(d[h-1][w-1])
0