結果

問題 No.20 砂漠のオアシス
ユーザー kurenai3110kurenai3110
提出日時 2016-12-13 15:15:31
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,667 bytes
コンパイル時間 886 ms
コンパイル使用メモリ 76,796 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2024-04-21 07:00:39
合計ジャッジ時間 7,494 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
using namespace std;
#define INF (int)1e7

vector<int>L;
int N, V, Ox, Oy,O;
int status[40000];
int cost[40000];
//int trace[40000];

void dijkstra(int s) {
	int dir[] = { -1 * N,1,1 * N,-1 };

	int minv;
	for (int i = 0; i < N*N; i++) {
		status[i] = 0;
		cost[i] = INF;
	}
	cost[s] = 0;
	//trace[s] = -1;
	status[s] = 1;

	vector<pair<int,int>>U;
	U.push_back(make_pair(cost[s],s));
	while (U.size()) {
		sort(U.begin(),U.end());
		//探索が終わってない中でコスト最小の点
		int u = U.front().second;
		U.erase(U.begin());

		if (status[u] == -1) continue;
		if (cost[u] >= V)break;

		status[u] = -1;

		//コスト最少の点を探る
		for (int i = 0; i < 4; i++) {
			if (status[u + dir[i]] != -1 && u + dir[i] >= 0 && u + dir[i] < N*N) {
				if ((dir[i] == 1 || dir[i] == -1) && (u + dir[i]) / N != u / N)continue;
				if (cost[u + dir[i]] > cost[u] + L[u + dir[i]]) {
					cost[u + dir[i]] = cost[u] + L[u + dir[i]];
					status[u + dir[i]] = 1;
					U.push_back(make_pair(cost[u+dir[i]], u+dir[i]));
				}
			}
		}
	}
}

int main()
{
	cin >> N >> V >> Ox >> Oy;
	Ox--; Oy--; O = Oy * N + Ox;
	bool hasOasis = O >= 0;

	L.resize(N*N);
	for (int i = 0; i < N*N; i++) {
		cin >> L[i];
	}

	dijkstra(0);
	//cout << cost[N*N - 1] << endl;
	if (cost[N*N - 1] < V) {
		cout << "YES" << endl;
		return 0;
	}
	else if(hasOasis){
		V = (V - cost[O]) * 2;
		//cout << V << endl;
		dijkstra(O);
		//cout << cost[N*N - 1] << endl;
		if (cost[N*N - 1] < V) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;

    return 0;
}

0