Submission #949268

# Submission time Handle Problem Language Result Execution time Memory
949268 2024-03-19T04:41:23 Z vjudge1 Sirni (COCI17_sirni) C++17
0 / 140
232 ms 338608 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
const int INF=1e9,N=1e7+5;
int nxt[N],par[N];
vector<pair< int,int> > g[N];
int f(int x){
	if(par[x]==x) return x;
	return par[x]=f(par[x]);
}
bool add(int a, int 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<int> p(n);
	for(int i=0;i<n;i++) cin>>p[i];
	sort(all(p));
	int 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 && 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]));
		}
	}
	
	int 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 164 ms 287568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 94 ms 276560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 289616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 158 ms 306356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 284616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 215 ms 330252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 284460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 232 ms 338464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 207 ms 338608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 109 ms 313796 KB Output isn't correct
2 Halted 0 ms 0 KB -