結果

問題 No.2669 Generalized Hitting Set
ユーザー chineristACchineristAC
提出日時 2023-12-30 23:15:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,716 bytes
コンパイル時間 2,323 ms
コンパイル使用メモリ 153,256 KB
実行使用メモリ 220,536 KB
最終ジャッジ日時 2024-01-16 20:53:57
合計ジャッジ時間 11,972 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 19 ms
6,676 KB
testcase_06 AC 35 ms
6,676 KB
testcase_07 AC 7 ms
6,676 KB
testcase_08 AC 9 ms
6,676 KB
testcase_09 AC 20 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 RE -
testcase_14 RE -
testcase_15 AC 5 ms
6,676 KB
testcase_16 AC 128 ms
51,064 KB
testcase_17 RE -
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 59 ms
28,532 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 129 ms
51,060 KB
testcase_22 AC 23 ms
15,220 KB
testcase_23 AC 53 ms
11,380 KB
testcase_24 AC 38 ms
6,676 KB
testcase_25 AC 166 ms
51,064 KB
testcase_26 RE -
testcase_27 AC 43 ms
15,224 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 94 ms
28,536 KB
testcase_34 AC 45 ms
6,960 KB
testcase_35 RE -
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 269 ms
97,400 KB
testcase_38 AC 11 ms
10,612 KB
testcase_39 RE -
testcase_40 RE -
権限があれば一括ダウンロードができます

ソースコード

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<<20][21];

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