結果

問題 No.20 砂漠のオアシス
ユーザー ayame_pyayame_py
提出日時 2016-01-06 05:28:41
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,419 bytes
コンパイル時間 1,465 ms
コンパイル使用メモリ 163,876 KB
実行使用メモリ 813,944 KB
最終ジャッジ日時 2024-04-21 06:48:30
合計ジャッジ時間 4,751 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 MLE -
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>
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;}
        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])){
                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;
}
0