# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
972760 |
2024-05-01T06:34:11 Z |
12345678 |
Sirni (COCI17_sirni) |
C++17 |
|
61 ms |
8140 KB |
#include <bits/stdc++.h>
using namespace std;
const int nx=1e3+5;
int n, a[nx], res, cnt, dsu[nx];
vector<tuple<int, int, int>> ed;
int find(int x)
{
if (dsu[x]==x) return x;
return dsu[x]=find(dsu[x]);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
cnt=n;
for (int i=1; i<=n; i++) cin>>a[i], dsu[i]=i;
for (int i=1; i<=n; i++) for (int j=i+1; j<=n; j++) ed.push_back({min(a[i]%a[j], a[j]%a[i]), i, j});
sort(ed.begin(), ed.end());
for (auto [w, u, v]:ed)
{
if (find(u)!=find(v)) res+=w, dsu[find(u)]=find(v), cnt--;
if (cnt==1) break;
}
cout<<res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
6860 KB |
Output is correct |
2 |
Correct |
53 ms |
7372 KB |
Output is correct |
3 |
Correct |
50 ms |
7116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
6860 KB |
Output is correct |
2 |
Correct |
61 ms |
8136 KB |
Output is correct |
3 |
Correct |
47 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
7624 KB |
Output is correct |
2 |
Correct |
39 ms |
7116 KB |
Output is correct |
3 |
Correct |
47 ms |
7780 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 |
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 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |