結果

問題 No.2669 Generalized Hitting Set
ユーザー suisensuisen
提出日時 2023-09-21 02:33:26
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,277 bytes
コンパイル時間 836 ms
コンパイル使用メモリ 83,628 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-28 02:31:13
合計ジャッジ時間 7,922 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

// WA: greedy (2)

#include <algorithm>
#include <iostream>
#include <vector>

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;
        }
    }

    std::vector<size_t> g(m + 1, n + 1);

    size_t prev_ok = 0;
    uint t = 0, ct = 0;
    while (prev_ok < m) {
        std::vector<std::pair<int, size_t>> hist(n);
        for (size_t i = 0; i < n; ++i) {
            hist[i] = { 0, i };
            if ((t >> i) & 1) hist[i].first = -1e9;
        }
        for (uint e : s) if (__builtin_popcount(t & e) < k) {
            for (size_t i = 0; i < n; ++i) if ((e >> i) & 1) ++hist[i].first;
        }

        t |= 1 << std::max_element(hist.begin(), hist.end())->second;
        ++ct;

        size_t ok = 0;
        for (uint e : s) ok += __builtin_popcount(t & e) >= k;
        if (ok > prev_ok) g[ok] = ct;
        prev_ok = ok;
    }

    for (size_t p = m; p; --p) {
        g[p - 1] = std::min(g[p - 1], g[p]);
    }

    for (size_t p = 1; p <= m; ++p) {
        std::cout << g[p] << '\n';
    }
}
0