# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
241006 | 2020-06-22T05:37:48 Z | SamAnd | Sirni (COCI17_sirni) | C++17 | 2922 ms | 785400 KB |
#include <bits/stdc++.h> using namespace std; #define m_p make_pair #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define fi first #define se second typedef long long ll; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 100005, M = 10000007; int n; int a[N]; int u[M], uu[M]; vector<pair<int, int> > v[M]; int p[N]; int fi(int x) { if (x == p[x]) return x; return p[x] = fi(p[x]); } void kpc(int x, int y) { x = fi(x); y = fi(y); p[x] = y; } void solv() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); u[a[i]] = i; } for (int i = M - 2; i >= 0; --i) { if (u[i]) { uu[i] = u[i]; } else { uu[i] = uu[i + 1]; } } for (int i = 1; i < M; ++i) { if (!u[i]) continue; v[a[uu[i + 1]] % i].push_back(m_p(u[i], uu[i + 1])); for (int j = i + i; j < M; j += i) { if (uu[j]) { v[a[uu[j]] % i].push_back(m_p(u[i], uu[j])); } } } for (int i = 1; i <= n; ++i) p[i] = i; int ans = 0; for (int i = 0; i < M; ++i) { for (int j = 0; j < v[i].size(); ++j) { int x = v[i][j].fi; int y = v[i][j].se; if (fi(x) != fi(y)) { kpc(x, y); ans += i; } } } printf("%d\n", ans); } int main() { #ifdef SOMETHING freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif // SOMETHING //ios_base::sync_with_stdio(false), cin.tie(0); solv(); return 0; } //while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 212 ms | 278136 KB | Output is correct |
2 | Correct | 336 ms | 305656 KB | Output is correct |
3 | Correct | 216 ms | 278520 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 257 ms | 274668 KB | Output is correct |
2 | Correct | 1848 ms | 670140 KB | Output is correct |
3 | Correct | 240 ms | 279032 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 210 ms | 278520 KB | Output is correct |
2 | Correct | 207 ms | 276856 KB | Output is correct |
3 | Correct | 209 ms | 278392 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 404 ms | 289316 KB | Output is correct |
2 | Correct | 775 ms | 317916 KB | Output is correct |
3 | Correct | 452 ms | 300380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 247 ms | 280440 KB | Output is correct |
2 | Correct | 619 ms | 301704 KB | Output is correct |
3 | Correct | 502 ms | 287632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 607 ms | 301268 KB | Output is correct |
2 | Correct | 1058 ms | 336688 KB | Output is correct |
3 | Correct | 468 ms | 299000 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 408 ms | 279364 KB | Output is correct |
2 | Correct | 996 ms | 336316 KB | Output is correct |
3 | Correct | 447 ms | 300372 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 362 ms | 327764 KB | Output is correct |
2 | Correct | 2037 ms | 673820 KB | Output is correct |
3 | Correct | 364 ms | 330292 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 357 ms | 332060 KB | Output is correct |
2 | Correct | 2922 ms | 785400 KB | Output is correct |
3 | Correct | 584 ms | 387736 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 274 ms | 311032 KB | Output is correct |
2 | Correct | 2646 ms | 665740 KB | Output is correct |
3 | Correct | 470 ms | 302672 KB | Output is correct |