답안 #371236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
371236 2021-02-26T08:56:29 Z FatihSolak Sirni (COCI17_sirni) C++17
126 / 140
2786 ms 786436 KB
#include <bits/stdc++.h>
#define N 100005
#define M 10000005
using namespace std;
int par[N];
int nxt[M];
int pos[M];
vector<pair<int,int>> v[M];
int find(int a){
	if(a == par[a])return a;
	return par[a] = find(par[a]);
}
bool unite(int a,int b){
	a = find(a);
	b = find(b);
	if(a == b)return 0;
	par[b] = a;
	return 1;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n;
	cin >> n;
	int maxi = 0;
	for(int i=1;i<=n;i++){
		int a;
		cin >> a;
		pos[a] = i;
		maxi = max(maxi,a);
	}
	vector<int> nums;
	for(int i=maxi;i>=0;i--){
		if(pos[i]){
			nxt[i] = i;
			nums.push_back(i);
		}
		else nxt[i] = nxt[i+1];
	}
	for(auto u:nums){
		for(int i=u;i<=maxi;i+=u){
			int p = nxt[i+(i==u)];
			if(p)
				v[p%u].push_back({pos[u],pos[p]});
		}
	}
	for(int i=0;i<n;i++){
		par[i] = i;
	}
	long long ans = 0;
	for(int i=0;i<=maxi;i++){
		for(auto u:v[i]){
			if(unite(u.first,u.second))ans+=i;
		}
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 278124 KB Output is correct
2 Correct 338 ms 311428 KB Output is correct
3 Correct 227 ms 278380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 235500 KB Output is correct
2 Correct 1827 ms 706540 KB Output is correct
3 Correct 228 ms 279148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 278384 KB Output is correct
2 Correct 246 ms 276844 KB Output is correct
3 Correct 230 ms 278508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 253656 KB Output is correct
2 Correct 363 ms 282036 KB Output is correct
3 Correct 269 ms 267948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 245356 KB Output is correct
2 Correct 276 ms 267116 KB Output is correct
3 Correct 215 ms 250068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 300 ms 265144 KB Output is correct
2 Correct 453 ms 295656 KB Output is correct
3 Correct 249 ms 261440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 240464 KB Output is correct
2 Correct 439 ms 310208 KB Output is correct
3 Correct 253 ms 266448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 361 ms 328300 KB Output is correct
2 Correct 2278 ms 656580 KB Output is correct
3 Correct 384 ms 332908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 371 ms 333060 KB Output is correct
2 Runtime error 2457 ms 786436 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 256 ms 310840 KB Output is correct
2 Correct 2786 ms 733520 KB Output is correct
3 Correct 265 ms 267196 KB Output is correct