結果

問題 No.20 砂漠のオアシス
ユーザー ゆるくゆるく
提出日時 2015-05-01 04:25:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,864 ms / 5,000 ms
コード長 1,514 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2024-04-21 06:28:06
合計ジャッジ時間 9,289 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
11,008 KB
testcase_01 AC 30 ms
11,008 KB
testcase_02 AC 31 ms
11,008 KB
testcase_03 AC 38 ms
11,008 KB
testcase_04 AC 37 ms
11,008 KB
testcase_05 AC 1,138 ms
11,904 KB
testcase_06 AC 643 ms
12,928 KB
testcase_07 AC 1,442 ms
13,056 KB
testcase_08 AC 206 ms
13,056 KB
testcase_09 AC 2,864 ms
12,928 KB
testcase_10 AC 28 ms
11,008 KB
testcase_11 AC 30 ms
11,008 KB
testcase_12 AC 77 ms
11,008 KB
testcase_13 AC 67 ms
11,008 KB
testcase_14 AC 248 ms
11,136 KB
testcase_15 AC 106 ms
11,136 KB
testcase_16 AC 120 ms
11,264 KB
testcase_17 AC 164 ms
11,136 KB
testcase_18 AC 293 ms
11,264 KB
testcase_19 AC 853 ms
11,392 KB
testcase_20 AC 47 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
#import re
#import bisect
#from collections import deque

n, v, ox, oy = (int(i) for i in input().split())
l = [[int(i) for i in input().split()] for i in range(n)]
cost = [[0xFFFFFFFF for i in range(n)] for j in range(n)]
direction = ((1, 0), (0, 1), (-1, 0), (0, -1))
def solve(x, y):
    h = []
    heapq.heappush(h, (x << 8) + y)
    inq = [[False for i in range(n)] for j in range(n)]
    for i in range(n):
        for j in range(n):
            cost[i][j] = 0xFFFFFFFF
    cost[y][x] = 0
    inq[y][x] = True
    while (h):
        vh = heapq.heappop(h)
        vx = (vh >> 8) & 0x00FF
        vy = vh & 0x00FF
        nowcost = cost[vy][vx]
        inq[vy][vx] = False
        for i in range(4):
            mx = vx + direction[i][0]
            my = vy + direction[i][1]
            if(mx < 0 or my < 0 or mx >= n or my >= n):
                continue
            newcost = nowcost + l[my][mx]
            if cost[my][mx] > newcost:
                cost[my][mx] = newcost                
                if inq[my][mx] == False:
                    inq[my][mx] = True
                    heapq.heappush(h, (mx << 8) + my)

solve(0, 0)
if cost[n - 1][n - 1] < v:
    print("YES")
else:
    if (ox > 0 and oy > 0):
        os = cost[oy - 1][ox - 1]
        if os < v:
            solve(ox - 1, oy - 1)
            if cost[n - 1][n - 1] < (v - os) * 2:
                print("YES")
            else:
                print("NO")
        else:
            print("NO")
    else:
        print("NO")
0