結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  ayame_py | 
| 提出日時 | 2016-01-06 05:43:02 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,541 ms / 5,000 ms | 
| コード長 | 1,636 bytes | 
| コンパイル時間 | 1,474 ms | 
| コンパイル使用メモリ | 163,280 KB | 
| 実行使用メモリ | 37,760 KB | 
| 最終ジャッジ日時 | 2024-10-13 05:32:05 | 
| 合計ジャッジ時間 | 6,699 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 21 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,n,m) for (int i=n; i<(int)(m); i++)
#define INF 1000000007
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
bool is[2][1002][201][201];
int l[201][201];
int N,V,Ox,Oy;
struct q{int used,hp,y,x;};
bool isok(int used, int hp, int y, int x){
    // 存在しないマス
    if(!(0<=y&&y<N&&0<=x&&x<N)) return false;
    // 体力がゼロになるマス
    int next_hp = hp-l[y][x];
    if(next_hp<=0) return false;
    // もう行ったマス
    // オアシスチェック
    if(used == 0 && Oy==y && Ox==x){next_hp*=2; used=1;}
    if(is[used][next_hp][y][x]) return false;
    
    return true;
}
bool bfs(){
    queue<q> que;
    que.push(q{0,V,0,0});
    while(!que.empty()){
        q t = que.front(); que.pop();
        
        if (t.y==N-1 && t.x==N-1) return true;
        if(t.used == 0 && Oy==t.y && Ox==t.x){t.hp*=2; t.used=1;}
        if(is[t.used][t.hp][t.y][t.x]) continue;
        else is[t.used][t.hp][t.y][t.x] = true;
        REP(i,4){
            if(isok(t.used,t.hp,t.y+dy[i],t.x+dx[i])){
                //cout << t.used << " " << t.hp << " " << t.y << " " << t.x;
                //cout << " -> " << t.y+dy[i] << " " << t.x+dx[i] << endl;
                que.push(q{t.used,t.hp-l[t.y+dy[i]][t.x+dx[i]],t.y+dy[i],t.x+dx[i]});
            }
        }
    }
    return false;
}
int main(){
    cin >> N >> V >> Ox >> Oy;
    Ox--;
    Oy--;
    REP(i,N){
        REP(j,N){
            cin >> l[i][j];
        }
    }
    if(bfs()) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}
            
            
            
        