結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー k
提出日時 2021-03-01 22:02:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 994 bytes
コンパイル時間 1,963 ms
コンパイル使用メモリ 196,232 KB
最終ジャッジ日時 2025-01-19 09:02:31
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

vector<int> g[61+100000];
int match[61+100000];
int used[61+100000];

void add_edge(int u, int v) {
  g[u].push_back(61+v);
  g[61+v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    int w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int ret = 0;
  memset(match, -1, sizeof(match));
  for (int v = 0; v <= 60; v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) {
        ++ret;
      }
    }
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    for (int j = 0; j <= 60; j++) {
      if (a & 1LL<<j)
        add_edge(j, i);
    }
  }

  cout << (1LL<<bipartite_matching()) << endl;
  
  return 0;
}
0