Submission #1251630

#TimeUsernameProblemLanguageResultExecution timeMemory
1251630ZicrusObstacles for a Llama (IOI25_obstacles)C++20
24 / 100
73 ms9800 KiB
#include <bits/stdc++.h>
#include "obstacles.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(v) v.begin(), v.end()
constexpr ll inf = 1ll << 62ll;
mt19937 mt(34056237);
ll _ = 0;

struct union_find {
	vector<ll> lnk, sz;

	union_find() { }
	union_find(ll n) : lnk(n), sz(n, 1) {
		iota(all(lnk), 0);
	}

	ll find (ll a) {
		if (lnk[a] != a) lnk[a] = find(lnk[a]);
		return lnk[a];
	}

	bool merge(ll a, ll b) {
		a = find(a); b = find(b);
		if (a == b) return false;
		if (sz[a] < sz[b]) swap(a, b);
		lnk[b] = a;
		sz[a] += sz[b];
		return true;
	}
};

union_find dsu;

void initialize(vector<int> T, vector<int> H) {
	ll n = T.size(), m = H.size();
	dsu = union_find(m);
	auto safe = [&](ll i, ll j) -> bool {
		return T[i] > H[j];
	};
	for (ll j = 1; j < m; j++) {
		if (safe(n-1, j) && safe(n-1, j-1)) dsu.merge(j, j-1);
	}
}

bool can_reach(int L, int R, int S, int D) {
	ll m = R + 1;
	return dsu.find(S) == dsu.find(D);
}

#ifdef TEST
#include "grader.cpp"
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...