# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1026536 |
2024-07-18T07:49:03 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++17 |
|
1075 ms |
786432 KB |
#include <bits/stdc++.h>
using namespace std;
int n, p[100000], dsu[100000], h[100000];
priority_queue<pair<int, pair<int, int> > > q;
int findRoot(int k) {
while(dsu[k] != k)
k = dsu[k];
return k;
}
void unite(int a, int b) {
a = findRoot(a);
b = findRoot(b);
if(h[a] > h[b])
swap(a, b);
dsu[a] = b;
h[b] = max(h[a] + 1, h[b]);
}
int main() {
cin>>n;
for(int i = 0; i < n; i++) {
cin>>p[i];
dsu[i] = i;
h[i] = 1;
}
for(int i = 0; i < n; i++)
for(int j = i + 1; j < n; j++)
q.push({-(max(p[i], p[j]) % min(p[i], p[j])), {i, j}});
long long res = 0;
while(q.size()) {
int d = -q.top().first;
int a = q.top().second.first;
int b = q.top().second.second;
q.pop();
//cout<<endl<<"d: "<<d<<" a: "<<a<<" b: "<<b;
if(findRoot(a) == findRoot(b))
continue;
//cout<<" +";
unite(a, b);
res += d;
}
//cout<<endl;
cout<<res<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
6856 KB |
Output is correct |
2 |
Correct |
85 ms |
7628 KB |
Output is correct |
3 |
Correct |
77 ms |
7884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
7624 KB |
Output is correct |
2 |
Correct |
82 ms |
8396 KB |
Output is correct |
3 |
Correct |
78 ms |
7368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
8140 KB |
Output is correct |
2 |
Correct |
69 ms |
7112 KB |
Output is correct |
3 |
Correct |
78 ms |
6856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1048 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1075 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
973 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1057 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1053 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1045 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1039 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |