結果

問題 No.1917 LCMST
ユーザー rabimearabimea
提出日時 2023-01-27 01:09:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,438 bytes
コンパイル時間 3,418 ms
コンパイル使用メモリ 208,140 KB
実行使用メモリ 56,768 KB
最終ジャッジ日時 2023-09-09 22:32:46
合計ジャッジ時間 22,162 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
16,432 KB
testcase_01 AC 66 ms
16,520 KB
testcase_02 AC 65 ms
16,424 KB
testcase_03 AC 74 ms
17,120 KB
testcase_04 AC 79 ms
17,208 KB
testcase_05 AC 67 ms
17,120 KB
testcase_06 AC 73 ms
17,104 KB
testcase_07 AC 73 ms
17,064 KB
testcase_08 AC 69 ms
16,452 KB
testcase_09 AC 424 ms
56,412 KB
testcase_10 AC 434 ms
56,452 KB
testcase_11 AC 445 ms
56,444 KB
testcase_12 AC 408 ms
39,148 KB
testcase_13 WA -
testcase_14 AC 419 ms
55,956 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 209 ms
21,844 KB
testcase_20 AC 193 ms
19,016 KB
testcase_21 AC 227 ms
21,928 KB
testcase_22 AC 197 ms
19,100 KB
testcase_23 AC 197 ms
19,276 KB
testcase_24 AC 220 ms
21,664 KB
testcase_25 AC 199 ms
19,392 KB
testcase_26 AC 203 ms
21,276 KB
testcase_27 AC 204 ms
21,348 KB
testcase_28 AC 210 ms
21,564 KB
testcase_29 AC 345 ms
56,768 KB
testcase_30 AC 349 ms
56,540 KB
testcase_31 AC 335 ms
56,672 KB
testcase_32 AC 377 ms
56,528 KB
testcase_33 AC 346 ms
56,504 KB
testcase_34 AC 158 ms
16,528 KB
testcase_35 AC 159 ms
16,440 KB
testcase_36 AC 159 ms
16,452 KB
testcase_37 AC 395 ms
56,664 KB
testcase_38 AC 383 ms
56,556 KB
testcase_39 AC 385 ms
56,656 KB
testcase_40 AC 386 ms
56,624 KB
testcase_41 AC 372 ms
56,504 KB
testcase_42 AC 409 ms
56,556 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 ++)
		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) {
		//~ cout << e.u << ' ' << e.v << ' ' << e.w << '\n';
		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