# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1106929 | 2024-10-31T09:18:14 Z | manhlinh1501 | Sirni (COCI17_sirni) | C++17 | 1318 ms | 764120 KB |
#include<bits/stdc++.h> using namespace std; using i64 = long long; template<class X, class Y> bool minimize(X &x, const Y &y) { if (x > y) { x = y; return true; } return false; } template<class X, class Y> bool maximize(X &x, const Y &y) { if (x < y) { x = y; return true; } return false; } using pii = pair<int, int>; const int MAXN = 1e7 + 5; namespace dsu { vector<int> lab; void init(int N) { lab.assign(N + 5, -1); } int root(int u) { if(lab[u] < 0) return u; return lab[u] = root(lab[u]); } bool is_same(int u, int v) { return root(u) == root(v); } bool join(int u, int v) { if(is_same(u, v)) return false; u = root(u); v = root(v); if(lab[u] > lab[v]) swap(u, v); lab[u] += lab[v]; lab[v] = u; return true; } } int N; int b[MAXN + 5]; vector<pii> edges[MAXN]; signed main() { #define task "code" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; vector<int> a(N + 1, 0); for(int i = 1; i <= N; i++) cin >> a[i]; sort(a.begin() + 1, a.end()); dsu::init(N); for(int i = 1; i <= N; i++) { int j = i; while(j < N and a[i] == a[j + 1]) { dsu::join(i, j); j++; } b[a[i]] = i; i = j; } for(int i = a[N]; i >= 1; i--) b[i] = (b[i] == 0 ? b[i + 1] : b[i]); for(int i = 1; i <= N; i++) { int j = i; while(j < N and a[i] == a[j + 1]) { dsu::join(i, j); j++; } dsu::join(i, j); if(b[a[i] + 1]) edges[a[b[a[i] + 1]] % a[i]].emplace_back(i, b[a[i] + 1]); for(int j = 2 * a[i]; j <= a[N]; j += a[i]) { if(b[j]) edges[a[b[j]] % a[i]].emplace_back(i, b[j]); } i = j; } i64 ans = 0; for(int i = 0; i < MAXN; i++) { for(auto [u, v] : edges[i]) if(dsu::join(u, v)) ans += i; } cout << ans; return (0 ^ 0); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 61 ms | 274512 KB | Output is correct |
2 | Correct | 128 ms | 303432 KB | Output is correct |
3 | Correct | 64 ms | 274632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 236624 KB | Output is correct |
2 | Correct | 919 ms | 670204 KB | Output is correct |
3 | Correct | 63 ms | 275188 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 60 ms | 274344 KB | Output is correct |
2 | Correct | 64 ms | 274248 KB | Output is correct |
3 | Correct | 60 ms | 274504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 87 ms | 251008 KB | Output is correct |
2 | Correct | 147 ms | 289020 KB | Output is correct |
3 | Correct | 110 ms | 263476 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 56 ms | 242504 KB | Output is correct |
2 | Correct | 121 ms | 264272 KB | Output is correct |
3 | Correct | 86 ms | 249792 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 118 ms | 267472 KB | Output is correct |
2 | Correct | 182 ms | 305540 KB | Output is correct |
3 | Correct | 113 ms | 262052 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 64 ms | 240092 KB | Output is correct |
2 | Correct | 186 ms | 300808 KB | Output is correct |
3 | Correct | 103 ms | 263264 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 113 ms | 287980 KB | Output is correct |
2 | Correct | 945 ms | 635616 KB | Output is correct |
3 | Correct | 118 ms | 290584 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 123 ms | 292316 KB | Output is correct |
2 | Correct | 1318 ms | 764120 KB | Output is correct |
3 | Correct | 245 ms | 350652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 276648 KB | Output is correct |
2 | Correct | 1137 ms | 636400 KB | Output is correct |
3 | Correct | 110 ms | 266600 KB | Output is correct |