結果

問題 No.2673 A present from B
ユーザー nono00nono00
提出日時 2024-03-15 22:06:01
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 959 bytes
コンパイル時間 3,132 ms
コンパイル使用メモリ 251,280 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-15 22:06:06
合計ジャッジ時間 4,742 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 148 ms
6,676 KB
testcase_07 AC 148 ms
6,676 KB
testcase_08 AC 148 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 30 ms
6,676 KB
testcase_13 AC 16 ms
6,676 KB
testcase_14 AC 54 ms
6,676 KB
testcase_15 AC 13 ms
6,676 KB
testcase_16 AC 13 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 14 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 46 ms
6,676 KB
testcase_21 AC 95 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

namespace nono {

void solve() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> a(m);
    for (int i = 0; i < m; i++) std::cin >> a[i];
    for (int i = 0; i < m; i++) a[i]--;
    constexpr int INF = 1e9;
    std::vector dp(m + 1, std::vector<int>(n, INF));
    for (int i = 0; i < n; i++) {
        dp[0][i] = i;
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            int cur = (a[m - i - 1] == j ? j + 1 : (a[m - i - 1] + 1 == j ? j - 1 : j));
            for (int k = 0; k < n; k++) {
                dp[i + 1][k] = std::min(dp[i + 1][k], dp[i][j] + std::abs(k - cur));
            }
        }
    }
    for (int i = 1; i < n; i++) {
        std::cout << dp[m][i] << (i + 1 == n ? '\n' : ' ');
    }
}

}  //  namespace nono

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(16);
    int t = 1;

    while (t--) nono::solve();
}
0