結果
問題 | No.1917 LCMST |
ユーザー | momohara |
提出日時 | 2022-04-29 23:15:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,933 bytes |
コンパイル時間 | 2,602 ms |
コンパイル使用メモリ | 220,592 KB |
実行使用メモリ | 258,028 KB |
最終ジャッジ日時 | 2024-06-29 05:00:35 |
合計ジャッジ時間 | 75,233 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 137 ms
108,540 KB |
testcase_01 | AC | 214 ms
129,388 KB |
testcase_02 | AC | 30 ms
67,244 KB |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | AC | 76 ms
83,172 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | WA | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | WA | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | AC | 124 ms
74,160 KB |
testcase_35 | AC | 124 ms
74,172 KB |
testcase_36 | AC | 125 ms
74,240 KB |
testcase_37 | AC | 3,870 ms
242,820 KB |
testcase_38 | AC | 3,881 ms
234,160 KB |
testcase_39 | AC | 3,935 ms
228,356 KB |
testcase_40 | AC | 3,898 ms
225,044 KB |
testcase_41 | AC | 3,829 ms
222,084 KB |
testcase_42 | TLE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
ソースコード
#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(vs[i][0], i); } if(uni.size(i) == 1 and i != 0) { 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; }