結果

問題 No.1900 Don't be Powers of 2
ユーザー 👑 NachiaNachia
提出日時 2022-04-08 21:38:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,752 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 92,872 KB
実行使用メモリ 35,572 KB
最終ジャッジ日時 2023-08-19 00:18:12
合計ジャッジ時間 2,639 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 6 ms
4,384 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 4 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 59 ms
35,572 KB
testcase_27 AC 14 ms
8,568 KB
testcase_28 AC 6 ms
4,384 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 56 ms
35,368 KB
testcase_34 AC 55 ms
35,168 KB
testcase_35 AC 56 ms
35,240 KB
testcase_36 AC 47 ms
34,468 KB
testcase_37 AC 7 ms
4,380 KB
testcase_38 AC 16 ms
13,264 KB
testcase_39 AC 7 ms
6,616 KB
testcase_40 AC 6 ms
4,376 KB
testcase_41 AC 7 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


#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;
0