# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
949280 |
2024-03-19T04:50:38 Z |
Baytoro |
Sirni (COCI17_sirni) |
C++17 |
|
910 ms |
786432 KB |
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define mp make_pair
#define ll long long
const ll INF=1e18,N=1e7+5;
ll nxt[N],par[N];
int f(ll x){
if(par[x]==x) return x;
return par[x]=f(par[x]);
}
bool add(ll a, ll b){
a=f(a),b=f(b);
if(a==b) return 0;
if(rand()%2) swap(a,b);
par[a]=b;
return 1;
}
void solve(){
int n;cin>>n;
vector<ll> p(n);
for(int i=0;i<n;i++) cin>>p[i];
sort(all(p));
ll mx=0;
for(int i=0;i<n;i++){
nxt[p[i]]=p[i];
mx=max(mx,p[i]);
par[p[i]]=p[i];
}
for(int i=N-1;i>=0;i--){
if(nxt[i]==0) nxt[i]=nxt[i+1];
}
vector<pair<int,pair<int,int> > > a;
for(int i=0;i<n;i++){
if(i<n-1 && p[i]==p[i+1]) continue;
//g[p[i]].pb(make_pair(p[i+1],p[i+1]%p[i]));
a.pb(mp(p[i+1]%p[i],mp(p[i],p[i+1])));
for(int j=p[i]*2;j<=mx;j+=p[i]){
a.pb(mp(nxt[j]%p[i],mp(p[i],nxt[j])));
//g[p[i]].pb(make_pair(nxt[j],nxt[j]%p[i]));
}
}
sort(all(a));
ll ans=0;
for(auto it: a){
if(add(it.sc.fr,it.sc.sc)){
ans+=it.fr;
}
}
cout<<ans<<endl;
}
int main(){
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
156808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
78928 KB |
Output is correct |
2 |
Runtime error |
752 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
156832 KB |
Output is correct |
2 |
Incorrect |
45 ms |
134196 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
113896 KB |
Output is correct |
2 |
Correct |
657 ms |
137348 KB |
Output is correct |
3 |
Correct |
345 ms |
139248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
91336 KB |
Output is correct |
2 |
Correct |
363 ms |
138784 KB |
Output is correct |
3 |
Correct |
219 ms |
110524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
406 ms |
138668 KB |
Output is correct |
2 |
Correct |
867 ms |
187204 KB |
Output is correct |
3 |
Correct |
310 ms |
113188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
89116 KB |
Output is correct |
2 |
Correct |
862 ms |
186788 KB |
Output is correct |
3 |
Correct |
314 ms |
113136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
274 ms |
184240 KB |
Output is correct |
2 |
Runtime error |
735 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
313 ms |
183228 KB |
Output is correct |
2 |
Runtime error |
736 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
160244 KB |
Output is correct |
2 |
Runtime error |
910 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |