結果

問題 No.2669 Generalized Hitting Set
ユーザー suisensuisen
提出日時 2024-01-16 21:55:32
言語 Nim
(2.0.2)
結果
AC  
実行時間 2,339 ms / 4,000 ms
コード長 1,555 bytes
コンパイル時間 3,313 ms
コンパイル使用メモリ 65,728 KB
実行使用メモリ 137,320 KB
最終ジャッジ日時 2024-01-16 21:56:06
合計ジャッジ時間 31,719 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 311 ms
6,676 KB
testcase_04 AC 254 ms
6,676 KB
testcase_05 AC 213 ms
6,676 KB
testcase_06 AC 376 ms
6,676 KB
testcase_07 AC 52 ms
6,676 KB
testcase_08 AC 79 ms
6,676 KB
testcase_09 AC 238 ms
6,676 KB
testcase_10 AC 123 ms
6,676 KB
testcase_11 AC 56 ms
6,676 KB
testcase_12 AC 290 ms
6,676 KB
testcase_13 AC 1,795 ms
135,016 KB
testcase_14 AC 191 ms
19,432 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 46 ms
7,144 KB
testcase_17 AC 202 ms
19,432 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 23 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 45 ms
7,144 KB
testcase_22 AC 12 ms
6,676 KB
testcase_23 AC 433 ms
6,676 KB
testcase_24 AC 307 ms
6,676 KB
testcase_25 AC 430 ms
8,936 KB
testcase_26 AC 1,871 ms
135,272 KB
testcase_27 AC 223 ms
6,676 KB
testcase_28 AC 2,329 ms
137,320 KB
testcase_29 AC 2,339 ms
137,320 KB
testcase_30 AC 2,336 ms
137,320 KB
testcase_31 AC 2,328 ms
137,320 KB
testcase_32 AC 2,286 ms
137,320 KB
testcase_33 AC 392 ms
6,784 KB
testcase_34 AC 405 ms
6,676 KB
testcase_35 AC 752 ms
37,352 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 91 ms
11,240 KB
testcase_38 AC 7 ms
6,676 KB
testcase_39 AC 2,321 ms
137,320 KB
testcase_40 AC 2,289 ms
137,320 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(3, 8) Warning: imported and not used: 'algorithm' [UnusedImport]

ソースコード

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
var b1 = 1
while b1 < 1 shl n:
    for l in countup(0, (1 shl n) - 1, 2 * b1):
        for p in l ..< l + b1:
            f[p] += f[p + b1]
    b1 *= 2

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

var b2 = 1
while b2 < 1 shl n:
    for l in countup(0, (1 shl n) - 1, 2 * b2):
        for p in l ..< l + b2:
            f[p + b2] += f[p]
    b2 *= 2

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