結果
| 問題 |
No.2669 Generalized Hitting Set
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-01-01 01:30:22 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 3,716 bytes |
| コンパイル時間 | 7,766 ms |
| コンパイル使用メモリ | 199,236 KB |
| 最終ジャッジ日時 | 2025-02-18 15:46:10 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 MLE * 1 -- * 27 |
ソースコード
// -fsanitize=undefined,
// #define _GLIBCXX_DEBUG
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <chrono>
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;
#define rep(i,n) for (int i=0;i<n;i+=1)
#define rrep(i,n) for (int i=n-1;i>-1;i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << " )\n";
template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<class T>
bool chmin(T &a, T b){
if (a>b){
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b){
if (a<b){
a = b;
return true;
}
return false;
}
template<class T>
T sum(vec<T> x){
T res=0;
for (auto e:x){
res += e;
}
return res;
}
template<class T>
void printv(vec<T> x){
for (auto e:x){
cout<<e<<" ";
}
cout<<endl;
}
template<class T,class U>
ostream& operator<<(ostream& os, const pair<T,U>& A){
os << "(" << A.first <<", " << A.second << ")";
return os;
}
template<class T>
ostream& operator<<(ostream& os, const set<T>& S){
os << "set{";
for (auto a:S){
os << a;
auto it = S.find(a);
it++;
if (it!=S.end()){
os << ", ";
}
}
os << "}";
return os;
}
template<class T>
ostream& operator<<(ostream& os, const vec<T>& A){
os << "[";
rep(i,A.size()){
os << A[i];
if (i!=A.size()-1){
os << ", ";
}
}
os << "]" ;
return os;
}
int res[1<<24][25];
void calc(int N,vec<int> freq){
rep(S,1<<N){
res[S][0] = freq[S];
}
for (int n=1;n<=N;n++){
int B = 1<<(n-1);
for (int L = 0; L < (1<<N); L += 2*B){
for (int S=L;S<L+B;S++){
for (int k=n;0<=k;k--){
int a = res[S][k], b = res[S^B][k];
res[S][k] += b;
res[S^B][k] = a;
if (k!=0){
res[S^B][k] += res[S^B][k-1];
}
}
}
}
}
}
vec<vec<int>> solve(int n,vec<int> freq){
/*
T in [0,2^n) に対して、 size(T & S)=kなるSに対するfreq[S]の総和
*/
vec<vec<int>> res(1<<n,vec<int>(n+1,0));
if (n == 0){
res[0][0] = freq[0];
return res;
}
vec<int> small = {freq.begin(),freq.begin()+(1<<(n-1))};
vec<int> big = {freq.begin()+(1<<(n-1)),freq.end()};
auto small_res = solve(n-1,small);
auto big_res = solve(n-1,big);
for (int S=0;S<(1<<(n-1));S++){
for (int k=0;k<=n-1;k++){
res[S][k] += small_res[S][k] + big_res[S][k];
res[S^(1<<(n-1))][k] += small_res[S][k];
res[S^(1<<(n-1))][k+1] += big_res[S][k];
}
}
return res;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n,m,k;
cin>>n>>m>>k;
vec<int> freq(1<<n,0);
rep(i,m){
string S;
cin>>S;
int val = 0;
rep(j,n){
if (S[j] == '1'){
val += (1<<j);
}
}
freq[val]++;
}
calc(n,freq);
vec<int> g(m+1,n);
for (int T=0;T<(1<<n);T++){
int T_size = 0;
rep(i,n){
if ((T>>i) & 1) T_size++;
}
int f_T = 0;
for (int i=k;i<=n;i++){
f_T += res[T][i];
}
chmin(g[f_T],T_size);
}
for (int i=m-1;0<=i;i--){
chmin(g[i],g[i+1]);
}
for (int i=1;i<=m;i++){
cout << g[i] << "\n";
}
}