結果

問題 No.20 砂漠のオアシス
ユーザー ant2357ant2357
提出日時 2019-03-28 01:22:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,739 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 177,152 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 13:50:11
合計ジャッジ時間 2,529 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int n, v, ox, oy;
vector<vector<int>> graph, dist;

void dijkstra(int sy, int sx) {
	dist[sy][sx] = 0;

	priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;
	pq.push({ dist[sy][sx], {sy, sx} });

	while (!pq.empty()) {
		int nowCost = pq.top().first;
		int y = pq.top().second.first;
		int x = pq.top().second.second;
		pq.pop();

		if (nowCost > dist[y][x]) {
			continue;
		}

		for (int i = 0; i < 4; i++) {
			int ny = y + dy[i];
			int nx = x + dx[i];

			if (ny < 0 || ny >= n || nx < 0 || nx >= n) {
				continue;
			}

			if (dist[ny][nx] > nowCost + graph[ny][nx]) {
				dist[ny][nx] = nowCost + graph[ny][nx];
				pq.push({ dist[ny][nx] , {ny, nx} });
			}
		}
	}
	
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> v >> ox >> oy;

	graph.resize(n, vector<int>(n));
	dist.resize(n, vector<int>(n, INT_MAX));

	for (int y = 0; y < n; y++) {
		for (int x = 0; x < n; x++) {
			cin >> graph[y][x];
		}
	}

	dijkstra(0, 0);

	if (dist[n - 1][n - 1] < v) {
		cout << "YES" << endl;
		return 0;
	}

	if (oy == -1 && ox == -1) {
		cout << "NO" << endl;
		return 0;
	}

	int healHp = (v - dist[oy][ox]) * 2;
	dijkstra(oy, ox);

	cout << ((healHp - dist[n - 1][n - 1] > 0) ? "YES" : "NO") << endl;
	return 0;
}
0