結果

問題 No.2029 Swap Min Max Min
ユーザー そすうぽよそすうぽよ
提出日時 2022-08-05 21:48:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,906 bytes
コンパイル時間 2,024 ms
コンパイル使用メモリ 202,560 KB
実行使用メモリ 8,892 KB
最終ジャッジ日時 2023-10-14 00:08:10
合計ジャッジ時間 4,848 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,352 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 12 ms
5,692 KB
testcase_06 AC 21 ms
7,272 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 8 ms
4,964 KB
testcase_11 WA -
testcase_12 AC 15 ms
6,204 KB
testcase_13 WA -
testcase_14 AC 31 ms
8,520 KB
testcase_15 WA -
testcase_16 AC 30 ms
8,596 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 31 ms
8,628 KB
testcase_20 AC 31 ms
8,660 KB
testcase_21 AC 30 ms
8,588 KB
testcase_22 AC 30 ms
8,596 KB
testcase_23 AC 32 ms
8,808 KB
testcase_24 AC 33 ms
8,848 KB
testcase_25 AC 28 ms
8,892 KB
testcase_26 AC 28 ms
8,780 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 WA -
testcase_33 AC 3 ms
4,352 KB
testcase_34 AC 3 ms
4,388 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 30 ms
7,992 KB
testcase_39 AC 27 ms
8,520 KB
testcase_40 AC 24 ms
8,132 KB
testcase_41 AC 31 ms
8,356 KB
testcase_42 AC 31 ms
8,392 KB
testcase_43 AC 27 ms
8,268 KB
testcase_44 AC 34 ms
8,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <variant>

#define rep2(i, k, n) for (i64 i = (i64)(k); i < (i64)(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(x) begin(x), end(x)
#ifdef ENV_LOCAL
#define dump \
  if (1) cerr
#else
#define dump \
  if (0) cerr
#endif

using namespace std;
using namespace std::string_literals;

using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;

// using namespace harudake;

// Light version
using Data = int;
const int len = 1 << 18;

struct BIT {
  vector<Data> data;
  BIT() : data(len, 0) {}
  void update(int i, Data value) {
    for (; i < len; i |= i + 1) data[i] += value;
  }
  Data query(int i) {
    Data s = 0;
    for (; i >= 0; i = (i & i + 1) - 1) s += data[i];
    return s;
  }
};

i64 inv_num(const vi64& v) {
  i64 ans = 0;
  BIT bit;
  rep(i, size(v)) {
    ans += i - bit.query(v[i]);
    bit.update(v[i], 1);
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 n;
  cin >> n;
  vi64 a(n);
  rep(i, n) cin >> a[i];
  i64 ans_1 = n / 2;
  i64 count_small = 0, count_large = 0;
  vi64 selo(n), sole(n);
  bool ok_selo = true, ok_sole = true;
  rep(i, n) {
    if (a[i] <= ans_1) {
      selo[i] = count_small * 2;
      sole[i] = count_small * 2 + 1;
      if (sole[i] >= n) ok_sole = false;
      ++count_small;
    } else {
      selo[i] = count_large * 2 + 1;
      sole[i] = count_large * 2;
      if (selo[i] >= n) ok_selo = false;
      ++count_large;
    }
  }
  i64 ans_2 = n * n;
  if (ok_selo) {
    dump << "SELO ";
    for (auto&& e : selo) dump << e << " ";
    dump << endl;
    ans_2 = min(ans_2, inv_num(selo));
  }
  if (ok_sole) {
    dump << "SOLE ";
    for (auto&& e : sole) dump << e << " ";
    dump << endl;
    ans_2 = min(ans_2, inv_num(sole));
  }
  cout << ans_1 << " " << ans_2 << endl;
  return 0;
}
0