답안 #234881

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234881 2020-05-26T06:52:17 Z mahmoudbadawy Sirni (COCI17_sirni) C++17
126 / 140
3766 ms 786436 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<N;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 147 ms 235384 KB Output is correct
2 Correct 382 ms 267920 KB Output is correct
3 Correct 146 ms 235640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 235256 KB Output is correct
2 Runtime error 2448 ms 786436 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 235384 KB Output is correct
2 Correct 145 ms 235256 KB Output is correct
3 Correct 143 ms 235512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2385 ms 250156 KB Output is correct
2 Correct 2180 ms 280232 KB Output is correct
3 Correct 1663 ms 262380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 237944 KB Output is correct
2 Correct 301 ms 259960 KB Output is correct
3 Correct 1698 ms 250428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2427 ms 262564 KB Output is correct
2 Correct 2469 ms 298188 KB Output is correct
3 Correct 2331 ms 259876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 480 ms 240600 KB Output is correct
2 Correct 1773 ms 300748 KB Output is correct
3 Correct 1903 ms 260924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1777 ms 253984 KB Output is correct
2 Correct 3146 ms 600760 KB Output is correct
3 Correct 1771 ms 257780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1760 ms 258460 KB Output is correct
2 Correct 3766 ms 763664 KB Output is correct
3 Correct 1864 ms 311632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 225 ms 238456 KB Output is correct
2 Correct 3276 ms 622292 KB Output is correct
3 Correct 1987 ms 261952 KB Output is correct