| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 891802 | cuman | Sirni (COCI17_sirni) | C++14 | 5099 ms | 566812 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
using i64 = long long;
#define rep(i,l,r) for (int i = (l); i <= (r); i++)
struct DSU {
vector<int> e;
void initSz(int n) {
e = vector<int>(n, -1);
}
int fr(int x) { return e[x] < 0 ? x : e[x] = fr(e[x]); }
bool unite(int x, int y) {
x = fr(x), y = fr(y);
if (x==y) return false;
if (e[x] > e[y]) swap(x,y);
e[x] += e[y];
e[y] = x;
return true;
}
};
signed main() {
int N; cin >> N;
vector<int> A(N);
for (int& i : A) cin >> i;
sort(all(A));
A.erase(unique(all(A)), A.end());
N = A.size();
int Largest = A.back();
vector<int> lb(Largest+1);
for (int i = 0; i <= Largest; i++) {
lb[i] = lower_bound(all(A), i) - A.begin();
}
vector<array<int,2>> edges;
for (int i = 0; i < N-1; i++) {
edges.push_back({i, i+1});
for (int at = 2 * A[i]; at <= Largest; at += A[i]) {
int j = lb[at];
if (j < N) {
edges.push_back({i, j});
}
}
}
sort(all(edges), [&](const array<int,2>& a, const array<int,2>& b) {
auto cost = [&](int i, int j) {
return min(A[i] % A[j], A[j] % A[i]);
};
return cost(a[0], a[1]) < cost(b[0], b[1]);
});
DSU dsu;
dsu.initSz(N);
long long res = 0;
for (int i = 0; i < edges.size(); i++) {
int u = edges[i][0];
int v = edges[i][1];
int w = A[v] % A[u];
res += w * dsu.unite(u, v);
}
cout << res;
return 0;
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
