結果

問題 No.2029 Swap Min Max Min
ユーザー RubikunRubikun
提出日時 2022-08-05 23:10:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,427 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 201,168 KB
実行使用メモリ 8,000 KB
最終ジャッジ日時 2023-10-14 00:58:27
合計ジャッジ時間 4,411 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 AC 13 ms
5,216 KB
testcase_04 AC 4 ms
4,352 KB
testcase_05 AC 7 ms
4,348 KB
testcase_06 AC 13 ms
4,352 KB
testcase_07 AC 14 ms
5,408 KB
testcase_08 AC 20 ms
7,688 KB
testcase_09 AC 6 ms
4,372 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 8 ms
4,616 KB
testcase_12 AC 10 ms
4,348 KB
testcase_13 AC 20 ms
7,732 KB
testcase_14 AC 19 ms
4,348 KB
testcase_15 AC 22 ms
7,728 KB
testcase_16 AC 19 ms
4,352 KB
testcase_17 AC 20 ms
7,744 KB
testcase_18 AC 22 ms
7,676 KB
testcase_19 AC 21 ms
4,348 KB
testcase_20 AC 20 ms
4,352 KB
testcase_21 AC 18 ms
4,356 KB
testcase_22 AC 19 ms
4,348 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 18 ms
4,352 KB
testcase_26 AC 19 ms
4,348 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 1 ms
4,352 KB
testcase_35 AC 1 ms
4,352 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 1 ms
4,352 KB
testcase_38 WA -
testcase_39 AC 19 ms
4,348 KB
testcase_40 AC 17 ms
4,348 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 18 ms
4,352 KB
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=600005,INF=1<<30;

ll dp[MAX][2];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<int> A;
    for(int i=0;i<N;i++){
        int x;cin>>x;
        if(x<=N/2) A.push_back(i);
    }
    
    ll ans=1LL<<60;
    
    if(N&1){
        vector<int> B;
        for(int i=1;i<N;i+=2) B.push_back(i);
        ll sum=0;
        for(int i=0;i<si(A);i++) sum+=abs(A[i]-B[i]);
        chmin(ans,sum);
    }else{
        for(int i=0;i<N;i++) for(int j=0;j<2;j++) dp[i][j]=INF;
        dp[0][1]=0;
        for(int i=0;i<N/2;i++){
            for(int j=0;j<2;j++){
                int a=(i-1)*2+j;
                for(int k=0;k<2;k++){
                    int b=i*2+k;
                    if(b-a==3) continue;
                    chmin(dp[i+1][k],dp[i][j]+abs(A[i]-b));
                }
            }
        }
        chmin(ans,dp[N/2][0]);
        chmin(ans,dp[N/2][1]);
    }
    
    cout<<N/2<<" "<<ans<<endl;
}
0