답안 #393448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393448 2021-04-23T13:33:34 Z ngpin04 Sirni (COCI17_sirni) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N = 1e7 + 5; 

vector <pair <int, int>> edge[N];

int a[N];
int par[N];
int n;

bool mini(int &a, int b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

int getpar(int u) {
	return (par[u] < 0) ? u : (par[u] = getpar(par[u]));
}

bool join(int u, int v) {
	u = getpar(u);
	v = getpar(v);
	if (u == v)
		return false;
	if (par[u] > par[v])
		swap(u, v);
	par[u] += par[v];
	par[v] = u;	
	return true;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;

	for (int i = 1; i <= n; i++) 
		cin >> a[i];
	sort(a + 1, a + n + 1);
	n = unique(a + 1, a + n + 1) - (a + 1);

	for (int i = 1; i <= n; i++) {
		p[a[i]] = a[i];
		val[a[i]] = 1e9;
	} 	

	int mx = a[n];
	for (int i = mx - 1; i >= 1; i--) 
		if (!p[i])
			p[i] = p[i + 1];

	for (int i = 1; i <= n; i++) {
		int x = a[i];
		if (i < n)
			 edge[p[x + 1] - x].push_back(mp(x, p[x + 1]));

		for (int j = 2 * x; j <= mx; j += x) {
			// cout << p[j] << " " << j << "\n";
			edge[p[j] - j].push_back(mp(x, p[j]));
		}
	}

	for (int i = 1; i <= mx; i++)
		par[i] = -1;
	long long ans = 0;
	for (int i = 0; i <= mx; i++) 
	for (pair <int, int> e : edge[i]) 
		ans += i * join(e.fi, e.se);
	cout << ans;
	return 0;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:49:3: error: 'p' was not declared in this scope
   49 |   p[a[i]] = a[i];
      |   ^
sirni.cpp:50:3: error: 'val' was not declared in this scope
   50 |   val[a[i]] = 1e9;
      |   ^~~
sirni.cpp:55:8: error: 'p' was not declared in this scope
   55 |   if (!p[i])
      |        ^
sirni.cpp:61:10: error: 'p' was not declared in this scope
   61 |     edge[p[x + 1] - x].push_back(mp(x, p[x + 1]));
      |          ^
sirni.cpp:65:9: error: 'p' was not declared in this scope
   65 |    edge[p[j] - j].push_back(mp(x, p[j]));
      |         ^