結果
| 問題 | No.34 砂漠の行商人 |
| コンテスト | |
| ユーザー |
h_noson
|
| 提出日時 | 2016-03-26 14:25:50 |
| 言語 | C++11(old_compat) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 5,000 ms |
| コード長 | 1,193 bytes |
| 記録 | |
| コンパイル時間 | 1,527 ms |
| コンパイル使用メモリ | 177,704 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-03-08 16:06:06 |
| 合計ジャッジ時間 | 2,305 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000
typedef long long ll;
int main() {
int i, j, n, v, sx, sy, gx, gy;
int l[101][101], cost[101][101];
queue<tuple<int,int,int,int>> q;
cin >> n >> v >> sx >> sy >> gx >> gy;
REP (i,1,n+1) REP (j,1,n+1) cin >> l[j][i];
q.push(make_tuple(sx,sy,0,0));
REP (i,1,n+1) fill(cost[i]+1,cost[i]+n+1,INF);
cost[sx][sy] = 0;
while (!q.empty()) {
int x, y, d, c;
int dx[4] {-1,0,1,0};
tie(x,y,d,c) = q.front(); q.pop();
if (x == gx && y == gy) {
cout << d << endl;
return 0;
}
rep (i,4) {
int nx = x+dx[i];
int ny = y+dx[(i+1)%4];
if (min(nx,ny) >= 1 && max(nx,ny) <= n && c+l[nx][ny] < v && c+l[nx][ny] < cost[nx][ny]) {
cost[nx][ny] = c+l[nx][ny];
q.push(make_tuple(nx,ny,d+1,cost[nx][ny]));
}
}
}
cout << -1 << endl;
return 0;
}
h_noson