結果

問題 No.20 砂漠のオアシス
ユーザー 👑 NachiaNachia
提出日時 2020-10-06 21:49:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 5,000 ms
コード長 1,242 bytes
コンパイル時間 2,832 ms
コンパイル使用メモリ 172,964 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 08:56:33
合計ジャッジ時間 3,440 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 55 ms
4,380 KB
testcase_06 AC 58 ms
4,376 KB
testcase_07 AC 59 ms
4,376 KB
testcase_08 AC 59 ms
4,380 KB
testcase_09 AC 58 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 12 ms
4,380 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 10 ms
4,380 KB
testcase_19 AC 12 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N, V;
int G[200][200] = {};
int dp[200][200] = {};
int O[2];

void dijkstra(int sx, int sy) {
    rep(x, N) rep(y, N) dp[x][y] = -1;
    priority_queue<pair<int, pair<int, int>>> Q;
    Q.push({ 0,{sx,sy} });
    while (Q.size()) {
        int d = Q.top().first;
        int x = Q.top().second.first;
        int y = Q.top().second.second;
        Q.pop();
        if (dp[x][y] != -1) continue;
        dp[x][y] = -d;
        if (x != 0) Q.push({ d - G[x - 1][y],{x - 1,y} });
        if (y != 0) Q.push({ d - G[x][y - 1],{x,y - 1} });
        if (x != N - 1) Q.push({ d - G[x + 1][y],{x + 1,y} });
        if (y != N - 1) Q.push({ d - G[x][y + 1],{x,y + 1} });
    }
}

int main() {
    cin >> N >> V;
    cin >> O[0] >> O[1]; O[0]--; O[1]--;
    rep(y, N) rep(x, N) cin >> G[x][y];
    dijkstra(0, 0);
    if (dp[N - 1][N - 1] < V) { cout << "YES" << endl; return 0; }
    if (O[0] == -1) { cout << "NO" << endl; return 0; }
    V = (V - dp[O[0]][O[1]]) * 2;
    dijkstra(O[0], O[1]);
    if (dp[N - 1][N - 1] < V) { cout << "YES" << endl; return 0; }
    cout << "NO" << endl;
    return 0;
}
0