# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1109877 |
2024-11-08T01:57:32 Z |
juliany2 |
Sirni (COCI17_sirni) |
C++17 |
|
126 ms |
300160 KB |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
struct DSU {
vector<int> e;
DSU(int sz) { e = vector<int> (sz + 1, -1); }
int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
bool unite(int u, int v) {
u = get(u), v = get(v);
if (u == v) return false;
if (e[v] < e[u]) swap(u, v);
e[u] += e[v], e[v] = u;
return true;
}
};
const int M = 1e7 + 7;
int n;
int nxt[M];
vector<array<int, 2>> e[M];
int main() {
cin.tie(0)->sync_with_stdio(false);
memset(nxt, -1, sizeof(nxt));
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();
for (int i = 0; i < n; i++) {
nxt[a[i]] = i;
}
for (int i = M - 2; i >= 0; i--) {
if (nxt[i] == -1)
nxt[i] = nxt[i + 1];
}
for (int i = 0; i < n; i++) {
vector<int> l;
if (~nxt[i + 1])
l.push_back(nxt[i + 1]);
for (int j = a[i] * 2; j < M; j += a[i]) {
if (nxt[j] == -1)
break;
l.push_back(nxt[j]);
}
l.erase(unique(all(l)), l.end());
for (int j : l) {
e[a[j] % a[i]].push_back({i, j});
}
}
DSU dsu(n);
ll ans = 0;
for (int i = 0; i < M; i++) {
for (auto &[u, v] : e[i]) {
if (dsu.unite(u, v)) {
ans += i;
}
}
if (-dsu.e[dsu.get(1)] == n)
break;
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
52 ms |
274448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
274472 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
274356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
100 ms |
285448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
275892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
126 ms |
300160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
278352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
115 ms |
287656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
115 ms |
287484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
276808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |