結果

問題 No.2029 Swap Min Max Min
ユーザー momoyuumomoyuu
提出日時 2022-08-17 21:59:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,161 bytes
コンパイル時間 4,830 ms
コンパイル使用メモリ 278,940 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 09:53:46
合計ジャッジ時間 7,541 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 36 ms
5,376 KB
testcase_04 AC 11 ms
5,376 KB
testcase_05 AC 22 ms
5,376 KB
testcase_06 AC 45 ms
5,376 KB
testcase_07 AC 41 ms
5,376 KB
testcase_08 AC 56 ms
5,504 KB
testcase_09 AC 17 ms
6,940 KB
testcase_10 AC 13 ms
6,944 KB
testcase_11 AC 22 ms
6,940 KB
testcase_12 AC 29 ms
6,940 KB
testcase_13 AC 60 ms
6,940 KB
testcase_14 AC 64 ms
6,940 KB
testcase_15 AC 64 ms
6,940 KB
testcase_16 AC 65 ms
6,940 KB
testcase_17 AC 58 ms
6,944 KB
testcase_18 AC 66 ms
6,944 KB
testcase_19 AC 64 ms
6,940 KB
testcase_20 AC 64 ms
6,944 KB
testcase_21 AC 64 ms
6,940 KB
testcase_22 AC 63 ms
6,940 KB
testcase_23 AC 67 ms
6,944 KB
testcase_24 AC 66 ms
6,944 KB
testcase_25 AC 66 ms
6,944 KB
testcase_26 AC 65 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 3 ms
6,944 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 3 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 56 ms
6,940 KB
testcase_39 AC 63 ms
6,940 KB
testcase_40 AC 56 ms
6,940 KB
testcase_41 AC 60 ms
6,940 KB
testcase_42 AC 61 ms
6,944 KB
testcase_43 AC 60 ms
6,940 KB
testcase_44 AC 65 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<class t> using vc = vector<t>;
template<class t> using vvc = vc<vc<t>>;
using pi = pair<int,int>;
using vi = vc<int>;
using vvi = vvc<int>;

#define rep(i,a,b) for (int i = a; i < b; i++)
#define irep(i,a,b) for (int i = a; i > b; i--)
#define print(n) cout << n << endl
#define rup(a,b) (a+b-1)/b


int main(){
    cout << fixed << setprecision(15);
    
    int N ;
    cin >> N;
    vi a(N);
    rep(i,0,N) cin >> a[i];
    int m = N / 2;
    vi b(N);
    int now = 0;
    rep(i,0,N){
        if (a[i]>m) continue;
        b[now] = i;
        now ++ ;
    }
    ll ans = 0;
    vc<ll> c(m);
    rep(i,0,m){
        ans += abs(2*i+1-b[i]);
        c[i] = ans;
    }
    if (N%2 == 0){
        ll aa = ans;
        ll na = 0;
        irep(i,m-1,-1){
            na += abs(2*i-b[i]);
            if (i!=0){
                aa = min(aa,na+c[i-1]);
            }else{
                aa = min(aa,na);
            }
        }
        ans = aa;
    }
    cout << m << " " << ans << endl;
    
    //system("pause");
    return 0;
}
0