結果

問題 No.3827 MST on LCM Graph
コンテスト
ユーザー okkuu
提出日時 2026-11-22 12:28:38
言語 C++23(gnu拡張gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,531 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,647 ms
コンパイル使用メモリ 499,292 KB
実行使用メモリ 70,956 KB
最終ジャッジ日時 2026-11-22 12:46:21
合計ジャッジ時間 11,830 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 24 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//*/
#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_cxx;
//using namespace __gnu_pbds;
//*
#include<atcoder/all>
using namespace atcoder;
using mint=modint998244353;
using Mint=modint1000000007;
//*/
using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using P=pair<int,int>;
using Pl=pair<ll,ll>;
constexpr int mod=998244353;
constexpr int Mod=1e9+7;
constexpr int inf=Mod;
constexpr ll linf=(ll)inf*inf;
constexpr int dx[]={1,0,0,-1},dy[]={0,1,-1,0};
constexpr int Dx[]={1,1,1,0,0,-1,-1,-1},Dy[]={1,0,-1,1,-1,1,0,-1};
struct initio{
	initio(){
		cin.tie(0)->sync_with_stdio(0);
		cout<<fixed<<setprecision(20);
	};
}iio;
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(a>b){
		a=b;
		return 1;
	}
	return 0;
}
int fl2(ll n){
	return 63-__builtin_clzll(n);
}
int main(){
	int n,a;
	cin>>n;
	int mx=200000;
	vector<int>cnt(mx+1);
	while(cin>>a)
		cnt[a]++;
	ll ans=0;
	for(int i=1;i<=mx;i++)
		if(cnt[i]>=2)
			ans+=(cnt[i]-1ll)*i;
	vector<pair<ll,P>>edges;
	for(int i=1;i<=mx;i++){
		int mn=0;
		for(int j=i;j<=mx;j+=i){
			if(cnt[j]==0)
				continue;
			if(mn==0)
				mn=j;
			else
				edges.push_back({lcm(mn,j),P(mn,j)});
		}
	}
	sort(edges.begin(),edges.end());
	dsu uf(mx+1);
	for(auto[c,p]:edges){
		auto[u,v]=p;
		if(uf.same(u,v))
			continue;
		uf.merge(u,v);
		ans+=c;
	}
	cout<<ans<<endl;
}
0