結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  Shibuyap | 
| 提出日時 | 2020-10-24 19:10:20 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,082 bytes | 
| コンパイル時間 | 2,876 ms | 
| コンパイル使用メモリ | 199,028 KB | 
| 最終ジャッジ日時 | 2025-01-15 15:18:38 | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 2 WA * 3 TLE * 14 MLE * 2 | 
ソースコード
#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;
}
 
 
            
            
            
        