結果

問題 No.20 砂漠のオアシス
ユーザー ShibuyapShibuyap
提出日時 2020-10-24 19:10:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,082 bytes
コンパイル時間 2,341 ms
コンパイル使用メモリ 204,344 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 20:40:42
合計ジャッジ時間 9,041 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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;
    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||j==0||j==n){
                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 = 0;
    p.second.second = 0;
    que.push(p);
    f[0][0][0] = 1;

    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;
        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