結果

問題 No.34 砂漠の行商人
ユーザー NotationNapNotationNap
提出日時 2015-05-01 02:40:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,003 ms / 5,000 ms
コード長 1,108 bytes
コンパイル時間 1,342 ms
コンパイル使用メモリ 151,868 KB
実行使用メモリ 122,036 KB
最終ジャッジ日時 2023-09-10 19:08:44
合計ジャッジ時間 7,409 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
120,740 KB
testcase_01 AC 40 ms
120,700 KB
testcase_02 AC 44 ms
120,632 KB
testcase_03 AC 40 ms
120,572 KB
testcase_04 AC 72 ms
120,868 KB
testcase_05 AC 72 ms
120,916 KB
testcase_06 AC 43 ms
120,540 KB
testcase_07 AC 404 ms
121,008 KB
testcase_08 AC 161 ms
121,144 KB
testcase_09 AC 220 ms
121,504 KB
testcase_10 AC 53 ms
120,768 KB
testcase_11 AC 410 ms
121,908 KB
testcase_12 AC 47 ms
120,804 KB
testcase_13 AC 698 ms
122,036 KB
testcase_14 AC 518 ms
121,944 KB
testcase_15 AC 41 ms
120,644 KB
testcase_16 AC 68 ms
120,980 KB
testcase_17 AC 41 ms
120,536 KB
testcase_18 AC 42 ms
120,568 KB
testcase_19 AC 180 ms
121,768 KB
testcase_20 AC 278 ms
121,948 KB
testcase_21 AC 1,003 ms
121,712 KB
testcase_22 AC 44 ms
120,816 KB
testcase_23 AC 41 ms
120,580 KB
testcase_24 AC 360 ms
121,932 KB
testcase_25 AC 61 ms
120,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long Int;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))


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

int N, V, SX, SY, GX, GY;
int L[100][100];
int best[100][100][3000];

bool isin(int x, int y) {
	return 0 <= x && x < N && 0 <= y && y < N;
}

int main() {
	cin >> N >> V >> SY >> SX >> GY >> GX;
	SX--;
	SY--;
	GX--;
	GY--;
	REP(i, N) REP(j, N) cin >> L[i][j];	
	REP(i, 100)REP(j, 100) REP(k, 3000) best[i][j][k] = -1;
	queue<tuple<int, int, int>> q;
	q.push(make_tuple(SX, SY, 0));
	best[SX][SY][0] = 0;
	int ans = -1;
	while (!q.empty()) {
		auto t = q.front();
		q.pop();
		int x = get<0>(t);
		int y = get<1>(t);
		int v = get<2>(t);
		int step = best[x][y][v];

		if (x == GX && y == GY && v < V) {
			ans = step;
			break;
		}

		REP(i, 4) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (isin(nx, ny)) {
				int nv = v + L[nx][ny];
				if (nv <= 2 * N * 10 + 100)
					if (best[nx][ny][nv] == -1) {
						best[nx][ny][nv] = step + 1;
						q.push(make_tuple(nx, ny, nv));
					}
			}
		}
	}
	cout << ans << endl;

}
0