結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
chakku
|
| 提出日時 | 2016-04-03 03:06:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 5,000 ms |
| コード長 | 2,626 bytes |
| コンパイル時間 | 626 ms |
| コンパイル使用メモリ | 73,348 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-13 05:36:38 |
| 合計ジャッジ時間 | 1,380 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#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;
};
void show(){
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
int tt = t[i][j][0];
if(tt>99) cout << tt << " ";
else if(tt>9) cout << tt << " ";
else cout << tt << " ";
}
cout << endl;
}
cout << endl;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
int tt = t[i][j][1];
if(tt>99) cout << tt << " ";
else if(tt>9) cout << tt << " ";
else cout << tt << " ";
}
cout << endl;
}
}
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 >> Oy >> Ox;
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;
//show();
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;
}
chakku