結果

問題 No.20 砂漠のオアシス
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-19 12:13:27
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,299 bytes
コンパイル時間 1,314 ms
コンパイル使用メモリ 142,832 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-29 02:11:00
合計ジャッジ時間 2,173 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
 
using namespace std;

template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;
 
int main(){
 
    bool ok=0;
    int N, V, h, w, oh, ow, alt, d, nh, nw;
    cin >> N >> V >> oh >> ow;
    oh--; ow--;
    swap(oh, ow);
    
    pq<tuple<int, int, int>> que;
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    vector<vector<int>> dist(N, vector<int>(N, 1e9));
    vector<vector<bool>> visit(N, vector<bool>(N));
    vector<vector<int>> field(N, vector<int>(N));
 
    for (int i=0; i < N; i++){
        for (int j=0; j<N; j++) cin >> field[i][j];
    }
 
    dist[0][0] = field[0][0];
    que.push({field[0][0], 0, 0});
 
    while(!que.empty()){
        tie(d, h, w) = que.top();
        que.pop();
        if (visit[h][w]) continue;
        visit[h][w] = 1;
        for (int dir=0; dir < 4; dir++){
            nh = h + dx[dir];
            nw = w + dy[dir];
            if (nh < 0 || nh >= N || nw < 0 || nw >= N) continue;
            alt = dist[h][w] + field[nh][nw];
            if (alt < dist[nh][nw]){
                dist[nh][nw] = alt;
                que.push({dist[nh][nw], nh, nw});
            }
        }
    }

    if (dist[N-1][N-1] < V) ok = 1;

    for (int i=0; i<N; i++){
        for (int j=0; j<N; j++){
            dist[i][j] = 1e9; visit[i][j] = 0;
        }
    }

    if (oh >= 0 && oh < N && ow >= 0 && ow < N){
        dist[oh][ow] = field[oh][ow];
        que.push({field[oh][ow], oh, ow});
 
        while(!que.empty()){
            tie(d, h, w) = que.top();
            que.pop();
            if (visit[h][w]) continue;
            visit[h][w] = 1;
            for (int dir=0; dir < 4; dir++){
                nh = h + dx[dir];
                nw = w + dy[dir];
                if (nh < 0 || nh >= N || nw < 0 || nw >= N) continue;
                alt = dist[h][w] + field[nh][nw];
                if (alt < dist[nh][nw]){
                    dist[nh][nw] = alt;
                    que.push({dist[nh][nw], nh, nw});
                }
            }
        }
        if (dist[0][0] < V && dist[N-1][N-1]-field[oh][ow] < (V-dist[0][0]) * 2) ok = 1;
    }

    cout << (ok ? "YES" : "NO") << endl;
 
    return 0;
}
0