結果

問題 No.20 砂漠のオアシス
ユーザー btkbtk
提出日時 2015-05-07 11:41:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,262 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 76,000 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 06:31:24
合計ジャッジ時間 1,845 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #


#include<iostream>
#include<queue>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>
using namespace std;
typedef pair<int,int> PI;
typedef pair<int,PI> V;
const int d[5]={0,1,0,-1,0};
int cost[201][201];
int dijkstra(PI s,PI t,int n){
	int dist[202][202];
	for(int i=1;i<=n;i++)for(int j=0;j<=n;j++)dist[i][j]=-1;
	for(int i=0;i<=n+1;i++)dist[0][i]=dist[i][0]=dist[n+1][i]=dist[i][n+1]=0;
	priority_queue<V,vector<V>,greater<V> > que;
	que.push(make_pair(0,s));
	while(que.empty()==false){
		PI v=que.top().second;
		int di=que.top().first;
		que.pop();
		if(dist[v.first][v.second]>=0)continue;
		dist[v.first][v.second]=di;
		for(int i=0;i<4;i++){
			PI p=v;
			p.first+=d[i];
			p.second+=d[i+1];
			if(dist[p.first][p.second]>=0)continue;
			que.push(make_pair(di+cost[p.first][p.second],p));
		}
	}
	return dist[t.first][t.second];
}

int main(){
	int N;
	int V;
	PI O;
	cin>>N>>V>>O.first>>O.second;
	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++)
			cin>>cost[i][j];
	auto st=make_pair(1,1);
	auto ed=make_pair(N,N);
	if(dijkstra(st,ed,N)<V){
		cout<<"YES"<<endl;
	}
	else {
		int U=(V-dijkstra(st,O,N))*2;
		if((O.first!=0||O.second!=0)&&U>0&&U-dijkstra(O,ed,N)>0)
			cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}


0