結果

問題 No.1917 LCMST
ユーザー 沙耶花沙耶花
提出日時 2022-04-29 22:03:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 361 ms / 4,000 ms
コード長 1,213 bytes
コンパイル時間 4,461 ms
コンパイル使用メモリ 269,660 KB
実行使用メモリ 49,452 KB
最終ジャッジ日時 2023-09-11 13:15:15
合計ジャッジ時間 17,486 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
15,312 KB
testcase_01 AC 53 ms
15,168 KB
testcase_02 AC 53 ms
15,084 KB
testcase_03 AC 58 ms
15,572 KB
testcase_04 AC 55 ms
15,444 KB
testcase_05 AC 60 ms
15,628 KB
testcase_06 AC 59 ms
15,628 KB
testcase_07 AC 57 ms
15,556 KB
testcase_08 AC 52 ms
14,972 KB
testcase_09 AC 353 ms
48,176 KB
testcase_10 AC 361 ms
49,256 KB
testcase_11 AC 353 ms
33,580 KB
testcase_12 AC 331 ms
33,112 KB
testcase_13 AC 226 ms
23,904 KB
testcase_14 AC 340 ms
31,692 KB
testcase_15 AC 193 ms
20,872 KB
testcase_16 AC 228 ms
23,276 KB
testcase_17 AC 269 ms
32,604 KB
testcase_18 AC 290 ms
32,036 KB
testcase_19 AC 190 ms
20,216 KB
testcase_20 AC 176 ms
17,308 KB
testcase_21 AC 194 ms
20,656 KB
testcase_22 AC 175 ms
17,316 KB
testcase_23 AC 176 ms
17,312 KB
testcase_24 AC 192 ms
20,408 KB
testcase_25 AC 176 ms
17,124 KB
testcase_26 AC 181 ms
19,548 KB
testcase_27 AC 185 ms
20,412 KB
testcase_28 AC 188 ms
20,876 KB
testcase_29 AC 263 ms
47,996 KB
testcase_30 AC 266 ms
47,976 KB
testcase_31 AC 297 ms
48,556 KB
testcase_32 AC 320 ms
49,452 KB
testcase_33 AC 263 ms
47,924 KB
testcase_34 AC 152 ms
15,104 KB
testcase_35 AC 152 ms
15,044 KB
testcase_36 AC 152 ms
15,084 KB
testcase_37 AC 316 ms
48,860 KB
testcase_38 AC 313 ms
49,072 KB
testcase_39 AC 314 ms
49,020 KB
testcase_40 AC 320 ms
48,312 KB
testcase_41 AC 314 ms
49,048 KB
testcase_42 AC 337 ms
48,412 KB
testcase_43 AC 153 ms
15,696 KB
testcase_44 AC 154 ms
15,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

int main(){
	
	int N;
	cin>>N;
	vector<int> cnt(100001,0);
	rep(i,N){
		int A;
		scanf("%d",&A);
		cnt[A]++;
	}
	
	long long ans = 0;
	rep(i,cnt.size()){
		if(cnt[i]>1){
			long long t = cnt[i]-1;
			t *= i;
			ans += t;
		}
	}
	
	vector ds(100001,vector<int>());
	for(int i=1;i<=100000;i++){
		for(int j=i*2;j<=100000;j+=i){
			ds[j].push_back(i);
		}
	}
	
	vector<long long> mini(100001,Inf);
	for(int i=1;i<=100000;i++){
		for(int j=i;j<=100000;j+=i){
			if(cnt[j]>0){
				mini[i] = j;
				break;
			}
		}
	}
	dsu D(100001);
	vector<pair<long long,pair<int,int>>> E;
	rep(i,cnt.size()){
		if(cnt[i]>0){
			rep(j,ds[i].size()){
				int t = ds[i][j];
				if(mini[t]==Inf)continue;
				E.emplace_back(lcm(mini[t],i),make_pair(mini[t],i));
			}
		}
	}
	sort(E.begin(),E.end());
	//cout<<ans<<endl;
	rep(i,E.size()){
		long long Dc = E[i].first;
		int u = E[i].second.first;
		int v = E[i].second.second;
		if(D.same(u,v))continue;
		D.merge(u,v);
		ans += Dc;
	}
	cout<<ans<<endl;
	
    return 0;
}
0