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"
using namespace std;
int root;
bool cmp(int x, int y){
return is_clockwise(root, x, y);
}
vector<int> getstv(vector<int> v, int st, int en){
root = st;
sort(v.begin(), v.end(), cmp);
vector<int> stv;
stv.push_back(st);
for(auto x: v){
while(stv.size() > 1 && is_clockwise(stv.end()[-2], stv.end()[-1], x) == false)
stv.pop_back();
stv.push_back(x);
}
return stv;
}
mt19937 rng(time(0));
int main(){
int n = get_n();
int a = rng()%(n - 1) + 1;
int b = rng()%(n - 1) + 1;
while(b == a)
b = rng()%(n - 1) + 1;
vector<int> l, r;
for(int i = 1; i<= n; i++){
if(i == a)
continue;
if(i == b)
continue;
if(is_clockwise(a, b, i) == false)
l.push_back(i);
else
r.push_back(i);
}
///L ARE ORDINEA DE LA A LA B, R DE LA B LA A
vector<int> stvl = getstv(l, a, b);
vector<int> stvr = getstv(r, b, a);
vector<int> stv = stvl;
for(auto x: stvr){
while(stv.size() > 1 && (is_clockwise(stv.end()[-2], stv.end()[-1], x) == false))
stv.pop_back();
stv.push_back(x);
}
for(auto x: stvl){
while(stv.size() > 1 && (is_clockwise(stv.end()[-2], stv.end()[-1], x) == false))
stv.pop_back();
stv.push_back(x);
}
for(auto x: stvr){
while(stv.size() > 1 && (is_clockwise(stv.end()[-2], stv.end()[-1], x) == false))
stv.pop_back();
stv.push_back(x);
}
vector<int> lap(n + 1, -1);
int ans =INT_MAX;
int pz = 0;
for(auto x: stv){
if(lap[x] != -1)
ans = min(ans, pz - lap[x]);
lap[x] = pz;
pz++;
}
give_answer(ans);
}
# | 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... |