240622026-02-03 19:07:36ubormaciMobilNet (50 pont)cpp17Accepted 50/5071ms10480 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
// #pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*

notes:

int64_t
stoi(string s) -> string to int
to_string() -> int (or else) to string

vector declaration:
vector<ll> v(n, 0)
vector<vector<ll>> v(n, vector<ll>(n, 0));

{if statement} ? {truth value} : {false value}

#ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

cout << fixed << setprecision(n);

set with custom ordering
set<ll, decltype(&cmp)> qu(cmp);

*/

typedef int64_t ll;

vector<ll> par;
vector<ll> s;

ll find(ll x) {

	if(par[x] == x) {
		return x;
	}else{
		par[x] = find(par[x]);
	}

	return par[x];

}

void join(ll a, ll b) {

	if(s[a] > s[b]) {
		swap(a, b);
	}

	par[a] = b;
	s[b] += s[a];
}

void solve() {
	
	// na az elso reszfeladat effektive egy krushkal
	// effektive, melyik a legnagyobb el-koltseg
	// es hany olyan el letezik

	// eloszor is okosan el kell raktarozzuk minden pontra a hozza negy legkozelebbi elet

	ll n;
	cin >> n;

	par.assign(n, 0);
	s.assign(n, 1);

	vector<pair<ll,ll>> v(n, {0,0}); // points
	map<ll, vector<pair<ll,ll>>> row;
	map<ll, vector<pair<ll,ll>>> col;

	for(ll i = 0; i < n; i++) {
		par[i] = i;

		cin >> v[i].first >> v[i].second;

		// add to columns, rows
		row[v[i].second].push_back({v[i].first, i});
		col[v[i].first].push_back({v[i].second, i});
	}

	// hmmmm
	// shall I do proper DSU, or no?
	// better to exercise it

	// atmegyunk minden column-on/row-on
	// a map-ben egyszeruen meg lehet keresni az elozo/kovetkezo elemet
	// insert edge, stb

	vector<pair<ll,pair<ll,ll>>> khr; // weight, points at the end

	for(auto & [r, vh] : row) {
		
		sort(vh.begin(), vh.end());

		//cerr << "\nrow=" << r << "; " << vh;

		for(ll i = 0; i < vh.size() - 1; i++) {
			khr.push_back({vh[i+1].first - vh[i].first, {vh[i].second, vh[i+1].second}});
		}
	}
	for(auto & [c, vh] : col) {

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

		//cerr << "\ncol=" << c << "; " << vh;
		for(ll i = 0; i < vh.size() - 1; i++) {
			khr.push_back({vh[i+1].first - vh[i].first, {vh[i].second, vh[i+1].second}});
		}
	}

	sort(khr.begin(), khr.end());
	ll mx = 0;
	ll cnt = 0;
	for(const auto & [w, fromto] : khr) {
		ll a = fromto.first;
		ll b = fromto.second;

		//cerr << "\na=" << a << "; b=" << b << "; w=" << w;
		//cerr << "\na=" << v[a];
		//cerr << "; b=" << v[b];

		if(find(a) != find(b)) {
			//cerr << "\nits joining time";
			join(find(a), find(b));

			if(w > mx) {
				mx = w;
				cnt = 1;
			}
			else if(w == mx) {
				cnt++;
			}
		}
	}
	
	cout << mx << "\n" << cnt;
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);

	solve();

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/06ms1268 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/22ms564 KiB
9Accepted2/23ms820 KiB
10Accepted2/24ms820 KiB
11Accepted2/26ms1256 KiB
12Accepted2/28ms1844 KiB
13Accepted3/314ms2552 KiB
14Accepted3/320ms3336 KiB
15Accepted3/329ms4672 KiB
16Accepted3/334ms5396 KiB
17Accepted3/350ms7136 KiB
18Accepted3/339ms6824 KiB
19Accepted3/357ms8256 KiB
20Accepted3/361ms8384 KiB
21Accepted3/371ms10480 KiB
22Accepted3/368ms10212 KiB