# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
954942 | hyakup | Triangles (CEOI18_tri) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <random>
using namespace std;
// int get_n(){
// cout << "N: " << endl;
// int x; cin >> x; return x;
// }
//
// bool is_clockwise( int a, int b, int c ){
// cout << a << " " << b << " "<< c << endl;
// int x; cin >> x; return x;
// }
//
// void give_answer( int x ){ cout << "RESP: " << x << endl; }
void ordena( vector<int>& v, vector<int>& resp ){
if( v.size() == 1 ) return;
vector<int> l, r;
l.push_back(v[0]); r.push_back(v[0]);
for( int i = 2; i < v.size(); i++ ){
if( is_clockwise( v[0], v[1], v[i] ) ) r.push_back(v[i]);
else l.push_back(v[i]);
}
ordena( l, resp ); resp.push_back(v[1]); ordena( r, resp );
}
int main(){
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n = get_n();
vector<int> v, resp;
for( int i = 1; i <= n; i++ ) v.push_back(i);
shuffle( v.begin(), v.end(), rng );
ordena(v, resp);
vector<int> hull; hull.push_back(v[0]);
for( int cur : resp ){
while( hull.size() >= 2 && !is_clockwise( hull[hull.size() - 2], hull.back(), cur ) ) hull.pop_back();
hull.push_back(cur);
}
for( int i = 0; i < hull.size() - 1; i++ ){
if( !is_clockwise(hull[i], hull[i + 1], hull.back()) ) continue;
give_answer((int)hull.size() - i); break;
}
}