結果

問題 No.1463 Hungry Kanten
ユーザー snow39snow39
提出日時 2021-04-02 21:58:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 621 ms / 2,000 ms
コード長 1,800 bytes
コンパイル時間 1,603 ms
コンパイル使用メモリ 129,156 KB
実行使用メモリ 56,064 KB
最終ジャッジ日時 2023-08-25 14:58:53
合計ジャッジ時間 4,268 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 19 ms
5,128 KB
testcase_03 AC 301 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 621 ms
56,064 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 6 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 19 ms
5,320 KB
testcase_17 AC 64 ms
8,404 KB
testcase_18 AC 17 ms
5,308 KB
testcase_19 AC 276 ms
26,520 KB
testcase_20 AC 374 ms
34,196 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

const int L=1e3;
const ll INF=1e9;

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

  int N,K;
  cin>>N>>K;
  vector<int> A(N);
  rep(i,N) cin>>A[i];

  sort(all(A));

  vector<int> isPrime(L+1,1);
  isPrime[0]=0;isPrime[1]=0;
  for(int i=2;i<=L;i++){
    if(isPrime[i]==0) continue;
    for(int j=2;i*j<=L;j++) isPrime[i*j]=0;
  }

  vector<int> primes;
  for(int i=2;i<=L;i++) if(isPrime[i]) primes.push_back(i);
  int V=primes.size();

  vector<vector<int>> pcnt(N);
  rep(i,N){
    rep(j,V){
      int value=A[i];
      while(value%primes[j]==0){
        pcnt[i].push_back(primes[j]);
        value/=primes[j];
      }
    }
  }

  map<int,int> mp;
  map<vector<int>,int> mulmp;

  for(int bit=0;bit<(1<<N);bit++){
    int sz=__builtin_popcount(bit);
    if(sz<K) continue;

    vector<int> v;
    rep(i,N) if(bit>>i&1) v.push_back(i);

    int sum=0;
    for(auto i:v) sum+=A[i];
    mp[sum]=1;

    ll value=1;
    bool over=false;
    for(auto i:v){
      value*=A[i];
      if(value>INF){
        over=true;
        break;
      }
    }
    if(over==false){
      mp[value]=1;
      continue;
    }

    vector<int> ps;
    for(auto i:v){
      for(auto n:pcnt[i]) ps.push_back(n);
    }
    sort(all(ps));
    mulmp[ps]=1;
  }

  int ans=mp.size()+mulmp.size();
  cout<<ans<<endl;

  return 0;
}
0