結果
| 問題 |
No.34 砂漠の行商人
|
| コンテスト | |
| ユーザー |
ふーらくたる
|
| 提出日時 | 2016-07-03 16:35:00 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,180 bytes |
| コンパイル時間 | 643 ms |
| コンパイル使用メモリ | 65,476 KB |
| 実行使用メモリ | 814,252 KB |
| 最終ジャッジ日時 | 2024-10-12 19:45:26 |
| 合計ジャッジ時間 | 4,893 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 MLE * 1 -- * 16 |
ソースコード
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
struct State {
int x, y, times, hp;
};
const int kMAX_N = 110;
int L[kMAX_N][kMAX_N];
int max_hp[kMAX_N][kMAX_N];
int N, V, sx, sy, gx, gy;
int dx[4] = {1, 0, -1, 0},
dy[4] = {0, 1, 0, -1};
void Solve() {
queue<State> que;
max_hp[sx - 1][sy - 1] = V;
que.push((State){sx - 1, sy - 1, 0, V});
while (!que.empty()) {
State s = que.front(); que.pop();
if (s.x == gx - 1 && s.y == gy - 1) {
cout << s.times << endl;
return;
}
for (int i = 0; i < 4; i++) {
int nx = s.x + dx[i], ny = s.y + dy[i];
if (0 <= nx && nx < N && 0 <= ny && ny < N &&
s.hp - L[nx][ny] > 0 && s.hp > max_hp[nx][ny]) {
max_hp[nx][ny] = s.hp - L[nx][ny];
que.push((State){nx, ny, s.times + 1, s.hp - L[nx][ny]});
}
}
}
cout << -1 << endl;
}
int main() {
cin >> N >> V >> sx >> sy >> gx >> gy;
for (int y = 0; y < N; y++) {
for (int x = 0; x < N; x++) {
cin >> L[x][y];
}
}
Solve();
return 0;
}
ふーらくたる