結果

問題 No.20 砂漠のオアシス
ユーザー krotonkroton
提出日時 2014-10-31 08:41:15
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,994 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 75,640 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-08-03 07:19:19
合計ジャッジ時間 1,756 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <fstream>
#include <sstream>
using namespace std;
typedef long long ll;

int N, V, OX, OY;
int L[600][600];
int cost[600][600];

int dy[] = {1,-1,0,0};
int dx[] = {0,0,1,-1};
const int INF = 1 << 25;

int dijkstra(int sx, int sy, int gx, int gy){
    for(int i=0;i<N;i++)for(int j=0;j<N;j++)cost[i][j] = INF;
    
    cost[sx][sy] = 0;
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> Q;
    
    Q.push(make_pair(0, sx * N + sy));
    while(!Q.empty()){
        auto now = Q.top(); Q.pop();
        int x = now.second / N;
        int y = now.second % N;
        int c = now.first;
        
        for(int i=0;i<4;i++){
            int nx = x + dx[i];
            int ny = y + dy[i];
            
            if(nx < 0 || nx >= N)continue;
            if(ny < 0 || ny >= N)continue;
            
            int nc = c + L[nx][ny];
            if(nc < cost[nx][ny]){
                cost[nx][ny] = nc;
                Q.push(make_pair(nc, nx * N + ny));
            }
            
        }
    }
    
    return cost[gx][gy];
}

int main(){
    cin >> N >> V >> OX >> OY;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin >> L[i][j];
        }
    }
    
    OX--;
    OY--;
    
    bool res = false;
    if(OX >= 0 && OY >= 0){
        int oasisCost = dijkstra(0, 0, OX, OY);
        int nv = V;
        
        nv -= oasisCost;
        if(nv > 0){
            nv *= 2;
            
            int goalCost = dijkstra(OX, OY, N-1, N-1);
            nv -= goalCost;
            
            if(nv > 0){
                res = true;
            }
        }
    }
    
    int goalCost = dijkstra(0, 0, N-1, N-1);
    if(V - goalCost > 0)res = true;
    
    cout << (res ? "YES" : "NO") << endl;
    return 0;
}
0