結果

問題 No.34 砂漠の行商人
ユーザー btkbtk
提出日時 2015-05-13 23:53:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 785 ms / 5,000 ms
コード長 982 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 59,708 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 19:08:22
合計ジャッジ時間 2,617 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>


using namespace std;

int cost[110][110];
int dp[2][110][110];
int INF = 1000000;
int dir[] = { 0, 1, 0, -1, 0 };
int main(void){
	int N, V, NN, SX, SY, GX, GY;
	cin >> N >> V >> SY >> SX >> GY >> GX;
	NN = N*N;
	for (int i = 0; i < N; i++){
		cost[i][0] = cost[0][i] = cost[i][N + 1] = cost[N + 1][i] = INF;
	}
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++){
			cin >> cost[i + 1][j + 1];
			dp[0][i + 1][j + 1]=dp[1][i + 1][j + 1] = INF;
		}
	}
	dp[0][SX][SY] = 0;

	for (int i = 1; i <= NN; i++){
		for (int x = 1; x <= N; x++){
			for (int y = 1; y <= N; y++){
				for (int j = 0; j < 4; j++){
					dp[i & 1][x + dir[j]][y + dir[j + 1]] = min(dp[i & 1][x + dir[j]][y + dir[j + 1]], dp[(i & 1) ^ 1][x][y] + cost[x + dir[j]][y + dir[j + 1]]);
				}
				dp[i&1][x][y] = min(dp[i&1][x][y], dp[(i & 1) ^ 1][x][y]);
			}
		}
		if (dp[i&1][GX][GY] < V){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;

}
0