結果

問題 No.340 雪の足跡
ユーザー convexineqconvexineq
提出日時 2021-01-14 08:12:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,230 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 110,908 KB
最終ジャッジ日時 2023-08-15 13:06:58
合計ジャッジ時間 9,054 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,668 KB
testcase_01 AC 79 ms
71,732 KB
testcase_02 AC 81 ms
71,740 KB
testcase_03 AC 83 ms
71,748 KB
testcase_04 AC 84 ms
71,468 KB
testcase_05 AC 80 ms
71,736 KB
testcase_06 AC 79 ms
71,680 KB
testcase_07 AC 80 ms
71,276 KB
testcase_08 AC 79 ms
71,740 KB
testcase_09 AC 80 ms
71,824 KB
testcase_10 AC 78 ms
71,528 KB
testcase_11 WA -
testcase_12 AC 123 ms
78,068 KB
testcase_13 WA -
testcase_14 AC 137 ms
80,376 KB
testcase_15 WA -
testcase_16 AC 127 ms
78,700 KB
testcase_17 AC 148 ms
80,808 KB
testcase_18 AC 151 ms
80,100 KB
testcase_19 AC 151 ms
81,144 KB
testcase_20 AC 289 ms
103,396 KB
testcase_21 AC 168 ms
78,928 KB
testcase_22 AC 118 ms
96,920 KB
testcase_23 AC 308 ms
105,712 KB
testcase_24 AC 252 ms
103,664 KB
testcase_25 AC 272 ms
106,428 KB
testcase_26 WA -
testcase_27 AC 100 ms
77,876 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 268 ms
92,168 KB
testcase_31 AC 368 ms
107,124 KB
testcase_32 AC 406 ms
109,684 KB
testcase_33 AC 377 ms
110,520 KB
testcase_34 AC 416 ms
109,876 KB
testcase_35 AC 327 ms
110,908 KB
testcase_36 AC 327 ms
110,704 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 abs(x-y) < 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<w 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