結果
| 問題 |
No.340 雪の足跡
|
| コンテスト | |
| ユーザー |
mkawa2
|
| 提出日時 | 2022-01-23 13:53:43 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,844 bytes |
| コンパイル時間 | 312 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 37,376 KB |
| 最終ジャッジ日時 | 2024-11-29 13:29:32 |
| 合計ジャッジ時間 | 29,957 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 19 TLE * 13 |
ソースコード
import sys
# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 18446744073709551615
# inf = 4294967295
# md = 10**9+7
md = 998244353
from collections import deque
w, h, n = LI()
row = [0]*h
col = [0]*w
for _ in range(n):
m = II()
bb = LI()
for k in range(m):
i, j = divmod(bb[k], w)
s, t = divmod(bb[k+1], w)
if i == s:
if j > t: j, t = t, j
row[i] |= (1 << t-j)-1 << j
else:
if i > s: i, s = s, i
col[j] |= (1 << s-i)-1 << i
# for a in row: print(bin(a)[2:].zfill(w))
# for a in col: print(bin(a)[2:].zfill(h))
def push(ij):
dist[ij] = d+1
if ij == h*w-1: return True
q.append(ij)
return False
dist = [-1]*h*w
q = deque([0])
dist[0] = 0
while q:
ij = q.popleft()
d = dist[ij]
i, j = divmod(ij, w)
if j and row[i] >> j-1 & 1 and dist[ij-1] == -1:
if push(ij-1): break
if j+1 < w and row[i] >> j & 1 and dist[ij+1] == -1:
if push(ij+1): break
if i and col[j] >> i-1 & 1 and dist[ij-w] == -1:
if push(ij-w): break
if i+1 < h and col[j] >> i & 1 and dist[ij+w] == -1:
if push(ij+w): break
# pDB(i,j,dist)
ans = dist[-1]
if ans == -1: ans = "Odekakedekinai.."
print(ans)
mkawa2