結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-01-23 21:47:29 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,352 bytes | 
| コンパイル時間 | 797 ms | 
| コンパイル使用メモリ | 73,760 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-13 05:00:18 | 
| 合計ジャッジ時間 | 1,484 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 17 WA * 4 | 
ソースコード
#	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;
}
            
            
            
        