# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
24251 | 2017-06-03T10:32:21 Z | Bruteforceman | Sirni (COCI17_sirni) | C++11 | 656 ms | 120484 KB |
#include "bits/stdc++.h" using namespace std; struct edge { int u, v, cost; edge () {} edge (int u, int v, int cost) : u(u), v(v), cost(cost) {} bool operator < (edge e) const { return cost < e.cost; } }; vector <int> node; vector <edge> e; const int maxn = 10000000; int nxt[maxn + 5]; int par[100010]; int sub[100010]; int root(int x) { if(x == par[x]) return x; else return par[x] = root(par[x]); } void join(int x, int y) { x = root(x); y = root(y); if(sub[x] > sub[y]) swap(x, y); if(x != y) { par[x] = y; sub[y] += sub[x]; } } int main(int argc, char const *argv[]) { set <int> s; int n; scanf("%d", &n); for(int i = 0; i < n; i++) { par[i] = i; sub[i] = 1; int p; scanf("%d", &p); s.insert(p); } node = vector <int> (s.begin(), s.end()); memset(nxt, -1, sizeof nxt); nxt[maxn + 1] = n; for(size_t i = 0; i < node.size(); i++) { nxt[node[i]] = i; } for(int i = maxn; i >= 0; i--) { if(nxt[i] == -1){ nxt[i] = nxt[i + 1]; } } for(size_t i = 0; i < node.size(); i++) { for(int j = 0; j <= maxn; j += node[i]) { if(nxt[j] < (int) node.size()) { e.push_back(edge(i, nxt[j], node[nxt[j]] - j)); } } } sort(e.begin(), e.end()); long long ans = 0; for(size_t i = 0; i < e.size(); i++) { int u = e[i].u; int v = e[i].v; int cost = e[i].cost; if(root(u) != root(v)) { join(u, v); ans += cost; } } printf("%lld\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 42184 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 126 ms | 42380 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 26 ms | 42188 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 353 ms | 83656 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 76 ms | 47276 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 656 ms | 120484 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 306 ms | 52932 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 289 ms | 83872 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 309 ms | 83872 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 66 ms | 47576 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |