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 "trilib.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, marc(n + 1, -1);
for( int i = 1; i <= n; i++ ) v.push_back(i);
shuffle( v.begin(), v.end(), rng );
resp.push_back(v[0]);
ordena(v, resp);
for( int i = 0; i < n; i++ ) resp.push_back(resp[i]);
vector<int> hull;
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( marc[hull[i]] == -1 ){ marc[hull[i]] = i; continue; }
give_answer(i - marc[hull[i]]); break;
}
}
Compilation message (stderr)
tri.cpp: In function 'void ordena(std::vector<int>&, std::vector<int>&)':
tri.cpp:22:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for( int i = 2; i < v.size(); i++ ){
| ~~^~~~~~~~~~
tri.cpp: In function 'int main()':
tri.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for( int i = 0; i < hull.size() - 1; i++ ){
| ~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |