結果

問題 No.20 砂漠のオアシス
ユーザー rodearodea
提出日時 2019-10-06 23:23:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,764 bytes
コンパイル時間 1,691 ms
コンパイル使用メモリ 121,444 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-20 01:01:57
合計ジャッジ時間 2,700 ms
ジャッジサーバーID
(参考情報)
judge4 / 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
7,168 KB
testcase_06 AC 19 ms
7,808 KB
testcase_07 AC 18 ms
7,808 KB
testcase_08 AC 20 ms
7,808 KB
testcase_09 AC 20 ms
7,680 KB
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
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 WA -
testcase_18 AC 5 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

int n, v;

void dijkstra(int s, int o, vector<vector<P>> &G){
    vector<int> dist(n*n, inf);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);

    while(que.size()){
        int ccost, cv;
        tie(ccost, cv) = que.top(); que.pop();

        if(dist[cv] < ccost) continue;

        for(auto nxt : G[cv]){
            int nv, ncost;
            tie(nv, ncost) = nxt;
            
            if(dist[cv] + ncost < dist[nv]){
                dist[nv] = dist[cv] + ncost;
                que.emplace(dist[nv], nv);
            }
        }
    }

    bool valid = false;
    if(o == -1){
        if(0 < v - dist[n*n-1]) valid = true; 
    }
    else{
        if(0 < v - dist[n*n-1]) valid = true;
        if(dist[n*n-1] - dist[o] < 2 * (v - dist[o])) valid = true;
    }

    cout << (valid ? "YES" : "NO") << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int ox, oy; cin>>n>>v>>ox>>oy;
    ox--, oy--;
    int l[n][n];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++) cin>>l[i][j];
    }

    int grid2graph[n][n];
    int cnt = 0;
    int o = -1;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i == oy && j == ox) o = cnt;
            grid2graph[i][j] = cnt++;
        }
    }

    vector<vector<P>> G(n*n);
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            int cy = i, cx = j;
            for(int k=0; k<4; k++){
                int ny = cy + dy[k], nx = cx + dx[k];
                if(!(0 <= ny && ny < n && 0 <= nx && nx < n)) continue;

                int cv = grid2graph[cy][cx], nv = grid2graph[ny][nx];
                G[cv].emplace_back(nv, l[ny][nx]);
                G[nv].emplace_back(cv, l[cy][cx]);
            }
        }
    }

    dijkstra(0, o, G);

    return 0;
}
0