結果

問題 No.1463 Hungry Kanten
ユーザー eQeeQe
提出日時 2021-04-02 22:09:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,554 bytes
コンパイル時間 4,499 ms
コンパイル使用メモリ 243,224 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-25 15:00:57
合計ジャッジ時間 7,705 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 1 ms
4,376 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 10 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define itr(x,c) for(auto x=c.begin();x!=c.end();x++)
#define ritr(x,c) for(auto x=c.rbegin();x!=c.rend();x++)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
using namespace std;
#include <atcoder/all>
using namespace atcoder;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const double PI=acos(-1);
static const double eps=1e-10;
//static const ll MOD=998244353;
//for(i=0;i<N;i++)cin>>a[i];

typedef vector<ll> v1d;
typedef vector<v1d> v2d;
typedef vector<v2d> v3d;
typedef vector<v3d> v4d;

v1d eratos(ll N) {
  v1d primes;
  v1d isp(N+5,1);
  isp[0]=isp[1]=0;
  ll i,j;
  
  for(i=2; i*i<=N; i++) {
    if(isp[i]==0) continue;
    for(j=i+i; j<=N; j+=i)
      isp[j]=0;
  }
  
  for(i=0; i<=N; i++)
    if(isp[i]) primes.push_back(i);
    
  return primes;
}

template <typename T>
struct PrimeFact {
  vector<T> spf;
  PrimeFact(T N) { init(N); }
  void init(T N) { // 前処理。spf を求める
    spf.assign(N + 1, 0);
    for (T i = 0; i <= N; i++) spf[i] = i;
    for (T i = 2; i * i <= N; i++) {
      if (spf[i] != i) continue;
      
      for (T j = i + i; j <= N; j += i) {
        spf[j] = i;
      }
    }
  }
  map<T, T> get(T n) { // nの素因数分解を求める
    map<T, T> m;
    while (n != 1) {
      m[spf[n]]++;
      n /= spf[n];
    }
    return m;
  }
};


int main(void) {
  ll i,j,k;
  /*
  ll N;cin>>N;
  v1d a(N);
  for(i=0;i<N;i++)cin>>a[i];
  */
  
  v1d pri=eratos(1000);
  map<ll,ll> dic;
  i=0;
  for(auto p:pri){
    dic[p]=i;i++;
  }
  
  
  PrimeFact<ll> pf(1000);
  
  ll N,K;cin>>N>>K;
  v1d a(N);
  v2d f(N,v1d(pri.size(),0));
  for(i=0;i<N;i++){
    cin>>a[i];
    map<ll,ll> mp=pf.get(a[i]);
    itr(it,mp) f[i][dic[it->first]]=it->second;
  }
  
  
  set<v1d> st;
  
  for(ll S=0;S<1<<N;S++){
    
    if(__builtin_popcountll(S)<K) continue;
    
    ll t=0;
    for(i=0;i<N;i++) if(S>>i&1)t+=a[i];
    
    map<ll,ll> mp=pf.get(t);
    v1d v(pri.size(),0);
    itr(it,mp) v[dic[it->first]]=it->second;
    st.insert(v);
    
    v1d cnt(pri.size(),0);
    v1d u;
    for(i=0;i<N;i++)if(S>>i&1)u.push_back(i);
    for(auto c:u){
      for(auto p:pri){
        cnt[dic[p]]+=f[c][dic[p]];
      }
    }
    st.insert(cnt);
    
  }
  
  pt(st.size());
  
}
0