結果

問題 No.1917 LCMST
ユーザー rabimearabimea
提出日時 2023-01-27 01:50:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,404 bytes
コンパイル時間 4,113 ms
コンパイル使用メモリ 208,464 KB
実行使用メモリ 56,900 KB
最終ジャッジ日時 2023-09-09 23:07:08
合計ジャッジ時間 20,194 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
16,580 KB
testcase_01 AC 52 ms
16,524 KB
testcase_02 AC 53 ms
16,496 KB
testcase_03 AC 57 ms
17,200 KB
testcase_04 AC 57 ms
17,108 KB
testcase_05 AC 58 ms
17,112 KB
testcase_06 AC 58 ms
17,236 KB
testcase_07 AC 57 ms
17,108 KB
testcase_08 AC 52 ms
16,484 KB
testcase_09 AC 373 ms
56,308 KB
testcase_10 AC 374 ms
56,664 KB
testcase_11 AC 385 ms
56,408 KB
testcase_12 AC 346 ms
39,212 KB
testcase_13 WA -
testcase_14 AC 367 ms
56,152 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 188 ms
21,728 KB
testcase_20 AC 170 ms
19,104 KB
testcase_21 AC 191 ms
21,860 KB
testcase_22 AC 171 ms
19,068 KB
testcase_23 AC 170 ms
19,036 KB
testcase_24 AC 190 ms
21,824 KB
testcase_25 AC 172 ms
19,532 KB
testcase_26 AC 178 ms
21,240 KB
testcase_27 AC 186 ms
21,692 KB
testcase_28 AC 189 ms
21,808 KB
testcase_29 AC 295 ms
56,700 KB
testcase_30 AC 293 ms
56,800 KB
testcase_31 AC 300 ms
56,740 KB
testcase_32 AC 327 ms
56,628 KB
testcase_33 AC 291 ms
56,628 KB
testcase_34 AC 141 ms
16,532 KB
testcase_35 AC 143 ms
16,496 KB
testcase_36 AC 143 ms
16,532 KB
testcase_37 AC 337 ms
56,720 KB
testcase_38 AC 334 ms
56,532 KB
testcase_39 AC 332 ms
56,588 KB
testcase_40 AC 333 ms
56,900 KB
testcase_41 AC 332 ms
56,796 KB
testcase_42 AC 350 ms
56,764 KB
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using pii = pair <int, int>;
//~ const ll mod = 998244353;
const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const int N = 1e5 + 11;
vi divs[N];
vi muls[N];

int a[N];

int p[N];
int find(int x) {
	if(p[x] == x) return x;
	return p[x] = find(p[x]);
}

struct edge {
	int u, v;
	ll w;
	bool operator <(const edge &e) const {
		return w < e.w;
	}
};

ll lcm(ll a, ll b) {
	return a / __gcd(a, b) * b;
}

int main() {
	ios :: sync_with_stdio(false);
	
	int n, m; cin >> n;
	
	ll ans = 0;
	for(int i = 1; i <= n; i ++) {
		int x; cin >> x;
		if(a[x]) ans += x;
		a[x] = 1;
	}
	
	for(int i = 1; i < N; i ++)
		for(int j = i; j < N; j += i) {
			divs[j].pb(i);
			if(a[j]) muls[i].pb(j);
		}
	for(int i = 1; i < N; i ++)
		if(muls[i].size()) sort(muls[i].begin(), muls[i].end());
	
	vector <edge> edges;
	for(int i = 1; i < N; i ++) if(a[i]) {
		for(int x : divs[i]) {
			if(muls[x].size())
				edges.pb({i, muls[x][0], lcm(i, muls[x][0])});
		}
	}
	
	sort(edges.begin(), edges.end());
	
	iota(p, p + N, 0);
	for(auto e : edges) {
		int u = e.u, v = e.v;
		u = find(u); v = find(v);
		if(u != v) {
			ans += e.w;
			p[u] = v;
		}
	}
	
	cout << ans << '\n';
}
0