結果

問題 No.20 砂漠のオアシス
ユーザー ゆるくゆるく
提出日時 2014-10-18 02:43:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,527 bytes
コンパイル時間 116 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2024-04-21 06:17:30
合計ジャッジ時間 1,925 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,880 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 32 ms
11,008 KB
testcase_04 AC 31 ms
11,136 KB
testcase_05 AC 92 ms
12,544 KB
testcase_06 AC 111 ms
12,928 KB
testcase_07 AC 112 ms
12,928 KB
testcase_08 AC 117 ms
13,056 KB
testcase_09 AC 112 ms
12,928 KB
testcase_10 WA -
testcase_11 AC 27 ms
10,880 KB
testcase_12 AC 29 ms
11,008 KB
testcase_13 AC 30 ms
11,008 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 42 ms
11,136 KB
testcase_18 WA -
testcase_19 AC 44 ms
11,264 KB
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

# 想定解を参考に作成
# ダイクストラ SPFAの違いがわからないorz

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, (0 << 24) + (0 << 8) + 0)
    visit = [[False for i in range(n)] for j in range(n)]
    cost[y][x] = 0
    visit[y][x] = True
    while (h):
        v = heapq.heappop(h)
        vx = (v >> 8) & 0x000000FF
        vy = v & 0x000000FF
        nowcost = cost[vy][vx]

        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 visit[my][mx] == False:
                    visit[my][mx] = True
                    heapq.heappush(h, (newcost << 24) + (mx << 8) + my)

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