# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
949333 |
2024-03-19T06:30:14 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++17 |
|
1539 ms |
167264 KB |
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e5+5;
int p[N];
int find_set(int v){
if(p[v]==v)return v;
return p[v]=find_set(p[v]);
}
bool union_set(int u,int v){
u=find_set(u);
v=find_set(v);
if(u==v)return false;
p[u]=v;
return true;
}
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n;
cin>>n;
vector <int> a(n);
for(int i=0;i<n;i++)cin>>a[i];
vector < vector <int> > v;
sort(all(a));
for(int i=0;i<n;i++){
if(i-1>=0 && a[i]==a[i-1])continue;
for(int j=a[i];j<=1e6;j+=a[i]){
auto it=lower_bound(all(a),j);
if(it!=a.end()){
int pos=it-a.begin();
v.pb({min(a[pos]%a[i],a[i]%a[pos]),pos,i});
}
}
}
sort(all(v));
for(int i=0;i<n;i++)p[i]=i;
int ans=0;
for(auto x : v){
int w=x[0];
int u=x[1];
int v=x[2];
//cout<<w<<" "<<u<<" "<<v<<"\n";
if(union_set(u,v))ans+=w;
}
cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
606 ms |
84968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
12300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1539 ms |
167264 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
161 ms |
22736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
8148 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
13272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
1428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |