結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  chakku | 
| 提出日時 | 2016-04-03 02:23:34 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,064 bytes | 
| コンパイル時間 | 571 ms | 
| コンパイル使用メモリ | 72,648 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-13 05:36:35 | 
| 合計ジャッジ時間 | 1,334 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 WA * 5 | 
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <climits>
#include <cassert>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX/3
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define ALL(v) (v).begin(),(v).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int N,V,Ox,Oy;
int L[256][256];
int t[256][256][2];     //t[i][j][k] : (i,j)に体力t[i][j][k]でたどり着ける(kが0の時泉未使用)
struct node{
    int x,y,hp;
    bool used;
};
bool ok(int x,int y){
    if(0<=x and x<N and 0<=y and y<N) return true;
    else return false;
}
int main(){
    cin >> N >> V >> Ox >> Oy;
    Ox--;Oy--;
    REP(i,N) REP(j,N) cin >> L[i][j];
    REP(i,N) REP(j,N) REP(k,2) t[i][j][k] = 0;
    queue<node> que;
    que.push(node{0,0,V,false});
    t[0][0][0] = V;
    while(!que.empty()){
        node p = que.front();
        que.pop();
        const int x = p.x;
        const int y = p.y;
        const int hp = p.hp;
        const bool used = p.used;
        assert(hp>0);
        if(x==N-1 and y==N-1){
            cout << "YES" << endl;
            return 0;
        }
        if(t[x][y][used]>hp) continue;
        REP(idx,4){
            const int nx = x + dx[idx], ny = y + dy[idx];
            if(!ok(nx,ny)) continue;
            if(hp-L[nx][ny]<0) continue;
            if(nx==Ox and ny==Oy and used==false){
                //泉使用
                if(t[nx][ny][1]<(hp-L[nx][ny])*2){
                    t[nx][ny][1] = (hp-L[nx][ny])*2;
                    que.push(node{nx,ny,t[nx][ny][1],true});
                }
            }
            else{
                if(t[nx][ny][used]<hp-L[nx][ny]){
                    t[nx][ny][used] = hp - L[nx][ny];
                    que.push(node{nx,ny,t[nx][ny][used],used});
                }
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}
            
            
            
        