結果

問題 No.20 砂漠のオアシス
ユーザー BantakoBantako
提出日時 2018-12-30 18:22:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,561 bytes
コンパイル時間 1,820 ms
コンパイル使用メモリ 171,024 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 22:34:38
合計ジャッジ時間 2,572 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 18 ms
5,376 KB
testcase_06 AC 21 ms
5,376 KB
testcase_07 AC 20 ms
5,376 KB
testcase_08 AC 20 ms
5,376 KB
testcase_09 AC 20 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 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 6 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   35 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int cost[210][210];//cost[i][j] i->jのコスト
int dist[210][210];//距離
int N,V,X,Y;
void dijkstra(int y, int x){
    rep(i, 0, N)rep(j, 0, N)dist[i][j] = INF;
    //<cost, (座標)>
    priority_queue<P, vector<PP>, greater<PP> > que;
    que.push(make_pair(0, make_pair(y, x)));
    dist[y][x] = 0;
    while(!que.empty()){
        auto c = que.top().first;
        auto now = que.top().second;
        que.pop();

        // if(dist[now.first][now.second] < c) continue;
        rep(i, 0, 4){
            int ny = now.first + dy[i], nx = now.second + dx[i];
            if(!(0 <= ny && ny < N && 0 <= nx && nx < N)) continue;
            if(dist[ny][nx] <= c + cost[ny][nx]) continue;
            dist[ny][nx] = c + cost[ny][nx];
            que.push(make_pair(dist[ny][nx], make_pair(ny, nx)));
        }
    }
}
main(){
    cin >> N >> V >> X >> Y;
    rep(i,0,N)rep(j,0,N)cin >> cost[i][j];
    string ans[] = {"NO", "YES"};
    dijkstra(0, 0);
    if(dist[N-1][N-1] < V){
        cout << "YES" << endl;
        return 0;
    }
    if(X != 0 || Y != 0 && dist[Y-1][X-1] < V){
        int ocost = dist[Y-1][X-1];
        dijkstra(Y-1, X-1);
        if(2 * (V - ocost) > dist[N-1][N-1]){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}
0