結果

問題 No.2029 Swap Min Max Min
ユーザー t98slidert98slider
提出日時 2022-08-06 12:00:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 727 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 167,364 KB
実行使用メモリ 4,660 KB
最終ジャッジ日時 2023-10-14 13:36:16
合計ジャッジ時間 7,862 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 31 ms
4,368 KB
testcase_04 AC 10 ms
4,368 KB
testcase_05 AC 19 ms
4,368 KB
testcase_06 AC 38 ms
4,376 KB
testcase_07 AC 36 ms
4,368 KB
testcase_08 AC 49 ms
4,504 KB
testcase_09 AC 14 ms
4,368 KB
testcase_10 AC 11 ms
4,372 KB
testcase_11 AC 19 ms
4,372 KB
testcase_12 AC 24 ms
4,368 KB
testcase_13 AC 52 ms
4,660 KB
testcase_14 AC 56 ms
4,516 KB
testcase_15 AC 55 ms
4,372 KB
testcase_16 AC 55 ms
4,372 KB
testcase_17 AC 52 ms
4,372 KB
testcase_18 AC 58 ms
4,428 KB
testcase_19 AC 55 ms
4,508 KB
testcase_20 AC 57 ms
4,436 KB
testcase_21 AC 55 ms
4,420 KB
testcase_22 AC 54 ms
4,504 KB
testcase_23 AC 57 ms
4,496 KB
testcase_24 AC 58 ms
4,404 KB
testcase_25 AC 57 ms
4,452 KB
testcase_26 AC 57 ms
4,428 KB
testcase_27 AC 1 ms
4,372 KB
testcase_28 AC 2 ms
4,368 KB
testcase_29 AC 2 ms
4,372 KB
testcase_30 AC 2 ms
4,368 KB
testcase_31 AC 2 ms
4,372 KB
testcase_32 AC 2 ms
4,372 KB
testcase_33 AC 1 ms
4,372 KB
testcase_34 AC 2 ms
4,368 KB
testcase_35 AC 1 ms
4,368 KB
testcase_36 AC 1 ms
4,368 KB
testcase_37 AC 1 ms
4,368 KB
testcase_38 AC 49 ms
4,384 KB
testcase_39 AC 55 ms
4,420 KB
testcase_40 AC 49 ms
4,376 KB
testcase_41 AC 52 ms
4,368 KB
testcase_42 AC 52 ms
4,392 KB
testcase_43 AC 52 ms
4,372 KB
testcase_44 AC 56 ms
4,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n), pos;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] <= n / 2)pos.push_back(i);
    }
    ll ans = 0;
    if(n & 1){
        for(int i = 0; i < pos.size(); i++){
            ans += abs(2 * i + 1 - pos[i]);
        }
    }else{
        ll s = 0;
        for(int i = 0; i < pos.size(); i++){
            s += abs(2 * i + 1 - pos[i]);
        }
        ans = s;
        for(int i = pos.size() - 1; i >= 0; i--){
            s -= abs(2 * i + 1 - pos[i]);
            s += abs(2 * i - pos[i]);
            ans = min(ans, s);
        }
    }
    cout << n / 2 << " " << ans << endl;
}
0