結果

問題 No.124 門松列(3)
ユーザー roiti46roiti46
提出日時 2015-02-24 18:38:04
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 883 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 6,552 KB
実行使用メモリ 15,320 KB
最終ジャッジ日時 2023-09-06 04:10:22
合計ジャッジ時間 2,928 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
15,244 KB
testcase_01 WA -
testcase_02 AC 13 ms
6,368 KB
testcase_03 AC 94 ms
15,320 KB
testcase_04 AC 93 ms
15,048 KB
testcase_05 AC 47 ms
15,164 KB
testcase_06 AC 13 ms
6,452 KB
testcase_07 AC 12 ms
6,280 KB
testcase_08 AC 12 ms
6,472 KB
testcase_09 AC 13 ms
6,468 KB
testcase_10 AC 13 ms
6,240 KB
testcase_11 AC 13 ms
6,276 KB
testcase_12 AC 13 ms
6,456 KB
testcase_13 AC 12 ms
6,232 KB
testcase_14 AC 13 ms
6,368 KB
testcase_15 AC 14 ms
6,516 KB
testcase_16 WA -
testcase_17 AC 16 ms
6,768 KB
testcase_18 AC 13 ms
6,408 KB
testcase_19 AC 15 ms
6,680 KB
testcase_20 WA -
testcase_21 AC 13 ms
6,536 KB
testcase_22 AC 15 ms
6,788 KB
testcase_23 AC 25 ms
9,608 KB
testcase_24 AC 31 ms
11,236 KB
testcase_25 AC 29 ms
10,904 KB
testcase_26 AC 19 ms
8,004 KB
testcase_27 AC 21 ms
7,496 KB
testcase_28 AC 48 ms
15,208 KB
testcase_29 AC 49 ms
15,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque
sys.setrecursionlimit(100000)

dxy = zip([1,0,-1,0],[0,1,0,-1])

def isKadomatsu(a,b,c):
    if a == 0 or b == 0: return True
    return False if a <= b <= c or c <= b <= a else True
    
W,H = map(int,raw_input().split())
M = [map(int,raw_input().split()) for i in xrange(H)]
que = deque([[0,0,0,M[0][0]]])
cost = [[[[-1]*W for i in xrange(H)] for j in xrange(10)] for k in xrange(10)]
cost[0][M[0][0]][0][0] = 0

while que:
    w,h,b,c = que.popleft()
    if (w,h) == (W-1,H-1):
        print cost[b][c][h][w]
        break
    for dx,dy in dxy:
        nw,nh = w+dx,h+dy
        if not (0 <= nw < W and 0 <= nh < H): continue
        a = M[nh][nw]
        if not isKadomatsu(b, c, a): continue
        if cost[c][a][nh][nw] != -1: continue
        cost[c][a][nh][nw] = cost[b][c][h][w]+1
        que.append([nw,nh,c,a])
else:
    print -1
0