結果

問題 No.2673 A present from B
ユーザー GOTKAKOGOTKAKO
提出日時 2024-03-15 21:57:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 984 bytes
コンパイル時間 2,126 ms
コンパイル使用メモリ 208,560 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-15 21:57:33
合計ジャッジ時間 3,279 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 5 ms
6,676 KB
testcase_07 AC 5 ms
6,676 KB
testcase_08 AC 5 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 3 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 4 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 1 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>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M; cin >> N >> M;
    vector<int> A(M);
    for(auto &a : A) cin >> a;
    reverse(A.begin(),A.end());

    int inf = 1e9;
    vector<vector<int>> dp(M+1,vector<int>(N+2,inf));
    dp.at(0).at(1) = 0;
    auto chmin = [](auto &a, auto b){a = min(a,b);};
    for(int i=0; i<=M; i++){
        for(int k=2; k<=N; k++) chmin(dp.at(i).at(k),dp.at(i).at(k-1)+1);
        for(int k=N-1; k>=1; k--) chmin(dp.at(i).at(k),dp.at(i).at(k+1)+1);
        if(i == M) break;

        int a = A.at(i);
        for(int k=1; k<=N; k++){
            if(k == a) chmin(dp.at(i+1).at(k+1),dp.at(i).at(k));
            else if(k == a+1) chmin(dp.at(i+1).at(k-1),dp.at(i).at(k));
            else chmin(dp.at(i+1).at(k),dp.at(i).at(k));
        }
    }

    for(int i=2; i<=N; i++){
        if(i != 2) cout << " ";
        cout << dp.back().at(i); 
    }    
    cout << endl;
}
0