結果

問題 No.2669 Generalized Hitting Set
ユーザー 👑 NachiaNachia
提出日時 2024-03-08 23:23:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,433 ms / 4,000 ms
コード長 2,885 bytes
コンパイル時間 1,070 ms
コンパイル使用メモリ 102,696 KB
実行使用メモリ 136,824 KB
最終ジャッジ日時 2024-03-08 23:23:30
合計ジャッジ時間 18,220 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 19 ms
6,548 KB
testcase_04 AC 17 ms
6,548 KB
testcase_05 AC 17 ms
6,548 KB
testcase_06 AC 31 ms
6,548 KB
testcase_07 AC 6 ms
6,676 KB
testcase_08 AC 9 ms
6,676 KB
testcase_09 AC 18 ms
6,676 KB
testcase_10 AC 14 ms
6,676 KB
testcase_11 AC 7 ms
6,676 KB
testcase_12 AC 23 ms
6,676 KB
testcase_13 AC 1,292 ms
134,392 KB
testcase_14 AC 126 ms
19,700 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 30 ms
7,416 KB
testcase_17 AC 125 ms
19,704 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 16 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 30 ms
7,412 KB
testcase_22 AC 8 ms
6,676 KB
testcase_23 AC 73 ms
6,676 KB
testcase_24 AC 36 ms
6,676 KB
testcase_25 AC 77 ms
9,208 KB
testcase_26 AC 1,306 ms
134,776 KB
testcase_27 AC 32 ms
6,676 KB
testcase_28 AC 1,433 ms
136,824 KB
testcase_29 AC 1,427 ms
136,824 KB
testcase_30 AC 1,402 ms
136,824 KB
testcase_31 AC 1,419 ms
136,824 KB
testcase_32 AC 1,333 ms
136,824 KB
testcase_33 AC 60 ms
7,168 KB
testcase_34 AC 39 ms
6,676 KB
testcase_35 AC 348 ms
37,624 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 60 ms
11,512 KB
testcase_38 AC 5 ms
6,676 KB
testcase_39 AC 1,347 ms
136,824 KB
testcase_40 AC 1,373 ms
136,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <array>
#include <cmath>
#include <atcoder/modint>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(i64 i=0; i<(i64)(n); i++)
#define repr(i,n) for(i64 i=(i64)(n)-1; i>=0; i--)
const i64 INF = 1001001001001001001;
const char* yn(bool x){ return x ? "Yes" : "No"; }
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
template<typename A> using nega_queue = std::priority_queue<A,std::vector<A>,std::greater<A>>;
using Modint = atcoder::static_modint<998244353>;
using namespace std;

namespace nachia{

int Popcount(unsigned long long c) noexcept {
#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/257)) >> 56;
    return c;
#endif
}

// please ensure x != 0
int MsbIndex(unsigned long long x) noexcept {
#ifdef __GNUC__
    return 63 - __builtin_clzll(x);
#else
    using u64 = unsigned long long;
    int q = (x >> 32) ? 32 : 0;
    auto m = x >> q;
    constexpr u64 hi = 0x8888'8888;
    constexpr u64 mi = 0x1111'1111;
    m = (((m | ~(hi - (m & ~hi))) & hi) * mi) >> 35;
    m = (((m | ~(hi - (x & ~hi))) & hi) * mi) >> 31;
    q += (m & 0xf) << 2;
    q += 0x3333'3333'2222'1100 >> (((x >> q) & 0xf) << 2) & 0xf;
    return q;
#endif
}

// please ensure x != 0
int LsbIndex(unsigned long long x) noexcept {
#ifdef __GNUC__
    return __builtin_ctzll(x);
#else
    return MsbIndex(x & -x);
#endif
}

}


void testcase(){
    i64 N, M, K; cin >> N >> M >> K;
    vector<i64> A(1<<N);
    rep(i,M){
        string s; cin >> s;
        i64 q = 0; rep(i,N) if(s[i] == '1') q |= 1 << i;
        A[q]++;
    }
    rep(d,N) rep(i,1<<N) if(!((i>>d)&1)) A[i] += A[i|1<<d];
    vector<vector<i64>> C(N+1);
    rep(i,N+1) C[i].assign(i+1, 1);
    for(i64 n=1; n<=N; n++) for(i64 k=1; k<n; k++) C[n][k] = C[n-1][k-1] + C[n-1][k];
    rep(i,1<<N){
        i64 x = nachia::Popcount(i);
        if(x < K){ A[i] = 0; continue; }
        if((x - K) % 2 == 1) A[i] = -A[i];
        A[i] *= C[x-1][K-1];
    }
    rep(d,N) rep(i,1<<N) if(!((i>>d)&1)) A[i|1<<d] += A[i];
    vector<i64> Q(N+1);
    rep(i,1<<N){
        i64 x = nachia::Popcount(i);
        chmax(Q[x], A[i]);
    }
    vector<i64> ans(M+1, N);
    rep(i,N+1) chmin(ans[Q[i]], i);
    repr(i,M) chmin(ans[i], ans[i+1]);
    rep(i,M) cout << ans[i+1] << '\n';
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    #ifdef NACHIA
    int T; cin >> T; for(int t=0; t<T; T!=++t?(cout<<'\n'),0:0)
    #endif
    testcase();
    return 0;
}
0