結果

問題 No.2669 Generalized Hitting Set
ユーザー suisensuisen
提出日時 2024-01-16 20:49:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,993 ms / 4,000 ms
コード長 2,218 bytes
コンパイル時間 3,685 ms
コンパイル使用メモリ 77,636 KB
実行使用メモリ 138,604 KB
最終ジャッジ日時 2024-01-16 21:01:54
合計ジャッジ時間 38,935 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
57,948 KB
testcase_01 AC 128 ms
57,572 KB
testcase_02 AC 131 ms
57,696 KB
testcase_03 AC 676 ms
69,556 KB
testcase_04 AC 624 ms
66,416 KB
testcase_05 AC 549 ms
65,140 KB
testcase_06 AC 770 ms
69,488 KB
testcase_07 AC 335 ms
62,740 KB
testcase_08 AC 411 ms
63,132 KB
testcase_09 AC 749 ms
67,900 KB
testcase_10 AC 580 ms
62,968 KB
testcase_11 AC 368 ms
63,092 KB
testcase_12 AC 834 ms
69,908 KB
testcase_13 AC 833 ms
127,316 KB
testcase_14 AC 256 ms
65,044 KB
testcase_15 AC 161 ms
58,040 KB
testcase_16 AC 219 ms
60,560 KB
testcase_17 AC 254 ms
65,068 KB
testcase_18 AC 132 ms
57,832 KB
testcase_19 AC 216 ms
58,540 KB
testcase_20 AC 131 ms
57,556 KB
testcase_21 AC 203 ms
60,544 KB
testcase_22 AC 188 ms
58,348 KB
testcase_23 AC 1,111 ms
70,136 KB
testcase_24 AC 922 ms
70,220 KB
testcase_25 AC 1,184 ms
72,004 KB
testcase_26 AC 1,774 ms
138,372 KB
testcase_27 AC 802 ms
67,760 KB
testcase_28 AC 1,946 ms
136,204 KB
testcase_29 AC 1,993 ms
138,604 KB
testcase_30 AC 1,934 ms
138,480 KB
testcase_31 AC 1,923 ms
135,968 KB
testcase_32 AC 1,927 ms
138,516 KB
testcase_33 AC 1,120 ms
71,584 KB
testcase_34 AC 1,052 ms
71,108 KB
testcase_35 AC 1,342 ms
86,728 KB
testcase_36 AC 130 ms
57,660 KB
testcase_37 AC 234 ms
62,660 KB
testcase_38 AC 174 ms
58,340 KB
testcase_39 AC 1,875 ms
138,468 KB
testcase_40 AC 1,928 ms
136,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final int MAX_N = 24;
    static final int MAX_HALF_N = (MAX_N + 1) / 2;
    static final int MASK_HALF_N = (1 << MAX_HALF_N) - 1;
    public static void main(String[] args) {
        var sc = new Scanner(System.in);
        final int n = Integer.parseInt(sc.next());
        final int m = Integer.parseInt(sc.next());
        final int k = Integer.parseInt(sc.next());
        var f = new int[1 << n];
        for (int i = 0; i < m; ++i) {
            var s = sc.next();
            int x = 0;
            for (int j = 0; j < n; ++j) {
                x |= (s.charAt(j) - '0') << j;
            }
            ++f[x];
        }
        sc.close();

        var binom = new int[n + 1][n + 1];
        for (int i = 0; i <= n; ++i) {
            binom[i][0] = 1;
            for (int j = 1; j <= i; ++j) binom[i][j] = binom[i - 1][j - 1] + binom[i - 1][j];
        }
        var a = new int[n + 1];
        for (int l = k; l <= n; ++l) {
            a[l] = 1;
            for (int i = k; i < l; ++i) a[l] -= a[i] * binom[l][i];
        }

        for (int b = 1; b < 1 << n; b *= 2) for (int l = 0; l < 1 << n; l += 2 * b) for (int p = l; p < l + b; ++p) {
            f[p] += f[b + p];
        }
        var popc = new int[1 << MAX_HALF_N];
        for (int i = 1; i < 1 << MAX_HALF_N; ++i) {
            popc[i] = 1 + popc[i & (i - 1)];
        }
        for (int i = 0; i < 1 << n; ++i) {
            f[i] *= a[popc[i & MASK_HALF_N] + popc[i >> MAX_HALF_N]];
        }
        for (int b = 1; b < 1 << n; b *= 2) for (int l = 0; l < 1 << n; l += 2 * b) for (int p = l; p < l + b; ++p) {
            f[b + p] += f[p];
        }
        
        var g = new int[m + 1];
        Arrays.fill(g, n);
        for (int t = 0; t < 1 << n; ++t) {
            g[f[t]] = Math.min(g[f[t]], popc[t & MASK_HALF_N] + popc[t >> MAX_HALF_N]);
        }
        for (int p = m - 1; p >= 0; --p) {
            g[p] = Math.min(g[p], g[p + 1]);
        }
        var pw = new PrintWriter(System.out);
        for (int p = 1; p <= m; ++p) {
            pw.println(g[p]);
        }
        pw.flush();
        pw.close();
    }
}
0