# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
949564 |
2024-03-19T11:12:20 Z |
Aiperiii |
Sirni (COCI17_sirni) |
C++14 |
|
251 ms |
331972 KB |
#include <bits/stdc++.h>
#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];
vector <pair <int,int> > g[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;
g[min(nxt%a[i],a[i]%nxt)].pb({ind[nxt],i});
}
}
for(int i=0;i<n;i++)p[i]=i;
int ans=0;
int cnt=0;
for(int i=0;i<M;i++){
for(auto x : g[i]){
if(union_set(x.ff,x.ss))ans+=i;
}
cnt++;
}
cout<<cnt<<"\n";
cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
195 ms |
278100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
140 ms |
274372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
145 ms |
278492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
195 ms |
289292 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
155 ms |
280320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
222 ms |
301084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
159 ms |
278868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
251 ms |
327764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
248 ms |
331972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
165 ms |
311120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |