結果

問題 No.20 砂漠のオアシス
ユーザー TwizzTwizz
提出日時 2017-05-23 00:48:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,623 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 76,764 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 08:20:56
合計ジャッジ時間 1,809 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<queue>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>
using namespace std;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
const int d[5] = { 0, 1, 0, -1, 0 };
int cost[201][201];
int dijkstra(PI s, PI t, int n){
    int dist[202][202];
    for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++)dist[i][j] = -1;
    for (int i = 0; i <= n + 1; i++)dist[0][i] = dist[i][0] = dist[n + 1][i] = dist[i][n + 1] = 100000;
    priority_queue<V, vector<V>, greater<V> > que;
    que.push(make_pair(0, s));
    while (que.empty() == false){
        PI v = que.top().second;
        int di = que.top().first;
        que.pop();
        if (dist[v.first][v.second] >= 0)continue;
        dist[v.first][v.second] = di;
        for (int i = 0; i<4; i++){

            PI p = v;
            
            p.first += d[i];
            p.second += d[i + 1];
            if (dist[p.first][p.second] >= 0)continue;
            que.push(make_pair(di + cost[p.first][p.second], p));
        }

    }
    return dist[t.first][t.second];
}

int main(){
    int N;
    int V;
    PI O;
    cin >> N >> V >> O.second >> O.first;
    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
            cin >> cost[i][j];
    auto st = make_pair(1, 1);
    auto ed = make_pair(N, N);
    if (dijkstra(st, ed, N)<V){
        cout << "YES" << endl;
    }
    else {
        int U = (V - dijkstra(st, O, N)) * 2;
        if ((O.first != 0 || O.second != 0) && U>0 && U - dijkstra(O, ed, N)>0)
            cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}
0