結果

問題 No.2029 Swap Min Max Min
ユーザー HaaHaa
提出日時 2022-08-05 22:30:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,021 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 169,608 KB
実行使用メモリ 5,768 KB
最終ジャッジ日時 2023-10-14 00:12:03
合計ジャッジ時間 4,897 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 32 ms
4,500 KB
testcase_04 AC 10 ms
4,352 KB
testcase_05 AC 19 ms
4,348 KB
testcase_06 AC 40 ms
5,072 KB
testcase_07 AC 37 ms
4,668 KB
testcase_08 AC 51 ms
5,408 KB
testcase_09 AC 14 ms
4,348 KB
testcase_10 AC 12 ms
4,352 KB
testcase_11 AC 20 ms
4,348 KB
testcase_12 AC 25 ms
4,372 KB
testcase_13 AC 54 ms
5,464 KB
testcase_14 AC 58 ms
5,688 KB
testcase_15 AC 57 ms
5,520 KB
testcase_16 AC 57 ms
5,708 KB
testcase_17 AC 53 ms
5,432 KB
testcase_18 AC 60 ms
5,736 KB
testcase_19 AC 58 ms
5,720 KB
testcase_20 AC 58 ms
5,564 KB
testcase_21 AC 57 ms
5,544 KB
testcase_22 AC 56 ms
5,708 KB
testcase_23 AC 59 ms
5,744 KB
testcase_24 AC 59 ms
5,644 KB
testcase_25 AC 58 ms
5,740 KB
testcase_26 AC 58 ms
5,684 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 2 ms
4,356 KB
testcase_32 AC 2 ms
4,356 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 1 ms
4,352 KB
testcase_36 AC 2 ms
4,352 KB
testcase_37 AC 2 ms
4,352 KB
testcase_38 AC 51 ms
5,580 KB
testcase_39 AC 57 ms
5,544 KB
testcase_40 AC 52 ms
5,672 KB
testcase_41 AC 54 ms
5,768 KB
testcase_42 AC 54 ms
5,516 KB
testcase_43 AC 55 ms
5,496 KB
testcase_44 AC 59 ms
5,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

int main(){
    int n; cin >> n;
    VI a(n); REP(i,n) cin >> a[i], a[i]--;
    int x=n/2;
    VI b;
    REP(i,n){
        if(a[i]<x)
            b.push_back(i);
    }
    ll ans=INF, s;
    if(n%2==0){
        s=0;
        REP(i,n/2){
            s+=abs(i*2-b[i]);
        }
        chmin(ans,s);
        REP(i,n/2){
            s-=abs(i*2-b[i]);
            s+=abs(i*2+1-b[i]);
            chmin(ans,s);
        }
    }
    else{
        s=0;
        REP(i,n/2){
            s+=abs(i*2+1-b[i]);
        }
        chmin(ans,s);
    }
    cout << x << " " << ans << endl;
    return 0;
}
0