Submission #863143

# Submission time Handle Problem Language Result Execution time Memory
863143 2023-10-19T16:52:50 Z MisterReaper Sirni (COCI17_sirni) C++17
Compilation error
0 ms 0 KB
//author: Ahmet Alp Orakci
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

const int MAXN = 2E7 + 5;

ostream& operator<< (ostream& os, pair <int, int> &pii) {
	return os << "{" << pii.first << " " << pii.second << "}";
}

struct DSU {
	int n;
	vector <int> par; 
	DSU(int n) : n(n) {
		par.resize(n);
		iota(par.begin(), par.end(), 0);
	}

	inline int get(int x) {
		return par[x] = (x == par[x] ? x : get(par[x]));
	}

	bool same(int a, int b) {
		return get(a) == get(b);
	}

	bool unite(int u, int v) {
		if(same(u, v)) 
			return false;

		u = get(u);
		v = get(v);

		par[v] = u;

		return true;
	}
};

#define ONLINE_JUDGE
void solve() {
	int n;
	cin >> n;

	vector <int> vec(n);
	for(int &i : vec)
		cin >> i;

	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());

	n = vec.size();

	vector <tuple <int, int, int>> edges;
	
	for(int it = 0; it < n; it++) {
		if(it != 0) {
			edges.emplace_back(vec[it] % vec[it -1], it -1, it);
		}

		int i = vec[it];
		for(int k = i; k < MAXN; k += i) {
			int itt = upper_bound(vec.begin(), vec.end(), k -1) - vec.begin();
			if(itt != n)
				edges.emplace_back(vec[itt] % vec[it], it, itt);

			int iit = lower_bound(vec.begin(), vec.end(), k -1);
			edges.emplace_back(vec[it] % vec[iit], iit, it);
		}
	}

	sort(edges.begin(), edges.end());

	DSU dsu(n);
	i64 ans = 0;
	for(auto [c, u, v] : edges) {
		//cerr << c << " " << u << " " << v << "\n";
		if(dsu.unite(u, v)) {
			ans += c;
		}
	}

	bool check = true;
	for(int i = 0; i < n; i++)
		check &= dsu.same(0, i);

	cout << ans;
	assert(check);
	
	return;
}

signed main() {
	#ifndef ONLINE_JUDGE
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int t = 1; //cin >> t;
	for(int i = 1; i <= t; i++) {
		solve();
	}

	return 0;
}

Compilation message

sirni.cpp: In function 'void solve()':
sirni.cpp:68:25: error: cannot convert '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to 'int' in initialization
   68 |    int iit = lower_bound(vec.begin(), vec.end(), k -1);
      |              ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                         |
      |                         __gnu_cxx::__normal_iterator<int*, std::vector<int> >