제출 #917891

#제출 시각아이디문제언어결과실행 시간메모리
917891NK_Triangles (CEOI18_tri)C++17
20 / 100
1 ms504 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(108);

// 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(a + 1, b + 1, 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.insert(begin(A), 0);

	// for(auto& x : A) cout << x << " ";
	// cout << endl;

	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 < 3; i++) {
		// cout << i << endl;
		A = fix(A);
		// for(auto& x : A) cout << x << " ";
		// cout << endl;
		rotate(begin(A), begin(A) + 2, 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...