結果

問題 No.20 砂漠のオアシス
ユーザー pekempeypekempey
提出日時 2015-08-19 16:51:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,569 bytes
コンパイル時間 1,677 ms
コンパイル使用メモリ 170,768 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 06:42:21
合計ジャッジ時間 2,159 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

int N, V, Ox, Oy;
int L[200][200];

int dp[200][200][2]; // y, x, oasis
typedef tuple<int, bool, int, int> P; // life, oasis, y, x

int main() {
	cin >> N >> V >> Oy >> Ox;
	Ox--; Oy--;
	rep (j, N) rep (i, N) cin >> L[i][j];

	priority_queue<P> q;
	q.emplace(V, false, 0, 0);
	memset(dp, -1, sizeof(dp));

	dp[0][0][0] = V;

	while (!q.empty()) {
		P p = q.top(); q.pop();
		int y = get<2>(p);
		int x = get<3>(p);
		bool oasis = get<1>(p);

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

		rep (k, 4) {
			int ny = y + dy[k];
			int nx = x + dx[k];

			if (ny < 0 || ny >= N || nx < 0 || nx >= N) continue;

			if (ny == Oy && nx == Ox && !oasis) {
				if (dp[y][x][0] - L[ny][nx] > 0) {
					if (dp[ny][nx][1] < (dp[y][x][0] - L[ny][nx]) * 2) {
						dp[ny][nx][1] = (dp[y][x][0] - L[ny][nx]) * 2;
						q.emplace(dp[ny][nx][1], true, ny, nx);
					}	
				}
				
			}

			if (dp[y][x][oasis] - L[ny][nx] > 0) {
				if (dp[ny][nx][oasis] < dp[y][x][oasis] - L[ny][nx]) {
					dp[ny][nx][oasis] = dp[y][x][oasis] - L[ny][nx];
					q.emplace(dp[ny][nx][oasis], oasis, ny, nx);
				}
			}
		}
	}

	if (dp[N - 1][N - 1][0] > 0 || dp[N - 1][N - 1][1] > 0) {
		cout << "YES" << endl;	
	} else {
		cout << "NO" << endl;
	}

	return 0;
}
0