結果

問題 No.1463 Hungry Kanten
ユーザー chocono2230chocono2230
提出日時 2021-04-02 21:52:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,219 ms / 2,000 ms
コード長 1,709 bytes
コンパイル時間 2,141 ms
コンパイル使用メモリ 218,152 KB
実行使用メモリ 252,220 KB
最終ジャッジ日時 2023-08-25 14:56:55
合計ジャッジ時間 5,777 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 25 ms
9,112 KB
testcase_03 AC 95 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1,219 ms
252,220 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 10 ms
5,636 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 35 ms
12,004 KB
testcase_17 AC 90 ms
20,560 KB
testcase_18 AC 31 ms
10,076 KB
testcase_19 AC 503 ms
99,740 KB
testcase_20 AC 692 ms
132,692 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

map<ll, ll> prime_factorization(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while(n >= a*a){
    if(n % a == 0){
      ans[a]++;
      n /= a;
    }else{
      a++;
    }
  }
  ans[n]++;

  return ans;
}

void dfs(vector<map<ll, ll>> &vm, vector<int> &a, int lv, int k, map<ll, ll> &now, int sn, set<map<ll, ll>> &se) {
  int n = vm.size();
  if(lv == n) {
    if(k > 0) return ;
    se.insert(now);
    se.insert(prime_factorization(sn));
    return ;
  }
  dfs(vm, a, lv+1, k, now, sn, se);
  for(auto p : vm.at(lv)) {
    if(p.first != 1) now[p.first] += p.second;
  }
  dfs(vm, a, lv+1, k-1, now, sn+a.at(lv), se);
  for(auto p : vm.at(lv)) {
    if(p.first == 1) continue;
    now[p.first] -= p.second;
    if(now[p.first] == 0) {
      now.erase(p.first);
    }
  }
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<map<ll, ll>> vm(n);
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  rep(i, n) {
    vm.at(i) = prime_factorization(a.at(i));
  }
  set<map<ll, ll>> se;
  map<ll, ll> now;
  dfs(vm, a, 0, k, now, 0, se);
  // for(auto mmp : se) {
  //   ll sum = 1;
  //   for(auto p : mmp) {
  //     sum *= p.first*p.second;
  //   }
  //   cerr << sum << endl;
  // }
  cout << se.size() << endl;
  return 0;
}
0