結果

問題 No.20 砂漠のオアシス
ユーザー NotationNapNotationNap
提出日時 2015-04-26 03:18:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 1,268 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 162,916 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 06:27:40
合計ジャッジ時間 2,129 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 8 ms
5,376 KB
testcase_06 AC 8 ms
5,376 KB
testcase_07 AC 30 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 24 ms
5,376 KB
testcase_10 AC 1 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 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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, y, v, o;
	int& ref() {
		return memo[x][y][o];
	}
	bool operator<(const S& o) const {
		return v < o.v;
	}
};

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

int main() {
	int V;
	cin >> N >> V;
	cin >> OY >> OX;
	OX--;
	OY--;
	REP(i, N) REP(j, N) cin >> L[i][j];

	bool ok = false;
	queue<S> pq;
	S start;
	start.x = 0;
	start.y = 0;
	start.v = V;
	start.o = 0;
	start.ref() = V;
	pq.push(start);
	while (!pq.empty()) {
		S cur = pq.front(); pq.pop();
		if (cur.v <= 0) continue;
		if (cur.x == N-1 && cur.y == N-1) {
			ok = true;
			break;
		}
		if (cur.ref() != cur.v) continue;
		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 (nx == OX && ny == OY && next.o == 0) {
					next.v *= 2;
					next.o = 1;
				}
				if (next.ref() < next.v) {
					next.ref() = next.v;
					pq.push(next);
				}
			}
		}
	}
	cout << (ok ? "YES" : "NO") << endl;
}
0