Submission #393444

# Submission time Handle Problem Language Result Execution time Memory
393444 2021-04-23T13:14:42 Z ngpin04 Sirni (COCI17_sirni) C++14
0 / 140
313 ms 87232 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N = 1e7 + 5; 

int a[N];
int p[N];
int val[N];
int n;

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

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];

	val[a[1]] = 0;
	priority_queue <pair <int, int>> heap;
	heap.push(mp(0, a[1]));

	long long ans = 0;
	while (heap.size()) {
		int i = heap.top().se;
		int cur = -heap.top().fi;
		heap.pop();
		if (val[i] != cur)
			continue;
		ans += cur;
		val[i] = -1e9;

		if (i < mx && mini(val[p[i + 1]], p[i + 1] - i)) 
			heap.push(mp(-val[p[i + 1]], p[i + 1]));
		for (int j = 2 * i; j <= mx; j += i) 
			if (mini(val[p[j]], p[j] - j))
				heap.push(mp(-val[p[j]], p[j]));
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 43076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 43408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 9700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 8784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 97 ms 9676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 2700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 181 ms 81116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 313 ms 87232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 74040 KB Output isn't correct
2 Halted 0 ms 0 KB -