結果
問題 | No.1917 LCMST |
ユーザー | SSRS |
提出日時 | 2022-04-29 22:07:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 442 ms / 4,000 ms |
コード長 | 1,438 bytes |
コンパイル時間 | 1,734 ms |
コンパイル使用メモリ | 181,084 KB |
実行使用メモリ | 42,616 KB |
最終ジャッジ日時 | 2024-06-29 03:36:32 |
合計ジャッジ時間 | 16,895 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
01_ | AC * 6 |
other | AC * 39 |
入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,812 KB |
testcase_01 | AC | 4 ms
6,940 KB |
testcase_02 | AC | 4 ms
6,940 KB |
testcase_03 | AC | 5 ms
6,944 KB |
testcase_04 | AC | 5 ms
6,940 KB |
testcase_05 | AC | 5 ms
6,944 KB |
testcase_06 | AC | 4 ms
6,944 KB |
testcase_07 | AC | 4 ms
6,940 KB |
testcase_08 | AC | 3 ms
6,940 KB |
testcase_09 | AC | 384 ms
26,232 KB |
testcase_10 | AC | 377 ms
24,700 KB |
testcase_11 | AC | 375 ms
24,960 KB |
testcase_12 | AC | 353 ms
24,560 KB |
testcase_13 | AC | 297 ms
16,636 KB |
testcase_14 | AC | 362 ms
24,764 KB |
testcase_15 | AC | 268 ms
12,572 KB |
testcase_16 | AC | 287 ms
16,888 KB |
testcase_17 | AC | 318 ms
24,568 KB |
testcase_18 | AC | 370 ms
24,812 KB |
testcase_19 | AC | 274 ms
13,600 KB |
testcase_20 | AC | 268 ms
9,928 KB |
testcase_21 | AC | 274 ms
12,696 KB |
testcase_22 | AC | 262 ms
9,804 KB |
testcase_23 | AC | 265 ms
9,740 KB |
testcase_24 | AC | 280 ms
13,340 KB |
testcase_25 | AC | 269 ms
9,796 KB |
testcase_26 | AC | 275 ms
9,808 KB |
testcase_27 | AC | 269 ms
12,892 KB |
testcase_28 | AC | 274 ms
11,868 KB |
testcase_29 | AC | 398 ms
42,060 KB |
testcase_30 | AC | 397 ms
41,096 KB |
testcase_31 | AC | 398 ms
40,884 KB |
testcase_32 | AC | 442 ms
41,124 KB |
testcase_33 | AC | 395 ms
42,616 KB |
testcase_34 | AC | 251 ms
7,916 KB |
testcase_35 | AC | 254 ms
7,872 KB |
testcase_36 | AC | 251 ms
7,876 KB |
testcase_37 | AC | 395 ms
41,436 KB |
testcase_38 | AC | 395 ms
42,004 KB |
testcase_39 | AC | 415 ms
42,368 KB |
testcase_40 | AC | 399 ms
41,716 KB |
testcase_41 | AC | 393 ms
41,200 KB |
testcase_42 | AC | 405 ms
41,056 KB |
testcase_43 | AC | 253 ms
8,116 KB |
testcase_44 | AC | 252 ms
8,124 KB |
ソースコード
#include <bits/stdc++.h>using namespace std;const int MAX = 100001;struct unionfind{vector<int> p;unionfind(int N){p = vector<int>(N, -1);}int root(int x){if (p[x] < 0){return x;} else {p[x] = root(p[x]);return p[x];}}bool same(int x, int y){return root(x) == root(y);}void unite(int x, int y){x = root(x);y = root(y);if (x != y){if (p[x] < p[y]){swap(x, y);}p[y] += p[x];p[x] = y;}}};int main(){int N;cin >> N;vector<int> A(N);for (int i = 0; i < N; i++){cin >> A[i];}vector<int> cnt(MAX, 0);for (int i = 0; i < N; i++){cnt[A[i]]++;}vector<tuple<long long, int, int>> E;for (int i = 1; i < MAX; i++){vector<int> p;for (int j = i; j < MAX; j += i){if (cnt[j] > 0){p.push_back(j);}}if (p.size() >= 2){int cnt2 = p.size();for (int j = 1; j < cnt2; j++){long long c = (long long) p[0] * p[j] / i;E.push_back(make_tuple(c, p[0], p[j]));}}}sort(E.begin(), E.end());int M = E.size();unionfind UF(MAX);long long ans = 0;for (int i = 0; i < M; i++){int u = get<1>(E[i]);int v = get<2>(E[i]);if (!UF.same(u, v)){UF.unite(u, v);ans += get<0>(E[i]);}}for (int i = 0; i < MAX; i++){if (cnt[i] >= 2){ans += (long long) i * (cnt[i] - 1);}}cout << ans << endl;}