結果

問題 No.124 門松列(3)
ユーザー roiti46roiti46
提出日時 2015-02-24 18:50:13
言語 Python2
(2.7.18)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 825 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 6,632 KB
実行使用メモリ 7,172 KB
最終ジャッジ日時 2023-09-06 04:13:43
合計ジャッジ時間 2,307 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
6,904 KB
testcase_01 AC 10 ms
5,844 KB
testcase_02 AC 11 ms
5,848 KB
testcase_03 AC 41 ms
7,172 KB
testcase_04 AC 17 ms
7,064 KB
testcase_05 AC 16 ms
7,028 KB
testcase_06 AC 10 ms
5,896 KB
testcase_07 AC 10 ms
5,808 KB
testcase_08 AC 12 ms
5,956 KB
testcase_09 AC 11 ms
5,988 KB
testcase_10 AC 11 ms
5,896 KB
testcase_11 AC 11 ms
5,864 KB
testcase_12 AC 11 ms
5,900 KB
testcase_13 AC 11 ms
5,804 KB
testcase_14 AC 12 ms
5,840 KB
testcase_15 AC 12 ms
5,856 KB
testcase_16 AC 13 ms
6,076 KB
testcase_17 AC 12 ms
5,944 KB
testcase_18 AC 11 ms
5,900 KB
testcase_19 AC 11 ms
5,904 KB
testcase_20 AC 13 ms
5,916 KB
testcase_21 AC 11 ms
5,960 KB
testcase_22 AC 12 ms
6,032 KB
testcase_23 AC 14 ms
6,288 KB
testcase_24 AC 15 ms
6,488 KB
testcase_25 AC 14 ms
6,536 KB
testcase_26 AC 12 ms
5,976 KB
testcase_27 AC 12 ms
6,184 KB
testcase_28 AC 17 ms
6,924 KB
testcase_29 AC 16 ms
6,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
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 b < a < c or b < c < a or a < c < b or c < a < b

W,H = map(int,raw_input().split())
M = [map(int,raw_input().split()) for i in xrange(H)]
que = [[0,0,0]]
cost = [[[-1]*W for i in xrange(H)] for j in xrange(10)]
cost[0][0][0] = 0

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