답안 #66552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66552 2018-08-11T11:44:34 Z KLPP Sirni (COCI17_sirni) C++14
126 / 140
5000 ms 40952 KB
#include<algorithm>
#include<stdio.h>
     
using namespace std;
#define MAXP 10000000
 
int pnt[MAXP+5];
int parent[1000000];
int size[1000000];
int root(int x){
	if(parent[x]==x)return x;
	parent[x]=root(parent[x]);
	return parent[x];
}
bool component(int a, int b){
    	a=root(a);
    	b=root(b);
    	if(root(a)==root(b))return true;
    	return false;
}
void merge(int a, int b){
    	a=root(a);
    	b=root(b);
    	if(a==b)return;
    	if(size[a]<size[b]){
    		size[b]+=size[a];
    		parent[a]=b;
    		return;
    	}
    	size[a]+=size[b];
    	parent[b]=a;
}
int main(){
    	int n;
    	scanf("%d",&n);
    	int arr[n];
    	for(int i=0;i<n;i++)scanf("%d",&arr[i]);
    	sort(arr,arr+n);
    	if(arr[0]==1){
		printf("0");
		return 0;
	}
    	int pn=1;
    	for(int i=1;i<n;i++){
    		if(arr[i]!=arr[pn-1]){
    			arr[pn]=arr[i];
    			pn++;
    		}
    	}
    	n=pn;
    	int k=arr[n-1];
    	for(int i=0;i<k+5;i++)pnt[i]=-1;
    	for(int i=0;i<n;i++){
    		pnt[arr[i]-1]=i;
    	}
    	long long int ans=0;
    	int CC=n;
    	for(int i=0;i<n;i++){
    		parent[i]=i;
    		size[i]=1;
    	}
    	int round=0;
    	while(CC>1){
    		//Plog(n)
    		for(int i=0;i<n;i++){
    			if(arr[i]>round){
    				for(int j=arr[i]+round-1;j<k;j+=arr[i]){
    					if(pnt[j]!=-1 && !component(i,pnt[j])){
    						merge(i,pnt[j]);
    						CC--;
    						ans+=round;
    					}
    				}
    			}
    		}
    		round++;
    	}printf("%lld",ans);
     
    	return 0;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:36:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
      scanf("%d",&n);
      ~~~~~^~~~~~~~~
sirni.cpp:38:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
      for(int i=0;i<n;i++)scanf("%d",&arr[i]);
                          ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 708 ms 39416 KB Output is correct
2 Correct 1618 ms 39416 KB Output is correct
3 Correct 612 ms 39476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 39476 KB Output is correct
2 Correct 927 ms 39640 KB Output is correct
3 Correct 133 ms 39640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 684 ms 39780 KB Output is correct
2 Correct 180 ms 39780 KB Output is correct
3 Correct 519 ms 39780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 39780 KB Output is correct
2 Correct 133 ms 39780 KB Output is correct
3 Correct 61 ms 39780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 39780 KB Output is correct
2 Correct 96 ms 39780 KB Output is correct
3 Correct 79 ms 39780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 39780 KB Output is correct
2 Correct 105 ms 39780 KB Output is correct
3 Correct 58 ms 39780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 39780 KB Output is correct
2 Correct 111 ms 39780 KB Output is correct
3 Correct 69 ms 39780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1530 ms 40904 KB Output is correct
2 Correct 1097 ms 40904 KB Output is correct
3 Correct 1602 ms 40952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 465 ms 40952 KB Output is correct
2 Correct 3014 ms 40952 KB Output is correct
3 Correct 163 ms 40952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1287 ms 40952 KB Output is correct
2 Execution timed out 5020 ms 40952 KB Time limit exceeded
3 Halted 0 ms 0 KB -