# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
120342 | tmwilliamlin168 | Printed Circuit Board (CEOI12_circuit) | C++14 | 43 ms | 4608 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>
using namespace std;
#define ll long long
const int mxN=2e5;
int n, l, r;
ll x[mxN+1], y[mxN+1];
vector<int> v, s;
bool b[mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
auto cp=[](int a, int b, int c) {
return (y[c]-y[a])*(x[b]-x[a])-(y[b]-y[a])*(x[c]-x[a]);
};
cin >> n;
for(int i=0; i<n; ++i) {
cin >> x[i] >> y[i];
if(!i||cp(n, l, i)>0||!cp(n, l, i)&&x[i]<x[l])
l=i;
if(!i||cp(n, r, i)<0||!cp(n, r, i)&&x[i]<x[r])
r=i;
}
int ic=cp((l+n-1)%n, l, (l+1)%n)>0?1:n-1;
for(; l^r; l=(l+ic)%n)
v.push_back(l);
v.push_back(r);
s={0, 1};
for(int i=2; i<v.size(); ++i) {
auto updLeft=[&]() {
while(cp(n, v[s.back()], v[i])>=0&&cp(v[i-1], v[i], v[s.back()])<=0)
s.pop_back();
for(int j=i, c=cp(n, v[s.back()], v[i])<0; cp(n, v[s.back()], v[i])>=0||!c; ++i) {
if(i^j?cp(n, v[j], v[i])>=0&&cp(n, v[j], v[i+1])<0&&cp(v[i], v[i+1], v[j])>0:cp(n, v[i], v[i+1])<0&&cp(v[i-1], v[i], v[i+1])>0)
++c;
if(cp(n, v[j], v[i])<0&&cp(n, v[j], v[i+1])>=0&&cp(v[i], v[i+1], v[j])<0)
--c;
}
};
auto escapeRight=[&]() {
while(cp(n, v[s.back()], v[i])<=0)
++i;
s.pop_back();
updLeft();
};
if(cp(n, v[i-1], v[i])<0) {
if(cp(n, v[i-2], v[i-1])>0&&cp(v[i-2], v[i-1], v[i])<0)
escapeRight();
} else if(cp(n, v[i-1], v[i])>0) {
if(cp(n, v[i-2], v[i-1])<0&&cp(v[i-2], v[i-1], v[i])>0)
while(cp(n, v[s.back()], v[i])>=0)
++i;
else
updLeft();
}
else {
if((cp(n, v[i-2], v[i-1])<0)==(cp(v[i-2], v[i-1], v[i])<0))
s.pop_back();
else if(cp(n, v[i-2], v[i-1])<0)
while(cp(n, v[s.back()], v[i])>=0)
++i;
else
escapeRight();
}
s.push_back(i);
}
cout << s.size() << "\n";
for(int a : s)
b[v[a]]=1;
for(int i=0; i<n; ++i)
if(b[i])
cout << i+1 << " ";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |