結果

問題 No.20 砂漠のオアシス
ユーザー face4face4
提出日時 2018-10-09 18:31:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,471 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 76,660 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-02 19:01:40
合計ジャッジ時間 1,687 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<queue>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)

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

const int INF = 1<<25;
int n, v, x, y, mat[200][200], dist[200][200];

void dijk(int fi, int fj){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            dist[i][j] = INF;
        }
    }
    dist[fi][fj] = 0;

    priority_queue<pair<int,pair<int,int>>> pq;
    pq.push({-dist[fi][fj],{fi,fj}});

    while(!pq.empty()){
        auto p = pq.top();  pq.pop();
        int c = -p.first, i = p.second.first, j = p.second.second;
        if(c > dist[i][j]) continue;
        
        for(int k = 0; k < 4; k++){
            int ni = i + dx[k], nj = j + dy[k];
            if(!inRange(ni,0,n) || !inRange(nj,0,n))    continue;
            if(dist[ni][nj] > mat[ni][nj] + c){
                dist[ni][nj] = mat[ni][nj] + c;
                pq.push({-dist[ni][nj], {ni,nj}});
            }
        }
    }
}

int main(){
    cin >> n >> v >> x >> y;
    x--; y--;
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> mat[i][j];
        }
    }
    
    dijk(0,0);

    bool judge = false;
    if(dist[n-1][n-1] < v)  judge = true;

    if(x+y != -2){
        dijk(y,x);
        if(v-dist[0][0] > 0 && (v-dist[0][0])*2-dist[n-1][n-1] > 0) judge = true;
    }

    if(judge) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}
0