結果

問題 No.34 砂漠の行商人
ユーザー atn112323atn112323
提出日時 2016-05-08 08:52:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,603 ms / 5,000 ms
コード長 955 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 61,116 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 19:23:51
合計ジャッジ時間 4,179 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 6 ms
4,384 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 825 ms
4,376 KB
testcase_08 AC 15 ms
4,376 KB
testcase_09 AC 14 ms
4,380 KB
testcase_10 AC 19 ms
4,380 KB
testcase_11 AC 35 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 35 ms
4,376 KB
testcase_14 AC 28 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 14 ms
4,384 KB
testcase_20 AC 19 ms
4,380 KB
testcase_21 AC 1,603 ms
4,380 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 22 ms
4,376 KB
testcase_25 AC 6 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>

using namespace std;

const int DX[] = {1, 0, -1, 0};
const int DY[] = {0, 1, 0, -1};

int N, V, SX, SY, GX, GY;
int L[100][100];
int dp[2][100][100];
int cur = 0, nex = 1;

int main() {
	cin >> N >> V >> SX >> SY >> GX >> GY;
	SX--; SY--; GX--; GY--;
	for (int y = 0; y < N; y++) {
		for (int x = 0; x < N; x++) {
			cin >> L[x][y];
		}
	}
	dp[cur][SX][SY] = V;
	for (int i = 0; i < 10000; i++) {
		for (int x = 0; x < N; x++) {
			for (int y = 0; y < N; y++) {
				dp[nex][x][y] = 0;
			}
		}
		for (int x = 0; x < N; x++) {
			for (int y = 0; y < N; y++) {
				for (int d = 0; d < 4; d++) {
					int xx = x + DX[d], yy = y + DY[d];
					if (0 <= xx && xx < N && 0 <= yy && yy < N) {
						dp[nex][xx][yy] = max(dp[nex][xx][yy], dp[cur][x][y] - L[xx][yy]);
					}
				}
			}
		}
		if (dp[nex][GX][GY] > 0) {
			cout << (i + 1) << endl;
			return 0;
		}
		cur ^= 1; nex ^= 1;
	}
	cout << -1 << endl;
	return 0;
}
0