結果

問題 No.20 砂漠のオアシス
ユーザー granddaifukugranddaifuku
提出日時 2020-03-22 12:24:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,806 bytes
コンパイル時間 1,546 ms
コンパイル使用メモリ 177,000 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-26 03:34:23
合計ジャッジ時間 2,787 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int n, v, ox, oy;
vector<vector<int> > g;

using P = pair<int, int>;
using PP = pair<int, P>;

vector<vector<int> > dist;

void dijkstra(int sx = 0, int sy = 0) {
   dist = vector<vector<int> >(n, vector<int>(n, Inf));
    dist[sx][sy] = 0;
    priority_queue<PP, vector<PP>, greater<PP> > pq;
    pq.push(PP(0, P(sx, sy)));

    while (!pq.empty()) {
        PP p = pq.top();
        pq.pop();
        int c = p.first;
        int vx = p.second.first, vy = p.second.second;
        if (dist[vx][vy] < p.first) continue;

        rep (i, 4) {
            int nx, ny;
            nx = vx + dx[i], ny = vy + dy[i];
            if (nx < 0 || ny < 0 || nx >= n || ny >= n) continue;
            if (dist[nx][ny] <= g[nx][ny] + c) continue;
            dist[nx][ny] = g[nx][ny] + c;
            pq.push(PP(dist[nx][ny], P(nx, ny)));
        } 
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    cin >> n >> v >> ox >> oy;
    ox--, oy--;
    g = vector<vector<int> >(n, vector<int>(n));
    rep (i, n) rep (j, n) cin >> g[i][j];
    dijkstra();
    if (dist[n - 1][n - 1] < v) {
        cout << "YES" << endl;
        return 0;
    }
    if (ox >= 0 && oy >= 0) {
        int toG = dist[n - 1][n - 1] - dist[ox][oy];
        int toO = v - dist[ox][oy];
        if (toG < 2 * toO) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    
    return 0;
}
0