結果

問題 No.2029 Swap Min Max Min
ユーザー umezoumezo
提出日時 2022-08-06 23:56:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 806 bytes
コンパイル時間 2,228 ms
コンパイル使用メモリ 201,892 KB
実行使用メモリ 6,180 KB
最終ジャッジ日時 2023-10-15 00:07:55
合計ジャッジ時間 6,256 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 2 ms
4,904 KB
testcase_03 AC 12 ms
5,424 KB
testcase_04 AC 5 ms
5,164 KB
testcase_05 AC 7 ms
4,352 KB
testcase_06 AC 15 ms
4,352 KB
testcase_07 AC 14 ms
5,468 KB
testcase_08 AC 19 ms
5,768 KB
testcase_09 AC 7 ms
5,216 KB
testcase_10 AC 5 ms
4,356 KB
testcase_11 AC 8 ms
5,136 KB
testcase_12 AC 9 ms
4,352 KB
testcase_13 AC 20 ms
5,996 KB
testcase_14 AC 20 ms
4,432 KB
testcase_15 AC 20 ms
5,860 KB
testcase_16 AC 19 ms
4,588 KB
testcase_17 AC 20 ms
5,808 KB
testcase_18 AC 22 ms
6,180 KB
testcase_19 AC 21 ms
4,424 KB
testcase_20 AC 21 ms
4,440 KB
testcase_21 AC 21 ms
4,480 KB
testcase_22 AC 19 ms
4,412 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 18 ms
4,452 KB
testcase_26 AC 19 ms
4,460 KB
testcase_27 AC 2 ms
5,024 KB
testcase_28 AC 2 ms
4,360 KB
testcase_29 AC 1 ms
4,356 KB
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 2 ms
4,360 KB
testcase_32 AC 3 ms
5,216 KB
testcase_33 AC 1 ms
4,352 KB
testcase_34 AC 2 ms
4,992 KB
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 2 ms
4,356 KB
testcase_37 AC 3 ms
4,908 KB
testcase_38 WA -
testcase_39 AC 19 ms
4,548 KB
testcase_40 AC 18 ms
4,368 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 19 ms
4,392 KB
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

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

ll dp[100100][2];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  vector<int> A(n);
  rep(i,n) cin>>A[i];
  
  cout<<n/2<<" ";
  
  vector<int> B;
  rep(i,n) if(A[i]<=n/2) B.push_back(i);
  if(n%2==1){
    ll ans=0;
    for(int i=1;i<n;i+=2) ans+=abs(i-B[i/2]);
    cout<<ans<<endl;
  }
  else{
    rep(i,100100) rep(j,2) dp[i][j]=1e9+7;
    dp[0][0]=0;
    rep(i,n/2){
      dp[i+1][0]=min(dp[i+1][0],dp[i][0]+abs(2*i+1-B[i]));
      dp[i+1][1]=min(dp[i+1][1],dp[i][0]+abs(2*i-B[i]));
      dp[i+1][1]=min(dp[i+1][1],dp[i][1]+abs(2*i-B[i]));
    }
    cout<<min(dp[n/2][0],dp[n/2][1])<<endl;
  }
  
  return 0;
}
0