結果

問題 No.1900 Don't be Powers of 2
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-04-08 21:32:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 2,980 bytes
コンパイル時間 953 ms
コンパイル使用メモリ 101,824 KB
実行使用メモリ 15,480 KB
最終ジャッジ日時 2023-08-19 00:12:42
合計ジャッジ時間 2,738 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,632 KB
testcase_01 AC 1 ms
7,696 KB
testcase_02 AC 2 ms
7,572 KB
testcase_03 AC 3 ms
7,672 KB
testcase_04 AC 3 ms
7,672 KB
testcase_05 AC 2 ms
7,688 KB
testcase_06 AC 3 ms
7,664 KB
testcase_07 AC 3 ms
7,660 KB
testcase_08 AC 3 ms
7,616 KB
testcase_09 AC 2 ms
7,672 KB
testcase_10 AC 1 ms
7,660 KB
testcase_11 AC 2 ms
7,732 KB
testcase_12 AC 3 ms
7,772 KB
testcase_13 AC 2 ms
7,636 KB
testcase_14 AC 3 ms
7,588 KB
testcase_15 AC 1 ms
5,592 KB
testcase_16 AC 1 ms
5,584 KB
testcase_17 AC 3 ms
7,732 KB
testcase_18 AC 2 ms
7,668 KB
testcase_19 AC 3 ms
7,676 KB
testcase_20 AC 3 ms
7,592 KB
testcase_21 AC 3 ms
7,808 KB
testcase_22 AC 2 ms
7,668 KB
testcase_23 AC 2 ms
5,528 KB
testcase_24 AC 2 ms
5,636 KB
testcase_25 AC 3 ms
5,608 KB
testcase_26 AC 13 ms
15,256 KB
testcase_27 AC 6 ms
12,308 KB
testcase_28 AC 3 ms
7,720 KB
testcase_29 AC 3 ms
7,704 KB
testcase_30 AC 2 ms
7,656 KB
testcase_31 AC 2 ms
5,644 KB
testcase_32 AC 2 ms
5,584 KB
testcase_33 AC 13 ms
15,480 KB
testcase_34 AC 11 ms
15,320 KB
testcase_35 AC 12 ms
15,300 KB
testcase_36 AC 10 ms
14,336 KB
testcase_37 AC 3 ms
7,716 KB
testcase_38 AC 5 ms
12,592 KB
testcase_39 AC 3 ms
12,116 KB
testcase_40 AC 4 ms
7,728 KB
testcase_41 AC 4 ms
7,664 KB
testcase_42 AC 2 ms
5,568 KB
testcase_43 AC 1 ms
5,584 KB
testcase_44 AC 2 ms
7,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


namespace BM {
constexpr int LIM_N0 = 2010;
constexpr int LIM_N1 = 2010;
constexpr int LIM_M = 1'000'010;
int n0, n1, m, as[LIM_M], bs[LIM_M];
int to[LIM_N0], fr[LIM_N1], tof;
int pt[LIM_N0 + 2], zu[LIM_M], used[LIM_N0], lev[LIM_N0], que[LIM_N0], *qb, *qe;
void init(int n0_, int n1_) {
  n0 = n0_; n1 = n1_; m = 0;
}
int ae(int u, int v) {
  as[m] = u; bs[m] = v; return m++;
}
int augment(int u) {
  used[u] = tof;
  for (int j = pt[u]; j < pt[u + 1]; ++j) {
    const int v = zu[j];
    const int w = fr[v];
    if (!~w || (used[w] != tof && lev[u] < lev[w] && augment(w))) {
      to[u] = v; fr[v] = u; return 1;
    }
  }
  return 0;
}
int run() {
  memset(pt, 0, (n0 + 2) * sizeof(int));
  for (int i = 0; i < m; ++i) ++pt[as[i] + 2];
  for (int u = 2; u <= n0; ++u) pt[u + 1] += pt[u];
  for (int i = 0; i < m; ++i) zu[pt[as[i] + 1]++] = bs[i];
  memset(to, ~0, n0 * sizeof(int));
  memset(fr, ~0, n1 * sizeof(int));
  memset(used, ~0, n0 * sizeof(int));
  for (tof = 0; ; ) {
    qb = qe = que; memset(lev, ~0, n0 * sizeof(int));
    for (int u = 0; u < n0; ++u) if (!~to[u]) lev[*qe++ = u] = 0;
    for (; qb != qe; ) {
      const int u = *qb++;
      for (int j = pt[u]; j < pt[u + 1]; ++j) {
        const int w = fr[zu[j]];
        if (~w && !~lev[w]) lev[*qe++ = w] = lev[u] + 1;
      }
    }
    int f = 0;
    for (int u = 0; u < n0; ++u) if (!~to[u]) f += augment(u);
    if (!f) return tof;
    tof += f;
  }
}
}  // namespace BM


int N;
vector<int> A;

int main() {
  for (; ~scanf("%d", &N); ) {
    A.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d", &A[i]);
    }
    
    vector<int> iss[2];
    for (int i = 0; i < N; ++i) {
      iss[__builtin_parity(A[i])].push_back(i);
    }
    const int n0 = iss[0].size();
    const int n1 = iss[1].size();
    BM::init(n0, n1);
    for (int u = 0; u < n0; ++u) for (int v = 0; v < n1; ++v) {
      const int b = A[iss[0][u]] ^ A[iss[1][v]];
      if (!(b & (b - 1))) {
        BM::ae(u, v);
      }
    }
    const int res = BM::run();
    printf("%d\n", N - res);
  }
  return 0;
}
0