# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884433 |
2023-12-07T10:33:41 Z |
gutzzy |
Sirni (COCI17_sirni) |
C++14 |
|
1468 ms |
786436 KB |
#include <bits/stdc++.h>
using namespace std;
vector<int> par;
int find(int x){
if(par[x]==x) return x;
par[x] = find(par[x]);
return par[x];
}
void merge(int x, int y){
x = find(x);
y = find(y);
par[max(x,y)] = min(x,y);
}
int main(){
int n;
cin >> n;
vector<int> ps(n);
unordered_map<int,int> pton;
for(int i=0;i<n;i++){
cin >> ps[i];
pton[ps[i]] = i; // si p son diferents!! (no ho diu a l'enunciat..)
}
// minimum spanning tree
vector<pair<int,pair<int,int>>> edges;
par = vector<int>(n);
for(int i=0;i<n;i++) par[i] = i;
for(int i=0;i<n;i++){
int l = ps[i];
for(int j=i;j<n;j++){
int r = ps[j];
edges.push_back({min(l%r,r%l),{pton[l],pton[r]}});
}
}
sort(edges.begin(),edges.end());
int ans = 0;
int v = 0;
for(auto e:edges){
int a = e.second.first;
int b = e.second.second;
if(find(a)!=find(b)){
merge(a,b);
ans += e.first;
v++;
if(v==n-1) break;
}
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
8648 KB |
Output is correct |
2 |
Correct |
61 ms |
8144 KB |
Output is correct |
3 |
Correct |
54 ms |
7776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
7368 KB |
Output is correct |
2 |
Correct |
66 ms |
7116 KB |
Output is correct |
3 |
Correct |
57 ms |
6876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
8140 KB |
Output is correct |
2 |
Correct |
49 ms |
7632 KB |
Output is correct |
3 |
Correct |
55 ms |
6864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1447 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1188 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1345 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1334 ms |
786436 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1450 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1468 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1426 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |