結果

問題 No.323 yuki国
ユーザー ぴろずぴろず
提出日時 2015-12-15 19:33:57
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 848 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 77,584 KB
実行使用メモリ 116,480 KB
最終ジャッジ日時 2023-10-13 17:09:51
合計ジャッジ時間 12,939 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python

from collections import deque

h,w = map(int, raw_input().split())
a,si,sj = map(int,raw_input().split())
b,gi,gj = map(int,raw_input().split())
m = [raw_input() for i in range(h)]

ma = max(a+h+w-1,b+2*(h+w))

dist = [[[1<<29] * (ma+1) for j in range(w)] for i in range(h)]

d = [0,1,0,-1]

q = deque([a << 16 | si << 8 | sj]);
dist[si][sj][a] = 0
while len(q) > 0:
    p = q.popleft()
    cs = p >> 16
    ci = p >> 8 & 0xff
    cj = p & 0xff
    for i in range(4):
        ni = ci + d[i]
	nj = cj + d[i^1]
	if ni < 0 or ni >= h or nj < 0 or nj >= w :
	    continue
	ns = cs + (1 if m[ni][nj] == '*' else -1)
	if ns > ma or ns <= 0 or dist[ni][nj][ns] <= dist[ci][cj][cs] + 1:
	    continue
	dist[ni][nj][ns] = dist[ci][cj][cs] + 1
	q.append(ns << 16 | ni << 8 | nj)
print(-1 if dist[gi][gj][b] >= 1 << 29 else dist[gi][gj][b])
0