結果
問題 | No.2669 Generalized Hitting Set |
ユーザー | suisen |
提出日時 | 2024-01-14 02:35:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 5,829 bytes |
コンパイル時間 | 1,031 ms |
コンパイル使用メモリ | 82,648 KB |
実行使用メモリ | 492,560 KB |
最終ジャッジ日時 | 2024-09-28 02:41:12 |
合計ジャッジ時間 | 22,830 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 3 ms
6,944 KB |
testcase_03 | AC | 22 ms
12,048 KB |
testcase_04 | AC | 18 ms
10,676 KB |
testcase_05 | AC | 17 ms
9,768 KB |
testcase_06 | AC | 29 ms
13,524 KB |
testcase_07 | AC | 6 ms
6,940 KB |
testcase_08 | AC | 8 ms
6,940 KB |
testcase_09 | AC | 19 ms
10,316 KB |
testcase_10 | AC | 12 ms
7,980 KB |
testcase_11 | AC | 6 ms
6,940 KB |
testcase_12 | AC | 25 ms
11,528 KB |
testcase_13 | MLE | - |
testcase_14 | AC | 384 ms
62,812 KB |
testcase_15 | AC | 4 ms
6,940 KB |
testcase_16 | AC | 57 ms
20,180 KB |
testcase_17 | AC | 334 ms
62,824 KB |
testcase_18 | AC | 3 ms
6,944 KB |
testcase_19 | AC | 40 ms
12,640 KB |
testcase_20 | AC | 3 ms
7,520 KB |
testcase_21 | AC | 32 ms
20,632 KB |
testcase_22 | AC | 9 ms
9,956 KB |
testcase_23 | AC | 73 ms
29,080 KB |
testcase_24 | AC | 27 ms
11,700 KB |
testcase_25 | AC | 105 ms
38,512 KB |
testcase_26 | MLE | - |
testcase_27 | AC | 41 ms
18,260 KB |
testcase_28 | MLE | - |
testcase_29 | MLE | - |
testcase_30 | MLE | - |
testcase_31 | TLE | - |
testcase_32 | MLE | - |
testcase_33 | AC | 78 ms
31,928 KB |
testcase_34 | AC | 42 ms
13,844 KB |
testcase_35 | AC | 833 ms
135,700 KB |
testcase_36 | AC | 2 ms
6,940 KB |
testcase_37 | AC | 119 ms
36,136 KB |
testcase_38 | AC | 6 ms
6,944 KB |
testcase_39 | MLE | - |
testcase_40 | MLE | - |
ソースコード
#include <cassert> #include <iostream> #include <string> #include <vector> constexpr int MAX_N = 24; constexpr int HALF = MAX_N / 2; constexpr int MAX_SIZE = HALF; int res[1 << (MAX_N - 1)][MAX_SIZE]{}; int f[1 << MAX_N]{}; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m, k; std::cin >> n >> m >> k; std::vector<std::string> S(m); for (int i = 0; i < m; ++i) { std::cin >> S[i]; } if (n <= HALF) { for (const auto &s_str : S) { int s = 0; for (int i = 0; i < n; ++i) s |= (s_str[i] - '0') << i; ++res[s][0]; } /* [1,1] [1,x] */ for (int B = 1; B < 1 << n; B <<= 1) { for (int L = 0; L < 1 << n; L += 2 * B) { for (int p = 0; p < B; ++p) { int* u = res[L + p], * v = res[L + B + p]; for (int t = k; t--;) { int tmp = u[t]; u[t] = tmp + v[t]; v[t] = tmp + (t ? v[t - 1] : 0); } } } } std::vector<int> g(m + 1, n); for (int T = 0; T < 1 << n; ++T) { int T_size = __builtin_popcount(T); int f_T = m; for (int i = 0; i < k; ++i) f_T -= res[T][i]; g[f_T] = std::min(g[f_T], T_size); } for (int i = m - 1; i >= 0; --i) g[i] = std::min(g[i], g[i + 1]); for (int i = 1; i <= m; ++i) std::cout << g[i] << '\n'; return 0; } if (k <= HALF) { /* [1,1] [1,x] */ for (int i = 0; i < 1 << n; ++i) { f[i] = m; } for (int topbit : { 0, 1 }) { for (int i = 0; i < 1 << (n - 1); ++i) { for (int j = 0; j < HALF; ++j) res[i][j] = 0; } for (const auto &s_str : S) { int s = 0; for (int i = 0; i < n; ++i) s |= (s_str[i] - '0') << i; if ((s >> (n - 1)) == topbit) { ++res[s & ~(1 << (n - 1))][0]; } } for (int B = 1; B < 1 << (n - 1); B <<= 1) { for (int L = 0; L < 1 << (n - 1); L += 2 * B) { for (int p = 0; p < B; ++p) { int* u = res[L + p], * v = res[L + B + p]; for (int t = k; t--;) { int tmp = u[t]; u[t] = tmp + v[t]; v[t] = tmp + (t ? v[t - 1] : 0); } } } } if (topbit == 0) { for (int T = 0; T < 1 << n; ++T) { for (int i = 0; i < k; ++i) { f[T] -= res[T & ~(1 << (n - 1))][i]; } } } else { for (int T = 0; T < 1 << n; ++T) { if (T >> (n - 1)) { for (int i = 0; i < k - 1; ++i) { f[T] -= res[T & ~(1 << (n - 1))][i]; } } else { for (int i = 0; i < k; ++i) { f[T] -= res[T][i]; } } } } } std::vector<int> g(m + 1, n); for (int T = 0; T < 1 << n; ++T) { int T_size = __builtin_popcount(T); g[f[T]] = std::min(g[f[T]], T_size); } for (int i = m - 1; i >= 0; --i) g[i] = std::min(g[i], g[i + 1]); for (int i = 1; i <= m; ++i) std::cout << g[i] << '\n'; } else { const int r = n - k + 1; /* [x,x] [x,1] */ for (int topbit : { 0, 1 }) { for (int i = 0; i < 1 << (n - 1); ++i) { for (int j = 0; j < HALF; ++j) res[i][j] = 0; } for (const auto &s_str : S) { int s = 0; for (int i = 0; i < n; ++i) s |= (s_str[i] - '0') << i; if ((s >> (n - 1)) == topbit) { ++res[s & ~(1 << (n - 1))][0]; } } for (int B = 1; B < 1 << (n - 1); B <<= 1) { for (int L = 0; L < 1 << (n - 1); L += 2 * B) { for (int p = 0; p < B; ++p) { int* u = res[L + p], * v = res[L + B + p]; for (int t = r; t-- > 1;) { u[t] = u[t - 1] + v[t - 1]; v[t] += u[t - 1]; } u[0] = 0; } } } if (topbit == 0) { for (int T = 0; T < 1 << n; ++T) { for (int i = 0; i < r - 1; ++i) { f[T] += res[T & ~(1 << (n - 1))][i]; } } } else { for (int T = 0; T < 1 << n; ++T) { if (T >> (n - 1)) { for (int i = 0; i < r; ++i) { f[T] += res[T & ~(1 << (n - 1))][i]; } } else { for (int i = 0; i < r - 1; ++i) { f[T] += res[T][i]; } } } } } std::vector<int> g(m + 1, n); for (int T = 0; T < 1 << n; ++T) { int T_size = __builtin_popcount(T); g[f[T]] = std::min(g[f[T]], T_size); } for (int i = m - 1; i >= 0; --i) g[i] = std::min(g[i], g[i + 1]); for (int i = 1; i <= m; ++i) std::cout << g[i] << '\n'; } }