結果

問題 No.124 門松列(3)
ユーザー yuyyuyuyuyyuyu
提出日時 2015-08-04 18:32:31
言語 PyPy2
(7.3.15)
結果
TLE  
実行時間 -
コード長 659 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 77,304 KB
実行使用メモリ 125,776 KB
最終ジャッジ日時 2023-09-25 01:06:45
合計ジャッジ時間 12,879 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

dxdy=zip([-1,0,1,0],[0,1,0,-1])
def kadomatsu(a,b,c):
    if a==0 or b==0:
        return True
    else:
        if (a!=b and b!=c and c!=a) and not (a<b<c or a>b>c):
            return True
        else:
            return False
W,H=map(int,raw_input().split())
M=[map(int,raw_input().split()) for _ in xrange(H)]
que=[[0,0,0,0]]
while que:
    [x,y,bfr,count]=que.pop(0)
    cur=M[y][x]
    if x==W-1 and y==H-1:
        print count
        exit()
    for dx,dy in dxdy:
        nx,ny=x+dx,y+dy
        if not(0<=nx<W and 0<=ny<H):continue
        aft=M[ny][nx]
        if not kadomatsu(bfr,cur,aft):continue
        que.append([nx,ny,cur,count+1])
print -1
0