結果

問題 No.2669 Generalized Hitting Set
ユーザー 👑 ygussanyygussany
提出日時 2024-02-18 12:34:50
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,083 ms / 4,000 ms
コード長 1,651 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 32,768 KB
実行使用メモリ 157,812 KB
最終ジャッジ日時 2024-02-18 12:35:08
合計ジャッジ時間 16,894 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
138,996 KB
testcase_01 AC 33 ms
138,996 KB
testcase_02 AC 33 ms
138,996 KB
testcase_03 AC 64 ms
143,476 KB
testcase_04 AC 58 ms
143,476 KB
testcase_05 AC 56 ms
141,428 KB
testcase_06 AC 102 ms
143,476 KB
testcase_07 AC 39 ms
139,124 KB
testcase_08 AC 47 ms
139,252 KB
testcase_09 AC 58 ms
143,476 KB
testcase_10 AC 50 ms
141,428 KB
testcase_11 AC 41 ms
139,124 KB
testcase_12 AC 67 ms
143,476 KB
testcase_13 AC 986 ms
153,332 KB
testcase_14 AC 135 ms
141,044 KB
testcase_15 AC 33 ms
141,044 KB
testcase_16 AC 54 ms
141,044 KB
testcase_17 AC 131 ms
141,044 KB
testcase_18 AC 33 ms
138,996 KB
testcase_19 AC 45 ms
141,044 KB
testcase_20 AC 33 ms
138,996 KB
testcase_21 AC 56 ms
141,044 KB
testcase_22 AC 40 ms
141,044 KB
testcase_23 AC 112 ms
145,524 KB
testcase_24 AC 108 ms
143,476 KB
testcase_25 AC 122 ms
145,524 KB
testcase_26 AC 976 ms
153,588 KB
testcase_27 AC 71 ms
143,476 KB
testcase_28 AC 1,078 ms
157,812 KB
testcase_29 AC 1,074 ms
157,812 KB
testcase_30 AC 1,083 ms
157,812 KB
testcase_31 AC 1,056 ms
157,812 KB
testcase_32 AC 1,064 ms
157,812 KB
testcase_33 AC 102 ms
145,524 KB
testcase_34 AC 94 ms
145,524 KB
testcase_35 AC 299 ms
147,572 KB
testcase_36 AC 32 ms
138,996 KB
testcase_37 AC 79 ms
141,044 KB
testcase_38 AC 36 ms
141,044 KB
testcase_39 AC 1,062 ms
157,812 KB
testcase_40 AC 1,062 ms
157,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int bit[25] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216};
int comb[25][25];

void chmin(int *a, int b)
{
	if (*a > b) *a = b;
}

int main()
{
	int i, n, m, k;
	char S[300001][25];
	scanf("%d %d %d", &n, &m, &k);
	for (i = 1; i <= m; i++) scanf("%s", S[i]);
	
	char l[16777216];
	int j, x, num[16777216] = {};
	for (i = 1, comb[0][0] = 1; i <= n; i++) for (j = 1, comb[i][0] = 1, comb[i][i] = 1; j < i; j++) comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
	for (x = 1, j = 1, l[0] = 0; x < bit[n]; x++, j++) {
		for (i = 0; (x & bit[i]) == 0; i++) j--;
		l[x] = j;
	}
	for (i = 1; i <= m; i++) {
		for (j = 0, x = 0; j < n; j++) if (S[i][j] != '0') x |= bit[j];
		num[x]++;
	}
	for (i = 0; i < n; i++) {
		for (x = 0; x < bit[n]; x++) {
			if ((x & bit[i]) == 0) continue;
			num[x ^ bit[i]] += num[x];
		}
	}
	// for (x = 0; x < bit[n]; x++) printf("%d %d\n", x, num[x]);

	int sum[16777216] = {};
	for (x = 0; x < bit[n]; x++) {
		if (l[x] >= k) {
			if ((l[x] - k) % 2 == 0) sum[x] = num[x] * comb[l[x]-1][k-1];
			else sum[x] = -num[x] * comb[l[x]-1][k-1];
		}
	}
	for (i = 0; i < n; i++) {
		for (x = 0; x < bit[n]; x++) {
			if ((x & bit[i]) != 0) continue;
			sum[x ^ bit[i]] += sum[x];
		}
	}
	// for (x = 0; x < bit[n]; x++) printf("%d %d\n", x, sum[x]);
	
	int ans[300001];
	for (i = 1; i <= m; i++) ans[i] = n;
	for (x = 0; x < bit[n]; x++) chmin(&(ans[sum[x]]), l[x]);
	for (i = m - 1; i >= 1; i--) chmin(&(ans[i]), ans[i+1]);
	for (i = 1; i <= m; i++) printf("%d\n", ans[i]);
	fflush(stdout);
	return 0;
}
0