結果

問題 No.34 砂漠の行商人
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-06 21:12:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 5,000 ms
コード長 1,297 bytes
コンパイル時間 1,606 ms
コンパイル使用メモリ 166,720 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 07:29:35
合計ジャッジ時間 3,493 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 139 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 10 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 10 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 151 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 6 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int N, V, Sx, Sy, Gx, Gy;
    cin >> N >> V >> Sx >> Sy >> Gx >> Gy;
    int L[110][110];
    for (int i = 0; i < N + 2; i++) {
        for (int j = 0; j < N + 2; j++) {
            L[i][j] = 100000;
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> L[j + 1][i + 1];
        }
    }


    int dp[110][110][2] = {};
    dp[Sx][Sy][0] = V;

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

    int now = 0, nxt = 1;
    int cnt = 0;
    for (int loop = 0; loop < N * N; loop++) {
        if (dp[Gx][Gy][now]) {
            cout << cnt << endl;
            return 0;
        }
        cnt++;
        for (int x = 1; x <= N; x++) {
            for (int y = 1; y <= N; y++) {
                dp[x][y][nxt] = 0;
            }
        }
        for (int x = 1; x <= N; x++) {
            for (int y = 1; y <= N; y++) {
                if (dp[x][y][now]) {
                    for (int i = 0; i < 4; i++) {
                        dp[x + dx[i]][y + dy[i]][nxt] = max(dp[x + dx[i]][y + dy[i]][nxt], dp[x][y][now] - L[x + dx[i]][y + dy[i]]);
                    }
                }
            }
        }
        swap(now, nxt);
    }
    cout << -1 << endl;
}
0