結果
問題 |
No.1900 Don't be Powers of 2
|
ユーザー |
|
提出日時 | 2022-02-25 00:53:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 341 ms / 2,000 ms |
コード長 | 853 bytes |
コンパイル時間 | 1,393 ms |
コンパイル使用メモリ | 89,516 KB |
最終ジャッジ日時 | 2025-01-28 01:41:24 |
ジャッジサーバーID (参考情報) |
judge2 / 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; assert(1 <= n && n <= 2000); vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; assert(0 <= a[i] && a[i] < 1 << 30); } 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; }