結果

問題 No.2669 Generalized Hitting Set
ユーザー suisensuisen
提出日時 2024-01-16 20:51:46
言語 Nim
(2.0.2)
結果
AC  
実行時間 2,342 ms / 4,000 ms
コード長 1,496 bytes
コンパイル時間 5,260 ms
コンパイル使用メモリ 65,612 KB
実行使用メモリ 137,320 KB
最終ジャッジ日時 2024-01-16 21:01:56
合計ジャッジ時間 31,375 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 315 ms
6,676 KB
testcase_04 AC 251 ms
6,676 KB
testcase_05 AC 207 ms
6,676 KB
testcase_06 AC 371 ms
6,676 KB
testcase_07 AC 51 ms
6,676 KB
testcase_08 AC 78 ms
6,676 KB
testcase_09 AC 235 ms
6,676 KB
testcase_10 AC 122 ms
6,676 KB
testcase_11 AC 54 ms
6,676 KB
testcase_12 AC 288 ms
6,676 KB
testcase_13 AC 1,831 ms
135,016 KB
testcase_14 AC 205 ms
19,432 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 47 ms
7,144 KB
testcase_17 AC 205 ms
19,432 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 24 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 47 ms
7,144 KB
testcase_22 AC 12 ms
6,676 KB
testcase_23 AC 430 ms
6,676 KB
testcase_24 AC 301 ms
6,676 KB
testcase_25 AC 421 ms
8,936 KB
testcase_26 AC 1,903 ms
135,272 KB
testcase_27 AC 219 ms
6,676 KB
testcase_28 AC 2,342 ms
137,320 KB
testcase_29 AC 2,327 ms
137,320 KB
testcase_30 AC 2,336 ms
137,320 KB
testcase_31 AC 2,330 ms
137,320 KB
testcase_32 AC 2,315 ms
137,320 KB
testcase_33 AC 386 ms
6,784 KB
testcase_34 AC 401 ms
6,676 KB
testcase_35 AC 753 ms
37,352 KB
testcase_36 AC 1 ms
6,676 KB
testcase_37 AC 96 ms
11,240 KB
testcase_38 AC 7 ms
6,676 KB
testcase_39 AC 2,313 ms
137,320 KB
testcase_40 AC 2,315 ms
137,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils
import strutils
import algorithm

const N_MAX: int = 24
const HALF_N_MAX: int = (N_MAX + 1) div 2
const MASK_HALF_N_MAX = (1 shl HALF_N_MAX) - 1

var binom: array[N_MAX + 1, array[N_MAX + 1, int]]
for i in 0 .. N_MAX:
    binom[i][0] = 1
    for j in 1 .. i:
        binom[i][j] = binom[i - 1][j - 1] + binom[i - 1][j]

var popcnt: array[1 shl HALF_N_MAX, int]
for t in 1 ..< 1 shl HALF_N_MAX:
    popcnt[t] = 1 + popcnt[t and (t - 1)]

var n, m, k: int
var nmk = stdin.readLine.split.map parseInt
n = nmk[0]
m = nmk[1]
k = nmk[2]

var f = newSeq[int](1 shl n)

for i in 0 ..< m:
    # reversed, but it's ok
    let s = stdin.readLine
    var x = 0
    for j in 0 ..< n:
        x += int(s[j] == '1') shl j
    f[x] += 1

var a = newSeq[int](n + 1)
for l in k .. n:
    a[l] = binom[l - 1][l - k]
    if bool((l - k) and 1):
        a[l] = -a[l]

# supset zeta
proc supset_zeta(): void =
    var b = 1
    while b < 1 shl n:
        for l in countup(0, (1 shl n) - 1, 2 * b):
            for p in l ..< l + b:
                f[p] += f[p + b]
        b *= 2
supset_zeta()

for t in 0 ..< 1 shl n:
    f[t] *= a[popcnt[t shr HALF_N_MAX] + popcnt[t and MASK_HALF_N_MAX]]

# subset zeta

f.reverse
supset_zeta()
f.reverse

var g = newSeq[int](m + 1)
for i in 0 .. m:
    g[i] = n
for t in 0 ..< 1 shl n:
    g[f[t]] = min(g[f[t]], popcnt[t shr HALF_N_MAX] + popcnt[t and MASK_HALF_N_MAX])

for p in countdown(m - 1, 0):
    g[p] = min(g[p], g[p + 1])

for p in 1 .. m:
    echo g[p]
0