結果

問題 No.34 砂漠の行商人
ユーザー kaffelunkaffelun
提出日時 2018-10-17 00:20:56
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,082 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 160,516 KB
実行使用メモリ 10,268 KB
最終ジャッジ日時 2024-04-20 20:41:43
合計ジャッジ時間 8,588 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
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 dir[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int main() {
	#ifdef DEBUG
	std::ifstream in("/home/share/inputf.in");
	std::cin.rdbuf(in.rdbuf());
	#endif
	int V, N, sx, sy, gx, gy;
	int L[100][100];
	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];
		}
	}
	int m[2][100][100];
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			m[0][i][j] = m[1][i][j] = 0;
		}
	}
	m[0][sy][sx] = V;
	int t = 0;
	int flag = 0;
	for(;!flag;t++) {
		flag = 1;
		for(int y = 0; y < N; y++) {
			for(int x = 0; x < N; x++) {
				if(m[t&1][y][x] <= 0) continue;
				if(y == gy && x == gx) {
					cout << t << endl;
					return 0;
				}
				for(int d = 0; d < 4; d++) {
					int ny = y + dir[d][0];
					int nx = x + dir[d][1];
					if(nx < 0 || N <= nx || ny < 0 || N <= ny) continue;
					m[~t&1][ny][nx] = max(m[~t&1][ny][nx], m[t&1][y][x] - L[ny][nx]);
					flag = 0;
				}
				m[t&1][y][x] = 0;
			}
		}
	}
	cout << -1 << endl;
	return 0;
}
0