結果

問題 No.20 砂漠のオアシス
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-15 22:42:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 1,092 bytes
コンパイル時間 1,334 ms
コンパイル使用メモリ 155,300 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 07:29:39
合計ジャッジ時間 2,434 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

int N;
int dp[200][200][2];
int L[200][200];

int ok(int a, int b){
	return a >= 0 && b >= 0 && a < N && b < N;
}

int main() {
	int V, Ox, Oy;
	cin >> N >> V >> Ox >> Oy;
	Ox--; Oy--;
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			cin >> L[i][j];
		}
	}
	
	dp[0][0][1] = V;
	priority_queue<tuple<int, int, int, int>> pq;

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

	pq.push(make_tuple(V, 0, 0, 1));
	while (!pq.empty()){
		auto now = pq.top(); pq.pop();
		int h = get<0>(now);
		int y = get<1>(now);
		int x = get<2>(now);
		int f = get<3>(now);
		if (y == N - 1 && x == N - 1){
			cout << "YES" << endl;
			return 0;
		}

		if (dp[y][x][f] != h) continue;

		if (f == 1 && y == Oy && x == Ox){
			h *= 2;
			f = 0;
		}
		for (int k = 0; k < 4; k++)
		{
			int ny = y + dy[k];
			int nx = x + dx[k];
			if (!ok(ny, nx)) continue;
			int nh = h - L[ny][nx];
			if (nh <= 0) continue;
			if (dp[ny][nx][f] < nh){
				dp[ny][nx][f] = nh;
				pq.push(make_tuple(nh, ny, nx, f));
			}
		}

	}
	cout << "NO" << endl;
}



0