#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
int n;
pair<int,int> p[100005];
int ord[100005];
bool seen[100005];
const pair<int,int> origin = make_pair(0,0);
long long det(const pair<int,int> &a,const pair<int,int> &b,const pair<int,int> &c){
return 1LL * a.first * (b.second - c.second) + 1LL * b.first * (c.second - a.second) + 1LL * c.first * (a.second - b.second);
}
pair<int,int> dir;
pair<int,int> nxt_dir;
struct segm_t{
int i,j;
long long a,b,c;
segm_t(int i,int j){
this->i = i;
this->j = j;
a = p[j].second - p[i].second;
b = p[i].first - p[j].first;
c = 1LL * p[j].first * p[i].second - 1LL * p[i].first * p[j].second;
}
bool operator < (const segm_t &other)const{
///-c/(a * dir.first + b * dir.second) < -other.c / (other.a * dir.first + other.b * dir.second);
int sgn = (a * dir.first + b * dir.second > 0 ? 1:-1) * (other.a * dir.first + other.b * dir.second > 0 ? 1:-1);
long long fst = sgn * c * (other.a * dir.first + other.b * dir.second);
long long snd = sgn * other.c * (a * dir.first + b * dir.second);
if(fst != snd){
return fst > snd;
}
else{
pair<int,int> dir = nxt_dir;
int sgn = (a * dir.first + b * dir.second > 0 ? 1:-1) * (other.a * dir.first + other.b * dir.second > 0 ? 1:-1);
long long fst = sgn * c * (other.a * dir.first + other.b * dir.second);
long long snd = sgn * other.c * (a * dir.first + b * dir.second);
if(fst != snd){
return fst > snd;
}
else{
return 1LL * p[j].second * p[j].second + 1LL * p[j].first * p[j].first < 1LL * p[other.j].first * p[other.j].first + 1LL * p[other.j].second * p[other.j].second;
}
}
}
bool is_good(const int &point)const{
return det(p[i],p[j],p[point]) >= 0;
}
};
set<segm_t> s;
bool cmp(const int &a,const int &b){
return det(origin,p[a],p[b]) > 0;
}
int main(){
scanf("%d",&n);
for(int i = 1;i <= n;i++){
scanf("%d %d",&p[i].first,&p[i].second);
ord[i] = i;
}
sort(ord + 1,ord + 1 + n,cmp);
vector<int> ans;
for(int i = 1;i <= n;i++){
dir = p[ord[i]];
int j = i + 1;
while(j <= n && cmp(ord[i],ord[j]) == 0){
j++;
}
j--;
nxt_dir = p[ord[j + 1]];
for(int k = i;k <= j;k++){
int curr = ord[k];
int ant = (curr == 1 ? n:curr - 1);
int nxt = (curr == n ? 1:curr + 1);
///TODO check colinearity of curr,nxt,ant to not erase stuff twice or smth
if(seen[ant]){
s.erase(segm_t(ant,curr));
}
else{
}
if(seen[nxt]){
s.erase(segm_t(nxt,curr));
}
else{
}
}
for(int k = i;k <= j;k++){
int curr = ord[k];
int ant = (curr == 1 ? n:curr - 1);
int nxt = (curr == n ? 1:curr + 1);
///TODO check colinearity of curr,nxt,ant to not erase stuff twice or smth
if(seen[ant]){
}
else{
s.insert(segm_t(curr,ant));
}
if(seen[nxt]){
}
else{
s.insert(segm_t(curr,nxt));
}
}
int closest = -1;
for(int k = i;k <= j;k++){
if(closest == -1 || p[ord[k]].first < p[closest].first){
closest = ord[k];
}
}
if(s.empty() == true){
ans.push_back(closest);
}
else{
if(s.begin()->is_good(closest)){
ans.push_back(closest);
}
}
for(int k = i;k <= j;k++){
seen[ord[k]] = true;
}
i = j;
}
printf("%d\n",(int)ans.size());
sort(ans.begin(),ans.end());
for(auto it:ans){
printf("%d ",it);
}
return 0;
}
Compilation message
circuit.cpp: In function 'int main()':
circuit.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
circuit.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&p[i].first,&p[i].second);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Incorrect |
11 ms |
1280 KB |
Output isn't correct |
6 |
Incorrect |
10 ms |
1152 KB |
Output isn't correct |
7 |
Incorrect |
21 ms |
2176 KB |
Output isn't correct |
8 |
Incorrect |
8 ms |
896 KB |
Output isn't correct |
9 |
Incorrect |
6 ms |
896 KB |
Output isn't correct |
10 |
Incorrect |
11 ms |
1152 KB |
Output isn't correct |
11 |
Incorrect |
11 ms |
1152 KB |
Output isn't correct |
12 |
Correct |
12 ms |
768 KB |
Output is correct |
13 |
Incorrect |
30 ms |
2424 KB |
Output isn't correct |
14 |
Correct |
28 ms |
1280 KB |
Output is correct |
15 |
Correct |
29 ms |
1536 KB |
Output is correct |
16 |
Correct |
58 ms |
2808 KB |
Output is correct |
17 |
Execution timed out |
139 ms |
8944 KB |
Time limit exceeded |
18 |
Execution timed out |
24 ms |
2808 KB |
Time limit exceeded (wall clock) |
19 |
Execution timed out |
37 ms |
2808 KB |
Time limit exceeded (wall clock) |
20 |
Execution timed out |
111 ms |
7676 KB |
Time limit exceeded |