#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];
ll cp(int a, int b, int c) {
return (y[c]-y[a])*(x[b]-x[a])-(y[b]-y[a])*(x[c]-x[a]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
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);
//cout << "a" << endl;
//for(int i : v)
//cout << x[i] << " " << y[i] << endl;
s={0, 1};
for(int i=2; i<v.size(); ++i) {
//cout << i << endl;
//for(int si : s)
//cout << si << " ";
//cout << endl;
if(cp(n, v[i-1], v[i])<0) {
if((cp(n, v[s.back()-1], v[s.back()])<=0||cp(v[s.back()-1], v[s.back()], v[i])>0)&&cp(n, v[s.back()], v[i])<0)
s.push_back(i);
} else {
if(s.back()==i-1) {
if(cp(n, v[i-2], v[i-1])<0?cp(v[i-2], v[i-1], v[i])>0:!cp(n, v[s.back()], v[i])&&cp(v[i-2], v[i-1], v[i])<0)
continue;
s.pop_back();
} else if(s.back()&&cp(n, v[s.back()-1], v[s.back()])>=0) {
if(cp(n, v[s.back()], v[i])<=0)
continue;
s.pop_back();
}
while(cp(n, v[i], v[s.back()])<=0&&cp(v[i], v[i-1], v[s.back()])>0)
s.pop_back();
if(cp(n, v[i], v[s.back()])>0)
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
circuit.cpp: In function 'int main()':
circuit.cpp:23:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if(!i||cp(n, l, i)>0||!cp(n, l, i)&&x[i]<x[l])
~~~~~~~~~~~~^~~~~~~~~~~
circuit.cpp:25:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if(!i||cp(n, r, i)<0||!cp(n, r, i)&&x[i]<x[r])
~~~~~~~~~~~~^~~~~~~~~~~
circuit.cpp:36:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=2; i<v.size(); ++i) {
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Correct |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Incorrect |
4 ms |
512 KB |
Output isn't correct |
6 |
Incorrect |
4 ms |
512 KB |
Output isn't correct |
7 |
Incorrect |
6 ms |
768 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
512 KB |
Output isn't correct |
9 |
Correct |
4 ms |
640 KB |
Output is correct |
10 |
Incorrect |
4 ms |
640 KB |
Output isn't correct |
11 |
Incorrect |
5 ms |
640 KB |
Output isn't correct |
12 |
Incorrect |
5 ms |
896 KB |
Output isn't correct |
13 |
Incorrect |
9 ms |
1056 KB |
Output isn't correct |
14 |
Incorrect |
9 ms |
1280 KB |
Output isn't correct |
15 |
Incorrect |
12 ms |
1556 KB |
Output isn't correct |
16 |
Incorrect |
21 ms |
2560 KB |
Output isn't correct |
17 |
Incorrect |
22 ms |
2300 KB |
Output isn't correct |
18 |
Incorrect |
39 ms |
4724 KB |
Output isn't correct |
19 |
Incorrect |
68 ms |
4596 KB |
Output isn't correct |
20 |
Incorrect |
49 ms |
4724 KB |
Output isn't correct |