結果

問題 No.2095 High Rise
ユーザー sawfishsawfish
提出日時 2022-10-16 21:17:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,491 ms / 2,000 ms
コード長 1,042 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 65,856 KB
実行使用メモリ 19,048 KB
最終ジャッジ日時 2023-09-09 22:37:30
合計ジャッジ時間 10,898 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 89 ms
7,968 KB
testcase_18 AC 49 ms
7,484 KB
testcase_19 AC 12 ms
4,376 KB
testcase_20 AC 135 ms
5,748 KB
testcase_21 AC 325 ms
9,320 KB
testcase_22 AC 1,490 ms
18,968 KB
testcase_23 AC 1,487 ms
19,016 KB
testcase_24 AC 1,491 ms
19,048 KB
testcase_25 AC 1,491 ms
19,000 KB
testcase_26 AC 1,491 ms
18,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
using LL = long long;

constexpr LL INF = 1L << 60;

LL dp[1001][1001];

int main() {
    int N, M;
    cin >> N >> M;

    if (N == 1) {
        cout << 0 << endl;
        exit(0);
    }

    LL A[N + 1][M + 1];
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            cin >> A[i][j];
        }
    }

    for (int i = 0; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            if (i == 0) dp[i][j] = 0;
            else dp[i][j] = INF;
        }
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            for (int k = 1; k <= M; k++) {
                if (j != k) {
                    dp[i][j] = min(dp[i][j], dp[i - 1][k] + A[i][k] + (i != N ? A[i][j] : 0));
                } else {
                    dp[i][j] = min(dp[i][j], dp[i - 1][j] + A[i][j]);
                }
            }
        }
    }

    LL ans = INF;
    for (int i = 1; i <= M; i++) {
        ans = min(ans, dp[N][i]);
    }

    cout << ans << endl;
}
0