結果

問題 No.2690 A present from B (Hard)
ユーザー 👑 eoeoeoeo
提出日時 2024-03-16 13:45:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,031 bytes
コンパイル時間 6,644 ms
コンパイル使用メモリ 203,828 KB
実行使用メモリ 13,480 KB
最終ジャッジ日時 2024-03-17 22:30:11
合計ジャッジ時間 6,143 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,480 KB
testcase_01 AC 1 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 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// 計算量O(NM)

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m);
    for (ll i = 0; i < m; i++) {
        cin >> a[i];
        a[i]--;  // 0-indexedにする
    }

    vector<ll> dist_from_chair0(n);
    for (ll i = 0; i < n; i++) {
        dist_from_chair0[i] = i;
    }

    for (ll i = m - 1; i >= 0; i--) {
        swap(dist_from_chair0[a[i]], dist_from_chair0[a[i] + 1]);
        for (ll j = 0; j < n; j++) {
            if (j + 1 < n) chmin(dist_from_chair0[j + 1], dist_from_chair0[j] + 1);
        }
        for (ll j = n - 1; j >= 0; j--) {
            if (j - 1 >= 0) chmin(dist_from_chair0[j - 1], dist_from_chair0[j] + 1);
        }
    }

    for (ll i = 1; i < (ll)dist_from_chair0.size(); i++) {
        cout << dist_from_chair0[i] << (i == (ll)dist_from_chair0.size() - 1 ? "\n" : " ");
    }
}
0