結果

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

テストケース

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

ソースコード

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;
		for(int i=0;i<4;i++){
			if(x==n-1&&y==n-1){
				if(life>0){
					cout<<"YES"<<endl;
					return 0;
				}
			}
			if(check(x,y,i)){
				if(oasis==0&&ox==nx&&oy==ny){
					if(dp[nx][ny][1]<2*(dp[x][y][0]-l[nx][ny])){
						dp[nx][ny][1]=2*(dp[x][y][0]-l[nx][ny]);
						pq.push(make_tuple(dp[nx][ny][1],nx,ny,1));
					}
				}
				else{
					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