結果

問題 No.2029 Swap Min Max Min
ユーザー KKT89KKT89
提出日時 2022-08-05 21:59:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,109 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 140,836 KB
実行使用メモリ 9,544 KB
最終ジャッジ日時 2023-10-14 00:10:05
合計ジャッジ時間 9,166 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,544 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 TLE -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 23 ms
5,200 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

ll solve1(vector<int> v){
    ll res1 = 0;
    for(int i=0;i<v.size();i++){
        res1 += abs(2*i-v[i]);
    }
    return res1;
}

ll solve2(vector<int> v){
    ll res2 = 0;
    for(int i=0;i<v.size();i++){
        res2 += abs(2*i+1-v[i]);
    }
    return res2;
}

ll solve(vector<int> v){
    return min(solve1(v),solve2(v));
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int res = n/2;
    ll cnt = 1e18;
    vector<int> v;
    for(int i=0;i<n;i++){
        if(a[i] <= res){
            v.push_back(i);
        }
    }
    if(n%2 == 0){
        cnt = solve(v);
    }
    else{
        { // 末尾
            auto vv = v;
            if(v.back() != n-1){
                cnt = min(cnt,solve2(v));
            }
            else{
                ll uo = 0;
                for(int i=0;i<v.size();i--){
                    if(v[v.size()-1] != n-1-i){
                        uo += i;
                        for(int j=i;j<v.size();j++){
                            v[j]--;
                        }
                        cnt = min(cnt,solve2(v)+uo);
                        break;
                    }
                }
                if(uo == 0){
                    uo = n;
                    for(int i=0;i<v.size();i++){
                        v[i]--;
                    }
                    cnt = min(cnt,solve2(v)+uo);
                }
            }
            v = vv;
        } 
        { // 先頭
            auto vv = v;
            if(v[0] != 0){
                for(int i=0;i<v.size();i--){
                    v[i]--;
                }
                cnt = min(cnt,solve1(v));
            }
            else{
                ll uo = 0;
                for(int i=0;i<v.size();i++){
                    if(v[i] != i){
                        uo = i;
                        for(int j=i;j<v.size();j++){
                            v[j]--;
                        }
                        cnt = min(cnt,solve1(v)+uo);
                    }
                }
                if(uo == 0){
                    uo = n;
                    cnt = min(cnt,solve1(v)+uo);
                }
            }
        }
    }
    cout << res << " " << cnt << endl;
}
0