結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,640 KB
testcase_01 AC 80 ms
71,408 KB
testcase_02 RE -
testcase_03 AC 76 ms
71,640 KB
testcase_04 AC 77 ms
71,404 KB
testcase_05 AC 78 ms
71,668 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 80 ms
71,656 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 179 ms
80,724 KB
testcase_18 AC 141 ms
80,240 KB
testcase_19 AC 151 ms
80,884 KB
testcase_20 AC 298 ms
103,548 KB
testcase_21 RE -
testcase_22 AC 116 ms
96,772 KB
testcase_23 AC 298 ms
105,672 KB
testcase_24 AC 248 ms
103,708 KB
testcase_25 AC 269 ms
106,184 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 404 ms
109,500 KB
testcase_33 AC 436 ms
110,656 KB
testcase_34 AC 404 ms
109,604 KB
testcase_35 AC 321 ms
110,676 KB
testcase_36 AC 337 ms
110,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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