結果

問題 No.2669 Generalized Hitting Set
ユーザー chineristACchineristAC
提出日時 2024-01-01 01:30:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 3,716 bytes
コンパイル時間 2,322 ms
コンパイル使用メモリ 153,268 KB
実行使用メモリ 811,896 KB
最終ジャッジ日時 2024-01-16 20:54:01
合計ジャッジ時間 5,022 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 22 ms
6,676 KB
testcase_04 AC 20 ms
6,676 KB
testcase_05 AC 18 ms
6,676 KB
testcase_06 AC 35 ms
6,676 KB
testcase_07 AC 7 ms
6,676 KB
testcase_08 AC 10 ms
6,676 KB
testcase_09 AC 21 ms
6,676 KB
testcase_10 AC 15 ms
6,676 KB
testcase_11 AC 8 ms
6,676 KB
testcase_12 AC 26 ms
6,676 KB
testcase_13 MLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// -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";
  }
  

  
}
0