Submission #412771

# Submission time Handle Problem Language Result Execution time Memory
412771 2021-05-27T13:26:55 Z kshitij_sodani Sirni (COCI17_sirni) C++14
0 / 140
623 ms 439872 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#define endl '\n'

llo n;
bool vis[10000001];
llo ind[10000001];
llo re[10000001+1];
llo par[100001];
llo find(llo no){
	if(par[no]==no){
		return no;
	}
	par[no]=find(par[no]);
	return par[no];
}
vector<pair<llo,llo>> pre[10000001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	llo ind2=0;
	vector<llo> it;
	for(llo i=0;i<n;i++){
		llo x;
		cin>>x;
		if(vis[x]==0){
			vis[x]=1;
			ind[x]=ind2;
			it.pb(x);
			//cout<<x<<":"<<ind2<<endl;
			ind2++;
		}
	}	
	for(llo i=0;i<ind2;i++){
		par[i]=i;
	}
	/*for(int i=0;i<ind2;i++){
		for(int j=0;j<ind2;j++){
			if(it[i]>it[j]){
				pre[it[i]%it[j]].pb({i,j});
			}
		}
	}*/
	re[10000001]=-1;
	for(llo i=10000000;i>=1;i--){
		re[i]=re[i+1];
		if(vis[i]==1){
			re[i]=i;
		}
	}
	for(llo i=1;i<=10000000;i++){
		if(vis[i]==1){
			for(llo j=i;j<=10000000;j+=i){
				if(re[j]>=0){
					pre[re[j]-j].pb({ind[re[j]],ind[i]});
				}
			}
		}
	}
	llo ans=0;
	for(llo i=0;i<=10000000;i++){
		for(auto j:pre[i]){
			llo x=find(j.a);
			llo y=find(j.b);
			//cout<<x<<","<<y<<","<<j.a<<","<<j.b<<endl;
			if(x==y){

			}
			else{
				ans+=i;
				par[x]=y;
			}
		}
	}
	cout<<ans<<endl;






	return 0;
}
 
# Verdict Execution time Memory Grader output
1 Incorrect 226 ms 320408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 304 ms 313672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 229 ms 320968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 420 ms 345348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 268 ms 326792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 623 ms 369784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 431 ms 323164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 413 ms 430652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 414 ms 439872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 274 ms 378380 KB Output isn't correct
2 Halted 0 ms 0 KB -