結果

問題 No.34 砂漠の行商人
ユーザー kaffelunkaffelun
提出日時 2018-06-21 23:49:35
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,167 bytes
コンパイル時間 1,211 ms
コンパイル使用メモリ 145,108 KB
実行使用メモリ 390,244 KB
最終ジャッジ日時 2023-09-13 07:44:44
合計ジャッジ時間 13,216 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
164,656 KB
testcase_01 AC 54 ms
167,104 KB
testcase_02 AC 189 ms
211,956 KB
testcase_03 AC 140 ms
312,560 KB
testcase_04 AC 597 ms
348,228 KB
testcase_05 AC 630 ms
359,988 KB
testcase_06 AC 374 ms
364,808 KB
testcase_07 AC 938 ms
382,812 KB
testcase_08 AC 1,188 ms
390,244 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int N, V, sx, sy, gx, gy;
int L[100][100];
// (vital, x, y) => length
int dp[10000][100][100];
const int dir[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
const int INF = 100000000;

// v: vital, x:x coord, y:y coord, l:length, od: old direction
void recursive(int v, int x, int y, int l, int od) {
	if (v <= 0 || dp[v][y][x] <= l) return;
	dp[v][y][x] = l;
	if(x == gx && y == gy) return;
	for(int d = 0; d < 4; d++) {
		int nx = x + dir[d][1], ny = y + dir[d][0];
		if(nx < 0 || N <= nx || ny < 0 || N <= ny || d == od) continue;
		recursive(v - L[ny][nx], nx, ny, l + 1, d ^ 2);
	}
}

int main() {
	#ifdef DEBUG
	std::ifstream in("/home/share/inputf.in");
	std::cin.rdbuf(in.rdbuf());
	#endif
	cin >> N >> V >> sx >> sy >> gx >> gy;
	sx--, sy--, gx--, gy--;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			cin >> L[i][j];
			for(int k = 0; k < 10000; k++) {
				dp[k][i][j] = INF;
			}
		}
	}
	recursive(V, sx, sy, 0, -1);
	int ans = INF;
	for(int i = 0; i < 10000; i++) {
		if(dp[i][gy][gx] == 0) continue;
		ans = min(ans, dp[i][gy][gx]);
	}
	if(ans == INF) ans = -1;
	cout << ans << endl;
	return 0;
}
0