結果

問題 No.2029 Swap Min Max Min
ユーザー baLoon8128baLoon8128
提出日時 2022-08-05 23:37:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 3,678 ms
コンパイル使用メモリ 226,492 KB
実行使用メモリ 7,292 KB
最終ジャッジ日時 2023-10-14 01:42:11
合計ジャッジ時間 7,510 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 31 ms
5,132 KB
testcase_04 AC 10 ms
4,352 KB
testcase_05 AC 20 ms
4,536 KB
testcase_06 AC 39 ms
5,852 KB
testcase_07 AC 37 ms
5,484 KB
testcase_08 AC 50 ms
6,216 KB
testcase_09 AC 15 ms
4,352 KB
testcase_10 AC 12 ms
4,352 KB
testcase_11 AC 20 ms
4,544 KB
testcase_12 AC 26 ms
4,704 KB
testcase_13 AC 54 ms
6,472 KB
testcase_14 AC 58 ms
6,712 KB
testcase_15 AC 57 ms
6,856 KB
testcase_16 AC 58 ms
6,716 KB
testcase_17 AC 54 ms
6,500 KB
testcase_18 AC 59 ms
6,976 KB
testcase_19 AC 55 ms
6,764 KB
testcase_20 AC 59 ms
6,824 KB
testcase_21 AC 58 ms
6,788 KB
testcase_22 AC 58 ms
6,760 KB
testcase_23 AC 59 ms
7,052 KB
testcase_24 AC 58 ms
7,292 KB
testcase_25 AC 59 ms
7,288 KB
testcase_26 AC 59 ms
7,176 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,352 KB
testcase_38 AC 51 ms
6,548 KB
testcase_39 AC 56 ms
6,792 KB
testcase_40 AC 51 ms
6,528 KB
testcase_41 AC 53 ms
6,472 KB
testcase_42 AC 54 ms
6,824 KB
testcase_43 AC 55 ms
6,792 KB
testcase_44 AC 58 ms
6,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i)

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    int x = n / 2;
    rep(i, n) a[i] = (a[i] > x ? 0 : 1);
    vector<ll> dpl(n + 1), dpr(n + 1);
    for (int i = 0, k = 1; i < n; i++) {
        dpl[i + 1] = dpl[i];
        if (a[i] & 1) dpl[i + 1] += abs(i - k), k += 2;
    }
    for (int i = n - 1, k = n - 2; i >= 0; i--) {
        dpr[i] = dpr[i + 1];
        if (a[i] & 1) dpr[i] += abs(i - k), k -= 2;
    }
    ll y = dpl[n];
    rep(i, n) y = min(y, dpl[i] + dpr[i]);
    printf("%d %lld\n", x, y);
    return 0;
}
0