Submission #917885

#TimeUsernameProblemLanguageResultExecution timeMemory
917885NK_Triangles (CEOI18_tri)C++17
20 / 100
1 ms348 KiB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
#include "trilib.h"

using namespace std;

#define nl '\n'
#define pb push_back
#define sz(x) int(x.size())

template<class T> using V = vector<T>;
using vi = V<int>;

mt19937 rng(1008);

// g++-13 -O2 trilib.cpp A.cpp -std=c++17 -o ./G
int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N = get_n();

	vi P(N); iota(begin(P), end(P), 0);
	shuffle(begin(P), end(P), rng);

	auto ask = [&](int a, int b, int c) {
		if (a == b || b == c || a == c) return 0;
		return is_clockwise(P[a] + 1, P[b] + 1, P[c] + 1);
	};

	function<vi(vi)> dnc = [&](vi A) {
		if (sz(A) <= 1) return A;

		int M = A[rng() % sz(A)]; vi L, R;

		for(auto& x : A) if (x != M) {
			if (!ask(0, M, x)) L.pb(x);
			else R.pb(x);
		}

		L = dnc(L); R = dnc(R);

		L.pb(M);
		L.insert(end(L), begin(R), end(R));

		return L;
	};

	vi A(N - 1); iota(begin(A), end(A), 1);

	A = dnc(A); A.pb(0);

	auto fix = [&](vi A) {
		vi C = {A[0]};
		for(int i = 1; i < sz(A); i++) {
			while(sz(C) >= 2 && !ask(C[sz(C) - 2], C[sz(C) - 1], A[i])) C.pop_back();
			C.pb(A[i]);
		}

		return C;
	};

	for(int i = 0; i < 5; i++) {
		// cout << i << endl;
		A = fix(A);
		// for(auto& x : A) cout << x << " ";
		// cout << endl;
		int rot = rng() % sz(A);
		rotate(begin(A), begin(A) + rot, end(A));
	}

	give_answer(sz(A));

	exit(0-0);
}
#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...