結果

問題 No.20 砂漠のオアシス
ユーザー roiti46roiti46
提出日時 2015-02-22 19:44:03
言語 Python2
(2.7.18)
結果
AC  
実行時間 921 ms / 5,000 ms
コード長 761 bytes
コンパイル時間 69 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-04-21 06:24:12
合計ジャッジ時間 3,086 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,784 KB
testcase_01 AC 12 ms
6,656 KB
testcase_02 AC 13 ms
6,656 KB
testcase_03 AC 24 ms
6,912 KB
testcase_04 AC 23 ms
6,784 KB
testcase_05 AC 75 ms
7,296 KB
testcase_06 AC 49 ms
7,552 KB
testcase_07 AC 921 ms
8,448 KB
testcase_08 AC 183 ms
7,936 KB
testcase_09 AC 555 ms
7,936 KB
testcase_10 AC 13 ms
6,656 KB
testcase_11 AC 11 ms
6,528 KB
testcase_12 AC 20 ms
6,912 KB
testcase_13 AC 17 ms
6,784 KB
testcase_14 AC 37 ms
6,784 KB
testcase_15 AC 28 ms
6,784 KB
testcase_16 AC 72 ms
7,040 KB
testcase_17 AC 45 ms
6,912 KB
testcase_18 AC 53 ms
6,912 KB
testcase_19 AC 63 ms
6,944 KB
testcase_20 AC 15 ms
6,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
dxy = zip([1,0,-1,0],[0,1,0,-1])
def bfs(que):
    while que:
        x,y,v = que.popleft()
        if (x,y) == (N-1,N-1): return True
        if HP[y][x] > v: continue
        HP[y][x] = v
        for dx,dy in dxy:
            nx,ny = x+dx,y+dy
            if 0 <= nx < N and 0 <= ny < N and v-L[ny][nx] >  HP[ny][nx]:
                HP[ny][nx] = v-L[ny][nx]
                que.append([nx,ny,v-L[ny][nx]])
    return False
    
N,V,Ox,Oy = map(int,raw_input().split())
L = [map(int,raw_input().split()) for i in xrange(N)]
HP = [[0]*N for i in xrange(N)]
if bfs(deque([[0,0,V]])): print "YES"
else:
    V = 2*HP[Oy-1][Ox-1]
    HP = [[0]*N for i in xrange(N)]
    if bfs(deque([[Ox-1,Oy-1,V]])): print "YES"
    else: print "NO"
0