結果
| 問題 |
No.1900 Don't be Powers of 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-24 22:40:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 374 ms / 2,000 ms |
| コード長 | 769 bytes |
| コンパイル時間 | 1,053 ms |
| コンパイル使用メモリ | 89,640 KB |
| 最終ジャッジ日時 | 2025-01-28 01:37:54 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
ソースコード
#include <atcoder/maxflow>
#include <iostream>
using namespace std;
using namespace atcoder;
int popcount(int a) {
if (a == 0) return 0;
return popcount(a / 2) + a % 2;
}
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
mf_graph<int> g(n + 2);
int s = n;
int t = n + 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (popcount(a[i]) % 2 == 0 && popcount(a[j]) % 2 == 1 && popcount(a[i] ^ a[j]) ==1) {
g.add_edge(i, j, 1);
}
}
}
for (int i = 0; i < n; ++i) if (popcount(a[i]) % 2 == 0) g.add_edge(s, i, 1);
for (int i = 0; i < n; ++i) if (popcount(a[i]) % 2 == 1) g.add_edge(i, t, 1);
cout << n-g.flow(s, t) << endl;
return 0;
}