이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |