답안 #234890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234890 2020-05-26T07:09:38 Z mahmoudbadawy Sirni (COCI17_sirni) C++17
126 / 140
3774 ms 786432 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int N=1e5+5,M=1e7+7;
 
int n;
int arr[N];
vector< pair<int,int> > ed[M];
int uni[N];
 
int uni_find(int x)
{
	return uni[x]=(uni[x]==x?x:uni_find(uni[x]));
}
 
int unio(int x,int y)
{
	x=uni_find(x); y=uni_find(y);
	if(x==y) return 0;
	uni[x]=y;
	return 1;
}
 
int main()
{
	scanf("%d",&n);
	set<int> ss;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
		ss.insert(arr[i]);
	}
	n=0;
	for(int i:ss) arr[n++]=i;
	for(int i=0;i<n;i++)
	{
		int s=i+1;
		for(int j=arr[i];j<M;j+=arr[i])
		{
			while(s<n && arr[s]<j) s++;
			if(s<n) ed[arr[s]%j].emplace_back(i,s);
		}
	}
	iota(uni,uni+n,0);
	long long ans=0;
	for(int i=0;i<M;i++)
	{
		for(auto j:ed[i])
		{
			if(unio(j.first,j.second)) ans+=i;
		}
	}
	cout << ans << endl;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
sirni.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&arr[i]);
   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 154 ms 235384 KB Output is correct
2 Correct 382 ms 267872 KB Output is correct
3 Correct 166 ms 235640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 235256 KB Output is correct
2 Runtime error 2549 ms 786432 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 161 ms 235388 KB Output is correct
2 Correct 158 ms 235256 KB Output is correct
3 Correct 158 ms 235512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2402 ms 250344 KB Output is correct
2 Correct 2220 ms 279404 KB Output is correct
3 Correct 1667 ms 261300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 222 ms 237944 KB Output is correct
2 Correct 347 ms 259372 KB Output is correct
3 Correct 1710 ms 249512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2569 ms 262468 KB Output is correct
2 Correct 2475 ms 297408 KB Output is correct
3 Correct 2298 ms 258740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 490 ms 240600 KB Output is correct
2 Correct 1758 ms 300332 KB Output is correct
3 Correct 1901 ms 260068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1771 ms 254124 KB Output is correct
2 Correct 3146 ms 599740 KB Output is correct
3 Correct 1763 ms 256752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1785 ms 258628 KB Output is correct
2 Correct 3774 ms 762812 KB Output is correct
3 Correct 1863 ms 310636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 239 ms 238456 KB Output is correct
2 Correct 3312 ms 621812 KB Output is correct
3 Correct 2008 ms 261132 KB Output is correct