# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
862656 | 2023-10-18T18:10:08 Z | Irate | Sirni (COCI17_sirni) | C++14 | 45 ms | 8652 KB |
#include<bits/stdc++.h> using namespace std; const int mxN = 1e3 + 3; int a[mxN]; struct Edge{ int u, v, w; bool operator<(Edge &other){ return w < other.w; } }; struct DSU{ vector<int>par; DSU(int n){ par.assign(n + 1, -1); } int FindRep(int u){ if(par[u] < 0)return u; return par[u] = FindRep(par[u]); } bool Union(int u, int v){ u = FindRep(u); v = FindRep(v); if(u == v)return false; if(par[u] > par[v])swap(u, v); par[u] += par[v]; par[v] = u; return true; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i = 1;i <= n;++i){ cin >> a[i]; } vector<Edge>edge_list; for(int i = 1;i <= n;++i){ for(int j = i + 1;j <= n;++j){ Edge temp; temp.u = i; temp.v = j; temp.w = min(a[i] % a[j], a[j] % a[i]); edge_list.push_back(temp); } } sort(edge_list.begin(), edge_list.end()); DSU dsu(n); long long res = 0; for(int i = 0;i < edge_list.size();++i){ if(dsu.Union(edge_list[i].u, edge_list[i].v))res += edge_list[i].w; } cout << res; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 7116 KB | Output is correct |
2 | Correct | 35 ms | 7884 KB | Output is correct |
3 | Correct | 43 ms | 6860 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 7368 KB | Output is correct |
2 | Correct | 30 ms | 8392 KB | Output is correct |
3 | Correct | 45 ms | 8652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 7628 KB | Output is correct |
2 | Correct | 36 ms | 7372 KB | Output is correct |
3 | Correct | 44 ms | 7112 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 604 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 604 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 472 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 604 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 604 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 600 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 604 KB | Execution killed with signal 8 |
2 | Halted | 0 ms | 0 KB | - |