結果

問題 No.20 砂漠のオアシス
ユーザー masamasa
提出日時 2015-01-23 21:47:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,352 bytes
コンパイル時間 831 ms
コンパイル使用メモリ 73,636 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 06:20:54
合計ジャッジ時間 1,469 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#	include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;
const int INF = 1e9;

vector< vector<int> > dessert;
vector< vector<int> > hp;
int n;

bool walk(int sx, int sy) {
	queue< pair<int, int> > que;
	que.push(make_pair(sx, sy));

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

	int x, y, nx, ny;
	while (!que.empty()) {
		auto now = que.front();
		x = now.first;
		y = now.second;
		que.pop();

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

			if (hp[y][x] > dessert[ny][nx] && hp[y][x] - dessert[y][x] > hp[ny][nx]) {
				hp[ny][nx] = hp[y][x] - dessert[ny][nx];
				if (nx == n && ny == n) {
					return true;
				}
				que.push(make_pair(nx, ny));
			}
		}
	}
	return false;
}

int main() {
	int v, ox, oy;

	cin >> n >> v >> ox >> oy;
	dessert.assign(n + 2, vector<int>(n + 2, INF));
	hp.assign(n + 2, vector<int>(n + 2, -1));

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> dessert[i][j];
		}
	}
	hp[1][1] = v;
	bool isGoal = walk(1, 1);

	if (!isGoal) {
		int hp_oasys = hp[oy][ox];
		if (hp_oasys <= 0) {
			isGoal = false;
		} else {
			hp.assign(n + 2, vector<int>(n + 2, -1));
			hp[oy][ox] = 2 * hp_oasys;
			isGoal = walk(ox, oy);
		}

	}

	cout << (isGoal ? "YES" : "NO") << endl;
	return 0;
}
0