結果

問題 No.2029 Swap Min Max Min
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2022-08-06 00:23:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,034 bytes
コンパイル時間 2,060 ms
コンパイル使用メモリ 200,772 KB
実行使用メモリ 5,452 KB
最終ジャッジ日時 2023-10-14 02:42:57
合計ジャッジ時間 5,845 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 31 ms
4,368 KB
testcase_04 AC 10 ms
4,348 KB
testcase_05 AC 19 ms
4,352 KB
testcase_06 AC 38 ms
4,356 KB
testcase_07 AC 36 ms
4,536 KB
testcase_08 AC 49 ms
5,148 KB
testcase_09 AC 14 ms
4,356 KB
testcase_10 AC 12 ms
4,348 KB
testcase_11 AC 19 ms
4,348 KB
testcase_12 AC 25 ms
4,352 KB
testcase_13 AC 53 ms
5,168 KB
testcase_14 AC 57 ms
4,612 KB
testcase_15 AC 55 ms
5,140 KB
testcase_16 AC 55 ms
4,600 KB
testcase_17 AC 52 ms
5,220 KB
testcase_18 AC 59 ms
5,420 KB
testcase_19 AC 56 ms
4,620 KB
testcase_20 AC 57 ms
4,572 KB
testcase_21 AC 56 ms
4,552 KB
testcase_22 AC 55 ms
4,512 KB
testcase_23 AC 58 ms
5,452 KB
testcase_24 AC 58 ms
5,300 KB
testcase_25 AC 57 ms
4,616 KB
testcase_26 AC 57 ms
4,512 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 2 ms
4,352 KB
testcase_37 AC 2 ms
4,356 KB
testcase_38 AC 50 ms
5,164 KB
testcase_39 AC 54 ms
4,548 KB
testcase_40 AC 48 ms
4,372 KB
testcase_41 AC 52 ms
5,152 KB
testcase_42 AC 53 ms
5,152 KB
testcase_43 AC 53 ms
4,640 KB
testcase_44 AC 58 ms
5,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
    int N;
    cin >> N;
    std::vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    cout << N / 2 << " ";
    if (N % 2) {
        ll ans = 0;
        ll now = 1;
        for (int i = 0; i < N; i ++) {
            if (A[i] <= N / 2) {
                ans += abs(now - i);
                now += 2;
            }
        }
        cout << ans << endl;
    } else {
        ll ans1 = 0;
        ll now = 0;
        vector<ll> B(N / 2);
        for (int i = 0; i < N; i ++) {
            if (A[i] <= N / 2) {
                B[now] = i - now * 2;
                ans1 += abs(B[now]);
                now ++;
            }
        }
        ll ans2 = 0;
        now = 0;
        for (int i = 0; i < N / 2; i ++) {
            if (B[i] > 0) {
                now --;
            } else {
                now ++;
            }
            ans2 = min(ans2, now);
        }
        cout << ans2 + ans1 << endl;
        // return 139;
    }
}
0