結果

問題 No.1917 LCMST
ユーザー chineristACchineristAC
提出日時 2022-04-18 13:31:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,283 bytes
コンパイル時間 5,802 ms
コンパイル使用メモリ 226,964 KB
実行使用メモリ 814,516 KB
最終ジャッジ日時 2023-09-10 17:00:44
合計ジャッジ時間 12,797 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,088 KB
testcase_01 AC 5 ms
7,084 KB
testcase_02 AC 4 ms
7,012 KB
testcase_03 AC 90 ms
15,832 KB
testcase_04 AC 91 ms
15,976 KB
testcase_05 AC 93 ms
16,400 KB
testcase_06 AC 92 ms
15,668 KB
testcase_07 AC 91 ms
15,864 KB
testcase_08 AC 5 ms
7,016 KB
testcase_09 MLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 <atcoder/all>
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 append push_back
#define all(x) (x).begin(), (x).end()

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

ll lpow(int n,int k){
  ll res = 1;
  ll e = n;
  while (k){
    if (k&1){
      res *= e;
    }
    e = e * e;
    k >>= 1;
  }
  return res;
}




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

  int N;
  cin>>N;
  vec<int> cnt(1e6+1,0);
  int M = 1e6;
  rep(i,N){
      int a;
      cin>>a;
      cnt[a]++;
  }

  ll res = 0;
  vec<int> A;
  for (int i=1;i<=M;i++){
      if (cnt[i] > 1){
          res += i * (cnt[i]-1);
          cnt[i] = 1;
      }
      if (cnt[i]==0){continue;}
      A.append(i);
      for (int j=2*i;j<=M;j+=i){
          if (cnt[j]!=0){
              res += j * cnt[j];
              cnt[j] = 0;
          }
      }
  }

  int n  = A.size();
  vec<tuple<ll,int,int>> Edge;
  rep(i,n){
      rep(j,n){
          if (i < j){
              ll cost = lcm((ll)A[i],(ll)A[j]);
              Edge.append({cost,i,j});
          }
      }
  }
  sort(all(Edge));

  dsu uf(n);
  for (auto [c,u,v]:Edge){
      if (!uf.same(u,v)){
          res += c;
          uf.merge(u,v);
      }
  }

  cout<<res<<endl;
}
0