結果

問題 No.2669 Generalized Hitting Set
ユーザー suisensuisen
提出日時 2024-01-14 05:25:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,963 ms / 4,000 ms
コード長 1,921 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 77,860 KB
実行使用メモリ 216,460 KB
最終ジャッジ日時 2024-01-16 21:01:29
合計ジャッジ時間 37,488 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
57,716 KB
testcase_01 AC 126 ms
57,696 KB
testcase_02 AC 125 ms
57,712 KB
testcase_03 AC 658 ms
69,492 KB
testcase_04 AC 602 ms
66,808 KB
testcase_05 AC 539 ms
64,424 KB
testcase_06 AC 747 ms
69,452 KB
testcase_07 AC 300 ms
61,372 KB
testcase_08 AC 396 ms
62,832 KB
testcase_09 AC 739 ms
67,968 KB
testcase_10 AC 544 ms
63,796 KB
testcase_11 AC 359 ms
61,584 KB
testcase_12 AC 858 ms
68,464 KB
testcase_13 AC 844 ms
192,720 KB
testcase_14 AC 249 ms
77,824 KB
testcase_15 AC 156 ms
57,940 KB
testcase_16 AC 199 ms
62,604 KB
testcase_17 AC 252 ms
77,764 KB
testcase_18 AC 128 ms
57,696 KB
testcase_19 AC 203 ms
60,248 KB
testcase_20 AC 126 ms
57,564 KB
testcase_21 AC 192 ms
62,936 KB
testcase_22 AC 177 ms
58,192 KB
testcase_23 AC 1,107 ms
70,304 KB
testcase_24 AC 910 ms
70,372 KB
testcase_25 AC 1,169 ms
72,356 KB
testcase_26 AC 1,715 ms
204,244 KB
testcase_27 AC 850 ms
71,004 KB
testcase_28 AC 1,921 ms
216,416 KB
testcase_29 AC 1,963 ms
214,336 KB
testcase_30 AC 1,889 ms
213,068 KB
testcase_31 AC 1,929 ms
216,460 KB
testcase_32 AC 1,950 ms
216,348 KB
testcase_33 AC 1,061 ms
71,100 KB
testcase_34 AC 1,028 ms
70,528 KB
testcase_35 AC 1,305 ms
107,808 KB
testcase_36 AC 124 ms
57,572 KB
testcase_37 AC 209 ms
64,484 KB
testcase_38 AC 165 ms
58,144 KB
testcase_39 AC 1,837 ms
212,996 KB
testcase_40 AC 1,868 ms
213,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    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];
        }

        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 << n];
        for (int i = 0; i < 1 << n; ++i) {
            if (i != 0) popc[i] = 1 + popc[i & (i - 1)];
            f[i] *= a[popc[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[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]);
        }
        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