답안 #66548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66548 2018-08-11T11:25:44 Z KLPP Sirni (COCI17_sirni) C++14
98 / 140
5000 ms 40912 KB
#include<iostream>
#include<vector>
#include<queue>
#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);
	int pn=1;
	for(int i=1;i<n;i++){
		if(arr[i]!=arr[pn-1]){
			arr[pn]=arr[i];
			pn++;
		}
	}
	n=pn;
	for(int i=0;i<MAXP+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;
	n--;
	while(CC>1){
		for(int i=0;i<n;i++){
			if(arr[i]>round){
				int point=i+1;
				while(point<=n){
					if(arr[point]%arr[i]==round && !component(i,point)){
						merge(i,point);
						ans+=round;CC--;
					}
					int num=arr[point];
					num/=arr[i];
					num++;
					num*=arr[i];
					num+=round;
					int lo,hi;
					lo=point;
					hi=n+1;
					while(hi-lo>1){
						int mid=(hi+lo)/2;
						if(arr[mid]>=num)hi=mid;
						else lo=mid;
					}
					point=hi;
				}
			}
		}
		round++;
	}printf("%lld\n",ans);

	return 0;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
sirni.cpp:40:27: 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 3768 ms 39544 KB Output is correct
2 Correct 348 ms 39784 KB Output is correct
3 Correct 1658 ms 39784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 39784 KB Output is correct
2 Correct 38 ms 39784 KB Output is correct
3 Correct 184 ms 39784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3314 ms 39784 KB Output is correct
2 Correct 501 ms 39784 KB Output is correct
3 Correct 1956 ms 39784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1515 ms 40816 KB Output is correct
2 Correct 2651 ms 40816 KB Output is correct
3 Correct 448 ms 40816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 319 ms 40816 KB Output is correct
2 Correct 1365 ms 40816 KB Output is correct
3 Correct 1010 ms 40816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2802 ms 40912 KB Output is correct
2 Correct 1442 ms 40912 KB Output is correct
3 Correct 461 ms 40912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 40912 KB Output is correct
2 Correct 1507 ms 40912 KB Output is correct
3 Correct 382 ms 40912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5028 ms 40912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2505 ms 40912 KB Output is correct
2 Execution timed out 5104 ms 40912 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5017 ms 40912 KB Time limit exceeded
2 Halted 0 ms 0 KB -