結果

問題 No.2673 A present from B
ユーザー t98slidert98slider
提出日時 2024-03-15 21:45:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 629 ms / 2,000 ms
コード長 1,525 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 208,044 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-15 21:45:24
合計ジャッジ時間 6,054 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 4 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 627 ms
6,548 KB
testcase_07 AC 629 ms
6,548 KB
testcase_08 AC 624 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 118 ms
6,548 KB
testcase_13 AC 49 ms
6,548 KB
testcase_14 AC 220 ms
6,548 KB
testcase_15 AC 43 ms
6,548 KB
testcase_16 AC 39 ms
6,548 KB
testcase_17 AC 9 ms
6,548 KB
testcase_18 AC 48 ms
6,548 KB
testcase_19 AC 7 ms
6,548 KB
testcase_20 AC 185 ms
6,548 KB
testcase_21 AC 395 ms
6,548 KB
testcase_22 AC 2 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
    if(vec.empty()) return os;
    os << vec[0];
    for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
    return os;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> dp(n, vector<int>(n, 1 << 30));
    vector<int> a(m);
    cin >> a;
    for(auto &&v : a) v--;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            dp[i][j] = abs(i - j);
        }
    }
    for(int i = 0; i < m; i++){
        vector<vector<int>> ndp(n, vector<int>(n, 1 << 30));
        int u = a[i], v = a[i] + 1;
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                if(k == u || k == v){
                    ndp[j][k ^ u ^ v] = min(ndp[j][k ^ u ^ v], dp[j][k]);
                }else{
                    ndp[j][k] = min(ndp[j][k], dp[j][k]);
                }
            }
            for(int k = 0; k + 1 < n; k++){
                ndp[j][k + 1] = min(ndp[j][k + 1], ndp[j][k] + 1);
            }
            for(int k = n - 1; k >= 1; k--){
                ndp[j][k - 1] = min(ndp[j][k - 1], ndp[j][k] + 1);
            }
        }
        swap(dp, ndp);
    }
    for(int i = 1; i < n; i++){
        cout << dp[i][0] << (i + 1 == n ? '\n' : ' ');
    }
}
0