結果
| 問題 |
No.1900 Don't be Powers of 2
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2022-04-08 21:38:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 73 ms / 2,000 ms |
| コード長 | 1,752 bytes |
| コンパイル時間 | 959 ms |
| コンパイル使用メモリ | 91,148 KB |
| 最終ジャッジ日時 | 2025-01-28 15:57:15 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
ソースコード
#include <vector>
#include <algorithm>
namespace nachia{
int popcount(unsigned long long c){
#ifdef __GNUC__
return __builtin_popcountll(c);
#else
c = (c & (~0ull/3)) + ((c >> 1) & (~0ull/3));
c = (c & (~0ull/5)) + ((c >> 2) & (~0ull/5));
c = (c & (~0ull/17)) + ((c >> 4) & (~0ull/17));
c = (c * (~0ull/255)) >> 56;
return c;
#endif
}
int msb_idx(unsigned long long x){
int res = 0;
for(int d=32; d>=0; d>>=1) if(x >> d){ res |= d; x >>= d; }
return res;
}
int lsb_idx(unsigned long long x){
return msb_idx(x & -x);
}
int upper_bound_idx(const std::vector<int>& A, int a){
return std::upper_bound(A.begin(), A.end(), a) - A.begin();
}
int lower_bound_idx(const std::vector<int>& A, int a){
return std::lower_bound(A.begin(), A.end(), a) - A.begin();
}
}
#include <iostream>
#include <atcoder/maxflow>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
int main(){
int N; cin >> N;
vector<int> A(N);
rep(i,N) cin >> A[i];
vector<int> B[2];
rep(i,N) B[nachia::popcount(A[i]) % 2].push_back(i);
atcoder::mf_graph<int> G(N + 2);
for(int i : B[0]) G.add_edge(N, i, 1);
for(int i : B[1]) G.add_edge(i, N+1, 1);
for(int i : B[0]) for(int j : B[1]) if(nachia::popcount(A[i] ^ A[j]) == 1) G.add_edge(i, j, 1);
int ans = G.flow(N, N+1);
cout << (N - ans) << '\n';
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia