結果
| 問題 | No.34 砂漠の行商人 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-11 01:30:20 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 5,000 ms |
| コード長 | 1,000 bytes |
| 記録 | |
| コンパイル時間 | 987 ms |
| コンパイル使用メモリ | 95,296 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-11 01:30:23 |
| 合計ジャッジ時間 | 2,529 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <iostream>
#include <queue>
#include <tuple>
using namespace std;
constexpr int DX[4] = {0, 1, 0, -1}, DY[4] = {1, 0, -1, 0};
int N, V, sx, sy, gx, gy;
int L[100][100], d[100][100];
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int N, V, sx, sy, gx, gy;
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];
queue<tuple<int, int, int, int>> que;
d[sx][sy] = V;
que.push(make_tuple(0, sx, sy, V));
while(!que.empty()) {
auto [dist, x, y, c] = que.front();
que.pop();
if(x == gx and y == gy) {
cout << dist << "\n";
return 0;
}
for(int dir = 0; dir < 4; ++dir) {
int nx = x + DX[dir], ny = y + DY[dir];
if(!(0 <= nx and nx < N and 0 <= ny and ny < N)) continue;
int nc = c - L[ny][nx];
if(d[nx][ny] < nc) {
d[nx][ny] = nc;
que.push(make_tuple(dist + 1, nx, ny, nc));
}
}
}
cout << -1 << "\n";
return 0;
}