結果

問題 No.2029 Swap Min Max Min
ユーザー SSRSSSRS
提出日時 2022-08-05 21:33:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 830 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 169,836 KB
実行使用メモリ 6,068 KB
最終ジャッジ日時 2023-10-14 00:04:03
合計ジャッジ時間 5,247 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 19 ms
4,372 KB
testcase_06 AC 38 ms
4,372 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 11 ms
4,372 KB
testcase_11 WA -
testcase_12 AC 25 ms
4,372 KB
testcase_13 WA -
testcase_14 AC 56 ms
4,392 KB
testcase_15 WA -
testcase_16 AC 55 ms
4,516 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 56 ms
4,428 KB
testcase_20 AC 56 ms
4,388 KB
testcase_21 AC 55 ms
4,380 KB
testcase_22 AC 54 ms
4,416 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 57 ms
4,600 KB
testcase_26 AC 56 ms
4,540 KB
testcase_27 AC 1 ms
4,372 KB
testcase_28 AC 2 ms
4,372 KB
testcase_29 AC 1 ms
4,372 KB
testcase_30 AC 2 ms
4,372 KB
testcase_31 AC 2 ms
4,372 KB
testcase_32 WA -
testcase_33 AC 2 ms
4,380 KB
testcase_34 WA -
testcase_35 AC 1 ms
4,372 KB
testcase_36 AC 1 ms
4,372 KB
testcase_37 AC 2 ms
4,372 KB
testcase_38 WA -
testcase_39 AC 55 ms
4,436 KB
testcase_40 AC 48 ms
4,440 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 53 ms
4,504 KB
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  int X = N / 2;
  vector<int> P;
  for (int i = 0; i < N; i++){
    if (A[i] <= X){
      P.push_back(i);
    }
  }
  if (N % 2 == 1){
    long long Y = 0;
    for (int i = 0; i < N / 2; i++){
      Y += abs(P[i] - (i * 2 + 1));
    }
    cout << X << ' ' << Y << endl;
  } else {
    vector<long long> L(N / 2 + 1);
    L[0] = 0;
    for (int i = 0; i < N / 2; i++){
      L[i + 1] = L[i] + abs(P[i] - (i * 2 + 1));
    }
    vector<long long> R(N / 2 + 1);
    R[N / 2] = 0;
    for (int i = N / 2 - 1; i >= 0; i--){
      R[i] = R[i + 1] + abs(P[i] - i * 2);
    }
    //?
    cout << X << ' ' << min(L[N / 2], R[N / 2]) << endl;
  }
}
0