# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
949438 |
2024-03-19T08:49:16 Z |
Aiperiii |
Sirni (COCI17_sirni) |
C++14 |
|
3917 ms |
786432 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,M=1e7+5;
int p[N],ind[M],nx[M];
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;
nx[a[i]]=a[i];
ind[a[i]]=i;
}
for(int i=M-2;i>=0;i--){
if(!nx[i])nx[i]=nx[i+1];
}
for(int i=0;i<n;i++){
if(i-1>=0 && a[i]==a[i-1])continue;
for(int j=a[i];j<M;j+=a[i]){
int nxt=0;
if(j==a[i])nxt=nx[j+1];
else nxt=nx[j];
if(!nxt)break;
v.pb({min(nxt%a[i],a[i]%nxt),ind[nxt],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 |
Correct |
90 ms |
156712 KB |
Output is correct |
2 |
Correct |
1155 ms |
322776 KB |
Output is correct |
3 |
Correct |
48 ms |
157840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
80892 KB |
Output is correct |
2 |
Runtime error |
534 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
156764 KB |
Output is correct |
2 |
Correct |
45 ms |
125964 KB |
Output is correct |
3 |
Correct |
44 ms |
157072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
721 ms |
171612 KB |
Output is correct |
2 |
Correct |
2849 ms |
318212 KB |
Output is correct |
3 |
Correct |
1129 ms |
253144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
98888 KB |
Output is correct |
2 |
Correct |
1530 ms |
252624 KB |
Output is correct |
3 |
Correct |
628 ms |
167916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1614 ms |
252824 KB |
Output is correct |
2 |
Correct |
3917 ms |
417236 KB |
Output is correct |
3 |
Correct |
1065 ms |
194616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
208 ms |
103724 KB |
Output is correct |
2 |
Correct |
3798 ms |
424316 KB |
Output is correct |
3 |
Correct |
922 ms |
200512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
967 ms |
241996 KB |
Output is correct |
2 |
Runtime error |
559 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1083 ms |
262720 KB |
Output is correct |
2 |
Runtime error |
606 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
169084 KB |
Output is correct |
2 |
Runtime error |
682 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |