Submission #551571

#TimeUsernameProblemLanguageResultExecution timeMemory
551571chenwzSirni (COCI17_sirni)C++11
140 / 140
4989 ms395436 KiB
// [COCI2016-2017#6] Sirni #include <bits/stdc++.h> using namespace std; const int NN = 1e5 + 4; #define _for(i, a, b) for (int i = (a); i < (int)(b); ++i) int P[NN], pa[NN]; int find_set(int x) { return pa[x] == x ? x : pa[x] = find_set(pa[x]); } struct Edge { int u, v, w; bool operator<(const Edge& e) const { return w < e.w; } }; int main() { ios::sync_with_stdio(false), cin.tie(0); vector<Edge> es; int n; cin >> n; _for(i, 0, n) cin >> P[i], pa[i] = i; sort(P, P + n), n = unique(P, P + n) - P; long long ans = 0; _for(i, 0, n) for (int x = P[i], y = x; y <= P[n - 1]; y += x) { int k = lower_bound(P + i + 1, P + n, y) - P; if (k < n && P[k] / x == y / x) es.push_back({i, k, P[k] % x}); } sort(es.begin(), es.end()); for (const Edge& e : es) { int u = find_set(e.u), v = find_set(e.v); if (u != v) ans += e.w, pa[u] = v; } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...