結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  mban | 
| 提出日時 | 2017-05-08 23:59:32 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,992 bytes | 
| コンパイル時間 | 742 ms | 
| コンパイル使用メモリ | 80,276 KB | 
| 実行使用メモリ | 16,248 KB | 
| 最終ジャッジ日時 | 2024-10-13 05:51:04 | 
| 合計ジャッジ時間 | 3,451 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 18 WA * 3 | 
ソースコード
#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 < 250; i++) {
		for (int j = 0; j < 250; 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;
}
            
            
            
        