結果

問題 No.2673 A present from B
ユーザー 👑 eoeoeoeo
提出日時 2024-02-11 21:44:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,031 bytes
コンパイル時間 2,466 ms
コンパイル使用メモリ 204,212 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-13 21:50:28
合計ジャッジ時間 3,300 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 3 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 2 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 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 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 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 3 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>
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