結果

問題 No.20 砂漠のオアシス
ユーザー mbanmban
提出日時 2017-05-08 23:56:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,988 bytes
コンパイル時間 918 ms
コンパイル使用メモリ 78,308 KB
実行使用メモリ 16,528 KB
最終ジャッジ日時 2023-08-03 08:14:46
合計ジャッジ時間 4,089 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

using namespace std;
struct  Cell
{
	int X, Y, Life;
	Cell(int x, int y, int life) {
		X = x;
		Y = y;
		Life = life;
	}
};

struct gret
{
	bool operator ()(const Cell &left, const Cell &right) {
		return left.Life < right.Life;
	}
};

int N, V, Ox, Oy;
int L[250][250];
int Next[4] = { 1,0,-1,0 };

int main() {
	cin >> N >> V >> Ox >> Oy;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> L[i][j];
		}
	}

	priority_queue<Cell,vector<Cell>,gret>pq;

	pq.push(Cell(1, 1, V));
	bool B[250][250];
	int oLife = -1;
	while (pq.size() > 0)
	{
		Cell c = pq.top();
		pq.pop();
		B[c.Y - 1][c.X - 1] = true;
		if (c.Y == N&&c.X == N) {
			cout << "YES" << endl;
			return 0;
		}

		if (c.Y == Oy&&c.X == Ox) {
			oLife = c.Life;
		}

		for (int i = 0; i < 4; i++) {
			int nextY = c.Y + Next[i];
			int nextX = c.X + Next[(i + 1) % 4];
			if (nextX < 1 || nextY < 1) continue;
			if (nextX > N || nextY > N) continue;
			if (B[nextY - 1][nextX - 1]) continue;
			int nextLife = c.Life - L[nextY - 1][nextX - 1];
			if (nextLife <= 0) continue;
			pq.push(Cell(nextX, nextY, nextLife));
		}
	}

	if (Ox == 0 && Oy == 0)
	{
		cout << "NO" << endl;
		return 0;
	}

	pq = priority_queue<Cell,vector<Cell>,gret>();

	pq.push(Cell(Ox, Oy, oLife * 2));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			B[i][j] = false;
		}
	}

	while (pq.size() > 0)
	{
		Cell c = pq.top();
		pq.pop();
		B[c.Y - 1][c.X - 1] = true;
		if (c.Y == N&&c.X == N) {
			cout << "YES" << endl;
			return 0;
		}

		for (int i = 0; i < 4; i++) {
			int nextY = c.Y + Next[i];
			int nextX = c.X + Next[(i + 1) % 4];
			if (nextX < 1 || nextY < 1) continue;
			if (nextX > N || nextY > N) continue;
			if (B[nextY - 1][nextX - 1]) continue;
			int nextLife = c.Life - L[nextY - 1][nextX - 1];
			if (nextLife <= 0) continue;
			pq.push(Cell(nextX, nextY, nextLife));
		}
	}

	cout << "NO" << endl;
	return 0;

}



0