結果

問題 No.20 砂漠のオアシス
ユーザー fiordfiord
提出日時 2015-07-16 22:28:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,139 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 168,876 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 06:38:14
合計ジャッジ時間 3,196 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 10 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 18 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 166 ms
5,376 KB
testcase_09 AC 209 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 12 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 26 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 81 ms
5,376 KB
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef tuple<int,int,int,int> mytuple;
#define	nx	x+mx[i]
#define	ny	y+my[i]
int mx[]={1,-1,0,0},my[]={0,0,1,-1};
int n;
int dp[200][200][2];
bool check(int x,int y,int i){
	if(nx<0||nx>=n)	return false;
	if(ny<0||ny>=n)	return false;
	return true;
}
int main(){
	int v,ox,oy;	cin>>n>>v>>ox>>oy;
	ox--;	oy--;
	int l[n][n];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)	cin>>l[i][j];
	}
	dp[0][0][0]=v;
	priority_queue<mytuple,vector<mytuple>,greater<mytuple> > pq;
	pq.push(make_tuple(v,0,0,0));
	while(!pq.empty()){
		auto current=pq.top();	pq.pop();
		int life=get<0>(current);
		int x=get<1>(current);
		int y=get<2>(current);
		int oasis=get<3>(current);
		if(dp[x][y][oasis]<life)	continue;
		if(x==n-1&&y==n-1){
			if(life>0){
				cout<<"YES"<<endl;
				return 0;
			}
		}
		if(x==ox&&y==oy&&oasis==0){
			life*=2;
			oasis=1;
		}
		for(int i=0;i<4;i++){
			if(check(x,y,i)){
				if(dp[nx][ny][oasis]<dp[x][y][oasis]-l[nx][ny]){
					dp[nx][ny][oasis]=dp[x][y][oasis]-l[nx][ny];
					pq.push(make_tuple(dp[nx][ny][oasis],nx,ny,oasis));
				}
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}
0