結果

問題 No.2669 Generalized Hitting Set
ユーザー suisensuisen
提出日時 2023-09-21 02:12:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 658 ms / 4,000 ms
コード長 2,186 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 80,568 KB
実行使用メモリ 72,400 KB
最終ジャッジ日時 2024-01-16 20:53:06
合計ジャッジ時間 10,381 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 20 ms
6,676 KB
testcase_04 AC 17 ms
6,676 KB
testcase_05 AC 17 ms
6,676 KB
testcase_06 AC 26 ms
6,676 KB
testcase_07 AC 5 ms
6,676 KB
testcase_08 AC 7 ms
6,676 KB
testcase_09 AC 18 ms
6,676 KB
testcase_10 AC 11 ms
6,676 KB
testcase_11 AC 5 ms
6,676 KB
testcase_12 AC 23 ms
6,676 KB
testcase_13 AC 592 ms
68,860 KB
testcase_14 AC 57 ms
11,512 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 15 ms
6,676 KB
testcase_17 AC 56 ms
11,516 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 8 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 16 ms
6,676 KB
testcase_22 AC 6 ms
6,676 KB
testcase_23 AC 44 ms
6,676 KB
testcase_24 AC 25 ms
6,676 KB
testcase_25 AC 52 ms
8,064 KB
testcase_26 AC 594 ms
69,484 KB
testcase_27 AC 25 ms
6,676 KB
testcase_28 AC 632 ms
72,400 KB
testcase_29 AC 636 ms
72,400 KB
testcase_30 AC 643 ms
72,400 KB
testcase_31 AC 645 ms
72,400 KB
testcase_32 AC 627 ms
72,400 KB
testcase_33 AC 44 ms
7,040 KB
testcase_34 AC 33 ms
6,676 KB
testcase_35 AC 166 ms
21,980 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 29 ms
7,420 KB
testcase_38 AC 4 ms
6,676 KB
testcase_39 AC 630 ms
72,400 KB
testcase_40 AC 658 ms
72,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

template <typename T>
void supset_zeta(std::vector<T> &f) {
    const int n = f.size();
    for (int b = 1; b < n; b *= 2) for (int l = 0; l < n; l += 2 * b) for (int p = 0; p < b; ++p) {
        f[l + p] += f[l + b + p];
    }
}
template <typename T>
void subset_zeta(std::vector<T> &f) {
    const int n = f.size();
    for (int b = 1; b < n; b *= 2) for (int l = 0; l < n; l += 2 * b) for (int p = 0; p < b; ++p) {
        f[l + b + p] += f[l + p];
    }
}

using Int = uint;

std::vector<Int> calc_f(const size_t n, const size_t, const size_t k, const std::vector<uint>& s) {
    std::vector binom(n + 1, std::vector<Int>(n + 1));
    for (size_t i = 0; i <= n; ++i) {
        binom[i][0] = 1;
        for (size_t j = 1; j <= i; ++j) {
            binom[i][j] = binom[i - 1][j - 1] + binom[i - 1][j];
        }
    }

    std::vector<Int> a(n + 1);
    for (size_t l = k; l <= n; ++l) {
        a[l] = 1;
        for (size_t i = k; i < l; ++i) {
            a[l] -= a[i] * binom[l][i];
        }
    }

    std::vector<Int> f(1 << n);
    for (uint u : s) ++f[u];
    supset_zeta(f);
    for (uint t = 0; t < 1u << n; ++t) {
        if (size_t(__builtin_popcount(t)) < k) {
            f[t] = 0;
        } else {
            f[t] *= a[__builtin_popcount(t)];
        }
    }
    subset_zeta(f);
    return f;
}

std::vector<size_t> calc_g(const size_t n, const size_t m, const std::vector<Int> &f) {
    std::vector<size_t> g(m + 1, n + 1);
    for (uint t = 0; t < 1u << n; ++t) {
        g[f[t]] = std::min<size_t>(g[f[t]], __builtin_popcount(t));
    }
    for (size_t p = m; p; --p) {
        g[p - 1] = std::min(g[p - 1], g[p]);
    }
    return g;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    size_t n, m, k;
    std::cin >> n >> m >> k;

    std::vector<uint> s(m);
    for (size_t i = 0; i < m; ++i) {
        std::string si;
        std::cin >> si;
        for (size_t j = 0; j < n; ++j) {
            s[i] |= (si[j] - '0') << j;
        }
    }
    auto f = calc_f(n, m, k, s);
    auto g = calc_g(n, m, f);
    for (size_t p = 1; p <= m; ++p) {
        std::cout << g[p] << '\n';
    }
}
0