結果

問題 No.20 砂漠のオアシス
ユーザー btk
提出日時 2015-05-07 14:26:45
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 1,420 bytes
コンパイル時間 596 ms
コンパイル使用メモリ 76,008 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 05:11:25
合計ジャッジ時間 1,483 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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 = 1; 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] = 100000;
	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.second >> O.first;
	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