結果

問題 No.20 砂漠のオアシス
ユーザー NotationNapNotationNap
提出日時 2015-04-25 23:34:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,372 bytes
コンパイル時間 1,410 ms
コンパイル使用メモリ 164,388 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 06:27:35
合計ジャッジ時間 2,211 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long Int;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))

int N;
int ox, oy;
int L[200][200];
int memo[200][200][2];

bool isin(int x, int y) {
	return 0 <= x && x < N && 0 <= y && y < N;
}
struct S {
	int x;
	int y;
	int v;
	int o;
	int& ref() {
		return memo[x][y][o];
	}
	bool operator<(const S& o) const {
		return v < o.v;
	}
};

int dx[] = { 0, 1, 0, -1 };
int dy[] = { 1, 0, -1, 0 };
int main() {
	int V;
	cin >> N >> V;
	cin >> ox >> oy;
	ox--;
	oy--;
	REP(i, N) REP(j, N) cin >> L[i][j];

	bool ok = false;
	priority_queue<S> pq;
	S start;
	V -= L[0][0];
	start.x = 0;
	start.y = 0;
	start.v = V;
	start.o = 0;
	start.ref() = V;
	pq.push(start);
	while (!pq.empty()) {
		S cur = pq.top(); pq.pop();
		if (cur.v <= 0) continue;
		if (cur.x == N-1 && cur.y == N-1) {
			ok = true;
			break;
		}
		REP(i, 4) {
			int nx = cur.x + dx[i];
			int ny = cur.y + dy[i];
			if (isin(nx, ny)) {
				S next = cur;
				next.x = nx;
				next.y = ny;
				next.v -= L[nx][ny];
				if (next.x == ox && next.y == oy && next.o == 0) {
					next.v *= 2;
					next.o = 1;
					if (next.v > next.ref()) {
						next.ref() = next.v;
						pq.push(next);
					}
				}
				else {
					if (next.v > next.ref()) {
						next.ref() = next.v;
						pq.push(next);
					}
				}
			}
		}
	}
	cout << (ok ? "YES" : "NO") << endl;
}
0