結果

問題 No.2669 Generalized Hitting Set
ユーザー suisensuisen
提出日時 2024-01-14 01:56:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,502 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 76,488 KB
実行使用メモリ 463,216 KB
最終ジャッジ日時 2024-01-16 20:55:12
合計ジャッジ時間 25,459 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 19 ms
6,676 KB
testcase_04 AC 17 ms
6,676 KB
testcase_05 AC 15 ms
6,676 KB
testcase_06 AC 25 ms
6,676 KB
testcase_07 AC 5 ms
6,676 KB
testcase_08 AC 7 ms
6,676 KB
testcase_09 AC 17 ms
6,676 KB
testcase_10 AC 10 ms
6,676 KB
testcase_11 AC 6 ms
6,676 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 48 ms
17,760 KB
testcase_17 AC 281 ms
61,560 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 RE -
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 26 ms
18,524 KB
testcase_22 AC 8 ms
8,280 KB
testcase_23 AC 49 ms
7,004 KB
testcase_24 AC 24 ms
6,676 KB
testcase_25 AC 79 ms
19,164 KB
testcase_26 MLE -
testcase_27 AC 29 ms
8,540 KB
testcase_28 MLE -
testcase_29 MLE -
testcase_30 MLE -
testcase_31 MLE -
testcase_32 MLE -
testcase_33 AC 49 ms
11,252 KB
testcase_34 RE -
testcase_35 RE -
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 82 ms
32,220 KB
testcase_38 AC 5 ms
6,676 KB
testcase_39 RE -
testcase_40 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 789428 KB for N = 24

#include <cassert>
#include <iostream>
#include <string>
#include <vector>

constexpr int MAX_N = 24;
constexpr int HALF = MAX_N / 2;

constexpr int MAX_SIZE = 7;

int res[1 << MAX_N][MAX_SIZE]{};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, m, k;
    std::cin >> n >> m >> k;

    for (int i = 0; i < m; ++i) {
        std::string S;
        std::cin >> S;
        int val = 0;
        for (int j = 0; j < n; ++j) val |= ((S[j] - '0') << j);
        ++res[val][0];
    }

    if (k <= HALF) {
        assert(k <= MAX_SIZE);
        /*
        [1,1]
        [1,x]
        */
        for (int B = 1; B < 1 << n; B <<= 1) {
            for (int L = 0; L < 1 << n; L += 2 * B) {
                for (int p = 0; p < B; ++p) {
                    int *u = res[L + p], *v = res[L + B + p];
                    for (int t = k; t--;) {
                        int tmp = u[t];
                        u[t] = tmp + v[t];
                        v[t] = tmp + (t ? v[t - 1] : 0);
                    }
                }
            }
        }

        std::vector<int> g(m + 1, n);
        for (int T = 0; T < 1 << n; ++T) {
            int T_size = __builtin_popcount(T);
            int f_T = m;
            for (int i = 0; i < k; ++i) f_T -= res[T][i];
            g[f_T] = std::min(g[f_T], T_size);
        }

        for (int i = m - 1; i >= 0; --i) g[i] = std::min(g[i], g[i + 1]);

        for (int i = 1; i <= m; ++i) std::cout << g[i] << '\n';
    } else {
        const int r = n - k + 1;
        assert(r <= MAX_SIZE);
        /*
        [x,x]
        [x,1]
        */
        for (int B = 1; B < 1 << n; B <<= 1) {
            for (int L = 0; L < 1 << n; L += 2 * B) {
                for (int p = 0; p < B; ++p) {
                    int *u = res[L + p], *v = res[L + B + p];
                    for (int t = r; t-- > 1;) {
                        u[t] = u[t - 1] + v[t - 1];
                        v[t] += u[t - 1];
                    }
                    u[0] = 0;
                }
            }
        }

        std::vector<int> g(m + 1, n);
        for (int T = 0; T < 1 << n; ++T) {
            int T_size = __builtin_popcount(T);
            int f_T = 0;
            for (int i = 0; i < r; ++i) f_T += res[T][i];
            g[f_T] = std::min(g[f_T], T_size);
        }

        for (int i = m - 1; i >= 0; --i) g[i] = std::min(g[i], g[i + 1]);

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