結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
ayame_py
|
| 提出日時 | 2016-01-06 05:28:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,419 bytes |
| コンパイル時間 | 1,710 ms |
| コンパイル使用メモリ | 163,284 KB |
| 実行使用メモリ | 814,632 KB |
| 最終ジャッジ日時 | 2024-10-13 05:31:58 |
| 合計ジャッジ時間 | 5,347 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 MLE * 1 -- * 17 |
ソースコード
#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;
}
ayame_py