結果

問題 No.2669 Generalized Hitting Set
ユーザー chineristACchineristAC
提出日時 2024-01-24 22:28:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,352 ms / 4,000 ms
コード長 3,919 bytes
コンパイル時間 8,913 ms
コンパイル使用メモリ 276,536 KB
実行使用メモリ 70,640 KB
最終ジャッジ日時 2024-01-24 22:29:01
合計ジャッジ時間 29,328 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 184 ms
6,676 KB
testcase_04 AC 154 ms
6,676 KB
testcase_05 AC 128 ms
6,676 KB
testcase_06 AC 240 ms
6,676 KB
testcase_07 AC 35 ms
6,676 KB
testcase_08 AC 53 ms
6,676 KB
testcase_09 AC 156 ms
6,676 KB
testcase_10 AC 86 ms
6,676 KB
testcase_11 AC 38 ms
6,676 KB
testcase_12 AC 211 ms
6,676 KB
testcase_13 AC 866 ms
69,360 KB
testcase_14 AC 91 ms
12,016 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 23 ms
6,676 KB
testcase_17 AC 91 ms
12,016 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 12 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 24 ms
6,676 KB
testcase_22 AC 7 ms
6,676 KB
testcase_23 AC 360 ms
6,676 KB
testcase_24 AC 240 ms
6,676 KB
testcase_25 AC 335 ms
6,784 KB
testcase_26 AC 933 ms
69,616 KB
testcase_27 AC 178 ms
6,676 KB
testcase_28 AC 1,345 ms
70,640 KB
testcase_29 AC 1,339 ms
70,640 KB
testcase_30 AC 1,341 ms
70,640 KB
testcase_31 AC 1,352 ms
70,640 KB
testcase_32 AC 1,307 ms
70,640 KB
testcase_33 AC 314 ms
6,676 KB
testcase_34 AC 314 ms
6,676 KB
testcase_35 AC 487 ms
20,976 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 44 ms
7,920 KB
testcase_38 AC 4 ms
6,676 KB
testcase_39 AC 1,287 ms
70,640 KB
testcase_40 AC 1,289 ms
70,640 KB
権限があれば一括ダウンロードができます

ソースコード

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/modint>
#include "testlib.h"




using namespace std;
using namespace atcoder;

using mint = modint998244353;



#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;
}

ostream& operator<<(ostream& os, const mint& a){
	os << a.val();
	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;
}

const int M = 10000;
mint fact[M],finv[M],inverse[M];

void init_mint(){
  fact[0] = 1, fact[1] = 1;
  finv[0] = 1, finv[1] = 1;
  inverse[0] = 0, inverse[1] = 1;
  for (int n=2;n<M;n++){
    fact[n] = fact[n-1] * n;
    inverse[n] = (-inverse[998244353 % n]) * (998244353/n);
    finv[n] = finv[n-1] * inverse[n];
  }
}

mint comb(int n,int r){
  if (r==-1 && n==-1) return 1;
  if (r < 0 || n < r) return 0;
  return fact[n] * finv[r] * finv[n-r];
}

const int MIN_n = 1;
const int MAX_n = 24;
const int MIN_m = 1;
const int MAX_m = 300'000;



int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  init_mint();

  registerValidation();
  int n = inf.readInt(MIN_n,MAX_n);
  inf.readSpace();
  int m = inf.readInt(MIN_m,MAX_m);
  inf.readSpace();
  int k = inf.readInt(1,n);
  inf.readEoln();

  string mok = "[0-1]{";
  mok += to_string(n);
  mok += ",";
  mok += to_string(n);
  mok += "}";

  vec<mint> cnt(1<<n,0);

  rep(i,m){
	string S = inf.readToken(mok);
	inf.readEoln();
	int val = 0, S_popcnt = 0;
	rep(j,n){
		val = (val<<1) + (S[j] - '0');
		S_popcnt += S[j] - '0';
	}
	ensure(k <= S_popcnt);

	cnt[val]++;
  }

  inf.readEof();

  vec<mint> f(n+1,0);
  f[k] = 1;
  for (int i=k+1;i<=n;i++){
	f[i] = 1;
	for (int j=k;j<i;j++){
		f[i] -= comb(i,j) * f[j];
	}
  }
  

  for (int i=0;i<n;i++){
	int t = 1<<i;
	for (int S = 0;S < (1<<n);S++){
		if (S & t) cnt[S^t] += cnt[S];
	}
  }

  for (int S = 0;S < (1<<n);S++){
	cnt[S] *= f[__builtin_popcount(S)];
  }

  

  for (int i=0;i<n;i++){
	int t = 1<<i;
	for (int S = 0;S < (1<<n);S++){
		if (S & t) cnt[S] += cnt[S^t];
	}
  }

  vec<int> g(m+1,n+1);
  rep(S,1<<n){
	int p = cnt[S].val();
	chmin(g[p],__builtin_popcount(S));
  }

  for (int i=m-1;0<=i;i--){
	g[i] = min(g[i],g[i+1]);
  }

  for (int i=1;i<=m;i++){
	cout << g[i] << "\n";
  }






  

    
}
0