結果
問題 | No.1917 LCMST |
ユーザー | momohara |
提出日時 | 2022-04-29 23:17:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,894 bytes |
コンパイル時間 | 2,592 ms |
コンパイル使用メモリ | 221,888 KB |
実行使用メモリ | 258,028 KB |
最終ジャッジ日時 | 2024-06-29 05:03:14 |
合計ジャッジ時間 | 28,632 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 151 ms
108,504 KB |
testcase_01 | AC | 228 ms
129,540 KB |
testcase_02 | AC | 33 ms
67,180 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 84 ms
83,328 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 3,752 ms
257,896 KB |
testcase_30 | AC | 3,721 ms
258,028 KB |
testcase_31 | TLE | - |
testcase_32 | AC | 3,639 ms
258,024 KB |
testcase_33 | AC | 3,709 ms
258,028 KB |
testcase_34 | AC | 132 ms
74,104 KB |
testcase_35 | AC | 131 ms
74,116 KB |
testcase_36 | AC | 130 ms
74,076 KB |
testcase_37 | AC | 3,532 ms
242,756 KB |
testcase_38 | AC | 3,513 ms
234,164 KB |
testcase_39 | AC | 3,428 ms
228,360 KB |
testcase_40 | AC | 3,380 ms
225,048 KB |
testcase_41 | AC | 3,386 ms
222,340 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<ll, ll>; using tp = tuple<ll, ll, ll>; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; #define all(hoge) (hoge).begin(), (hoge).end() #define en '\n' #define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i) #define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i) #define REP(i, n) rep(i, 0, n) #define REP2(i, n) rep2(i, 0, n) constexpr long long INF = 1LL << 60; constexpr int INF_INT = 1 << 25; // constexpr long long MOD = (ll)1e9 + 7; constexpr long long MOD = 998244353LL; static const ld pi = 3.141592653589793L; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } //グラフ関連 struct Edge { int to, rev; ll cap; Edge(int _to, int _rev, ll _cap) : to(_to), rev(_rev), cap(_cap) {} }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) { G[from].push_back(Edge(to, (int)G[to].size(), cap)); if(revFlag) G[to].push_back(Edge(from, (int)G[from].size() - 1, revCap)); } class UnionFind { vector<int> data; int num; public: UnionFind(int size) : data(size, -1), num(size) {} bool unionSet(int x, int y) { x = root(x); y = root(y); if(x != y) { if(data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; num--; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } int numSet() { return num; } }; vector<ll> divisor(ll n) { vector<ll> ret; for(ll i = 1; i * i <= n; i++) { if(n % i == 0) { ret.push_back(i); if(i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); return ret; } void solve() { ll n; cin >> n; vec<ll> a(n); REP(i, n) { cin >> a[i]; } ll ma = 2020202; vec<ll> num(ma, 0); vvec<int> vs(ma); ll ans = 0; sort(all(a)); vec<ll> b; REP(i, n) { num[a[i]]++; if(num[a[i]] >= 2) { ans += a[i]; continue; } int k = b.size(); b.push_back(a[i]); for(int j = 1; j * a[i] < ma; j++) { vs[j * a[i]].push_back(k); } } UnionFind uni(b.size()); REP(i, ma) { if(vs[i].size() <= 1) continue; rep(j, 1, vs[i].size()) { if(uni.unionSet(vs[i][0], vs[i][j])) { ans += i; } } if(uni.size(0) == b.size()) break; } if(uni.size(0) != b.size()) { REP(i, b.size()) { auto d = divisor(b[i]); for(auto p : d) { if(vs[i].size()) if(uni.unionSet(i, vs[i][0])) ans += gcd(b[vs[i][0]], b[i]); } if(uni.unionSet(i, 0)) { ans += gcd(b[i], b[0]); } } } assert(uni.size(0) == b.size()); cout << ans << en; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // cout << fixed << setprecision(10); // ll t; // cin >> t; // REP(i, t - 1) { // solve(); // } solve(); return 0; }