結果

問題 No.34 砂漠の行商人
ユーザー ふーらくたるふーらくたる
提出日時 2016-07-03 16:35:00
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,180 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 65,052 KB
実行使用メモリ 814,136 KB
最終ジャッジ日時 2024-04-20 21:31:55
合計ジャッジ時間 5,115 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 29 ms
12,928 KB
testcase_05 AC 8 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 17 ms
6,940 KB
testcase_08 AC 19 ms
6,940 KB
testcase_09 MLE -
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 <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;
}
0