# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1026687 | 2024-07-18T09:16:46 Z | vjudge1 | Sirni (COCI17_sirni) | C++17 | 670 ms | 786432 KB |
#include <bits/stdc++.h> using namespace std; bool cmp(int a, int b) { return a>b; } vector<int>p, sz; void make_set(int n) { p.resize(n); sz.resize(n); for(int i=0; i<n; i++) { p[i]=i; sz[i]=1; } } int Find(int i) { if(p[i]==i) return i; return p[i]=Find(p[i]); } bool Union(int a, int b) { a=Find(a), b=Find(b); if(a!=b) { if(sz[a]>sz[b]) swap(a, b); p[a]=b; sz[b]+=sz[a]; return 1; } return 0; } int main() { int n; cin>>n; make_set(n); long long int a[n]; long long rez=0; vector<pair<int, pair<int, int>>>v; for(int i=0; i<n; i++) { cin>>a[i]; } sort(a, a+n, cmp); for(int i=0; i<n; i++) { for(int j=i+1; j<n; j++) { v.push_back(make_pair(a[i]%a[j], make_pair(i, j))); } } sort(v.begin(), v.end()); int edges=0; for(int i=0; i<v.size(); i++) { if(edges==n-1) break; if(Union(v[i].second.first, v[i].second.second)) { rez+=v[i].first; edges++; } } cout<<rez; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 7116 KB | Output is correct |
2 | Correct | 44 ms | 6856 KB | Output is correct |
3 | Correct | 38 ms | 7880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 47 ms | 7880 KB | Output is correct |
2 | Correct | 51 ms | 8652 KB | Output is correct |
3 | Correct | 38 ms | 8136 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 7236 KB | Output is correct |
2 | Correct | 29 ms | 8136 KB | Output is correct |
3 | Correct | 38 ms | 8068 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 653 ms | 786432 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 653 ms | 786432 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 646 ms | 786432 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 654 ms | 786432 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 648 ms | 786432 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 670 ms | 786432 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 603 ms | 786432 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |