# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884424 |
2023-12-07T10:24:03 Z |
gutzzy |
Sirni (COCI17_sirni) |
C++14 |
|
1473 ms |
786432 KB |
#include <bits/stdc++.h>
using namespace std;
int find(int x, vector<int> &par){
if(par[x]==x) return x;
par[x] = find(par[x],par);
return par[x];
}
void merge(int x, int y, vector<int> &par){
x = find(x,par);
y = find(y,par);
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;
vector<int> par(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;
for(auto e:edges){
int a = e.second.first;
int b = e.second.second;
if(find(a,par)!=find(b,par)){
merge(a,b,par);
ans += e.first;
}
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
7624 KB |
Output is correct |
2 |
Correct |
62 ms |
8144 KB |
Output is correct |
3 |
Correct |
56 ms |
7116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
7880 KB |
Output is correct |
2 |
Correct |
67 ms |
8648 KB |
Output is correct |
3 |
Correct |
60 ms |
7376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
7372 KB |
Output is correct |
2 |
Correct |
47 ms |
7372 KB |
Output is correct |
3 |
Correct |
57 ms |
7632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1472 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1226 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1366 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1373 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1408 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1399 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1473 ms |
786432 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |