結果

問題 No.2029 Swap Min Max Min
ユーザー Iván SotoIván Soto
提出日時 2022-08-06 00:29:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,353 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 204,064 KB
実行使用メモリ 5,924 KB
最終ジャッジ日時 2023-10-14 02:47:36
合計ジャッジ時間 4,947 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 13 ms
4,556 KB
testcase_04 AC 4 ms
4,352 KB
testcase_05 AC 8 ms
4,352 KB
testcase_06 AC 14 ms
4,348 KB
testcase_07 AC 15 ms
5,004 KB
testcase_08 AC 20 ms
5,496 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 6 ms
4,352 KB
testcase_11 AC 8 ms
4,348 KB
testcase_12 AC 10 ms
4,352 KB
testcase_13 AC 21 ms
5,496 KB
testcase_14 AC 21 ms
4,424 KB
testcase_15 AC 22 ms
5,864 KB
testcase_16 AC 20 ms
4,420 KB
testcase_17 AC 21 ms
5,756 KB
testcase_18 AC 23 ms
5,848 KB
testcase_19 AC 20 ms
4,452 KB
testcase_20 AC 21 ms
4,436 KB
testcase_21 AC 20 ms
4,432 KB
testcase_22 AC 20 ms
4,400 KB
testcase_23 WA -
testcase_24 AC 22 ms
5,924 KB
testcase_25 AC 20 ms
4,436 KB
testcase_26 AC 20 ms
4,636 KB
testcase_27 WA -
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 1 ms
4,352 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 WA -
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 20 ms
4,356 KB
testcase_40 AC 18 ms
4,360 KB
testcase_41 AC 20 ms
5,504 KB
testcase_42 AC 21 ms
5,552 KB
testcase_43 AC 19 ms
4,476 KB
testcase_44 AC 22 ms
5,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <algo/debug.h>
#else
#define debug(...) 42
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> pos;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] <= n / 2) {
      pos.push_back(i);
    }
  }
  long long ans = 0;
  if (n % 2 == 1) {
    int p = 1;
    for (int i = 0; i < (int) pos.size(); i++) {
      ans += abs(pos[i] - p);
      p += 2;
    }
  } else {
    debug(pos);
    for (int s = 0; s < 2; s++) {
      int p = s;
      ans = (long long) 1e18;
      long long res = 0;
      for (int i = 0; i < (int) pos.size(); i++) {
        res += abs(pos[i] - p);
        p += 2;
      }
      ans = min(ans, res);
    }
    vector<long long> l((int) pos.size()), r((int) pos.size());
    {
      int p = 1;
      for (int i = 0; i < (int) pos.size(); i++) {
        l[i] = (i - 1 < 0 ? 0 : l[i - 1]) + abs(pos[i] - p);
        p += 2;
      }
    }
    {
      int p = n - 2;
      for (int i = (int) pos.size() - 1; i >= 0; i--) {
        r[i] = (i + 1 < (int) pos.size() ? r[i + 1] : 0) + abs(pos[i] - p);
        p -= 2;
      }
    }
    for (int i = 0; i < (int) pos.size() - 1; i++) {
      ans = min(ans, l[i] + r[i + 1]);
    }
  }
  cout << n / 2 << ' ' << ans << '\n';
  return 0;
}
0