結果

問題 No.20 砂漠のオアシス
ユーザー ShibuyapShibuyap
提出日時 2020-10-24 19:18:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 2,155 bytes
コンパイル時間 2,116 ms
コンパイル使用メモリ 205,128 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 20:41:13
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005

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

int main() {
    int n, v, ox, oy;
    cin >> n >> v >> ox >> oy;
    swap(ox,oy);
    int a[n+2][n+2];
    int f[n+2][n+2][2];
    rep(i,n+2){
        rep(j,n+2){
            if(i==0||i==n+1||j==0||j==n+1){
                a[i][j] = 1001001001;
            }else{
                cin >> a[i][j];
            }
            f[i][j][0] = 0;
            f[i][j][1] = 0;
        }
    }

    priority_queue<pair<P,P>> que;
    pair<P,P> p;
    p.first.first = v;
    p.first.second = 0;
    p.second.first = 1;
    p.second.second = 1;
    que.push(p);
    f[1][1][0] = v;

    while(que.size() > 0){
        int v = que.top().first.first;
        int z = que.top().first.second;
        int x = que.top().second.first;
        int y = que.top().second.second;
        que.pop();
        if(f[x][y][z] > v) continue;

        // cout << x << ' ' << y << ' ' << z << ' ' << v << endl;

        rep(i,4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            int nv = v - a[nx][ny];
            if(nv <= f[nx][ny][z]) continue;
            if(nx==ox&&ny==oy){
                nv *= 2;
                if(f[nx][ny][1] < nv){
                    f[nx][ny][1] = nv;
                    p.first.first = nv;
                    p.first.second = 1;
                    p.second.first = nx;
                    p.second.second = ny;
                    que.push(p);
                }
            }else{
                if(f[nx][ny][z] < nv){
                    f[nx][ny][z] = nv;
                    p.first.first = nv;
                    p.first.second = z;
                    p.second.first = nx;
                    p.second.second = ny;
                    que.push(p);
                }
            }
        }
    }

    if(f[n][n][0]>0||f[n][n][1]>0) yn;
    return 0;
}
 
 
0