# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
956269 |
2024-04-01T12:44:55 Z |
Trisanu_Das |
Sirni (COCI17_sirni) |
C++17 |
|
1012 ms |
786432 KB |
#include "bits/stdc++.h"
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
vector<int> a(n),parent(n);
for(auto &i:a)cin>>i;
for(int i=0;i<n;i++){
parent[i] =i;
}
auto find = [&](int x){
while(x != parent[x])x = parent[x];
return x;
};
auto unite = [&](int a,int b){
a = find(a);
b = find(b);
if(a != b){
parent[b] = a;
}
};
vector<pair<int,pair<int,int>>> edges;
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
edges.push_back({min(a[i]%a[j],a[j]%a[i]),{i,j}});
}
}
long long res = 0;
sort(edges.begin(),edges.end());
for(auto edge:edges){
int x = edge.second.first,b = edge.second.second;
if(find(x) != find(b)){
res += edge.first;
unite(x,b);
}
}
cout << res <<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
7624 KB |
Output is correct |
2 |
Correct |
388 ms |
7116 KB |
Output is correct |
3 |
Correct |
572 ms |
7112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
487 ms |
7368 KB |
Output is correct |
2 |
Correct |
829 ms |
7112 KB |
Output is correct |
3 |
Correct |
606 ms |
6604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
372 ms |
7880 KB |
Output is correct |
2 |
Correct |
181 ms |
7628 KB |
Output is correct |
3 |
Correct |
428 ms |
7880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1012 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
649 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
628 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
638 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
630 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
639 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
627 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |