# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
863476 |
2023-10-20T12:20:32 Z |
blacktulip |
Sirni (COCI17_sirni) |
C++17 |
|
1399 ms |
654912 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
#define fi first
#define se second
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
#define _ << " " <<
const lo inf = 1000000000;
const lo li = 500005;
const lo mod = 1000000007;
int n,m,a[li],k,flag,t,fa[li],vis[10000005],mx[10000005],ind[10000005];
long long cev;
string s;
vector<pair<int,int>> v[10000002];
set<pair<int,int>> st;
inline int dsu(int x){
if(x==fa[x])return x;
return fa[x]=dsu(fa[x]);
}
int main(void){
fio();
cin>>n;
FOR{
fa[i]=i;
cin>>a[i];
mx[a[i]]=a[i];
}
for(int i=10000000-1;i>=1;i--){
if(!mx[i])mx[i]=mx[i+1];
}
sort(a+1,a+n+1);
FOR{
if(!ind[a[i]])ind[a[i]]=i;
}
FOR{
if(a[i]==a[i-1]){
v[0].pb({i-1,i});
continue;
}
if(mx[a[i]+1] && mx[a[i]*2]!=mx[a[i]+1])v[mx[a[i]+1]-a[i]].pb({i,ind[mx[a[i]+1]]});
for(int j=a[i]*2;j<=10000000;j+=a[i]){
vis[j]=i;
if(mx[j] && mx[j]!=mx[j+a[i]])v[mx[j]-j].pb({i,ind[mx[j]]});
}
}
for(int i=0;i<=10000000;i++){
for(auto go:v[i]){
int x=go.fi;
int y=go.se;
if(dsu(x)==dsu(y))continue;
fa[dsu(x)]=dsu(y);
cev+=i;
}
}
cout<<cev<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
297164 KB |
Output is correct |
2 |
Correct |
161 ms |
323268 KB |
Output is correct |
3 |
Correct |
104 ms |
322564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
318552 KB |
Output is correct |
2 |
Correct |
396 ms |
319828 KB |
Output is correct |
3 |
Correct |
106 ms |
322404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
322396 KB |
Output is correct |
2 |
Correct |
102 ms |
321168 KB |
Output is correct |
3 |
Correct |
104 ms |
322580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
271 ms |
331248 KB |
Output is correct |
2 |
Correct |
662 ms |
361688 KB |
Output is correct |
3 |
Correct |
311 ms |
336784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
322960 KB |
Output is correct |
2 |
Correct |
443 ms |
343840 KB |
Output is correct |
3 |
Correct |
370 ms |
330500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
446 ms |
343536 KB |
Output is correct |
2 |
Correct |
768 ms |
373728 KB |
Output is correct |
3 |
Correct |
301 ms |
335264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
310 ms |
322172 KB |
Output is correct |
2 |
Correct |
876 ms |
368232 KB |
Output is correct |
3 |
Correct |
306 ms |
334912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
196 ms |
368240 KB |
Output is correct |
2 |
Correct |
953 ms |
568360 KB |
Output is correct |
3 |
Correct |
224 ms |
370640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
188 ms |
368196 KB |
Output is correct |
2 |
Correct |
1399 ms |
654912 KB |
Output is correct |
3 |
Correct |
226 ms |
374756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
353004 KB |
Output is correct |
2 |
Correct |
1333 ms |
644836 KB |
Output is correct |
3 |
Correct |
320 ms |
336828 KB |
Output is correct |