CSES - E4590 2016 1 - Results
Submission details
Task:Taxing
Sender:Ollie
Submission time:2016-09-17 14:28:12 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.05 sdetails
#3ACCEPTED0.06 sdetails
#4ACCEPTED0.05 sdetails
#5ACCEPTED0.06 sdetails

Compiler report

input/code.cpp: In function 'bool inPoly(point, const std::vector<point>&)':
input/code.cpp:53:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<P.size()-1;i++) {
                          ^
input/code.cpp: In function 'int main()':
input/code.cpp:78:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<P.size()-1;i++) {
                            ^

Code

#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(0);cin.tie();
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define vpii vector<pii>
#define ld long double
#define PI 3.14159265358979d

using namespace std;

struct point {
  ll x, y;
  point() { x = y = 0; }
  point(ll _x, ll _y) : x(_x), y(_y) {};
};

ll cross(point a, point b) {
  return a.x*b.y - a.y*b.x;
}

point toVec(point a, point b) {
  return point(b.x - a.x, b.y - a.y);
}

bool ccw(point p, point q, point r) {
  return cross(toVec(p, q), toVec(q, r)) > 0;
}

bool coll(point p, point q, point r) {
  return cross(toVec(p, q), toVec(q, r)) == 0;
}

ld dot(point a, point b) {
  return a.x*b.x+a.y*b.y;
}

ld norm_sq(point a) {
  return a.x*a.x+a.y*a.y;
}

ld angle(point a, point o, point b) {
  point oa = toVec(o, a);
  point ob = toVec(o, b);
  return acos(dot(oa, ob) / sqrt(norm_sq(oa)*norm_sq(ob)));
}

bool inPoly(point pt, const vector<point> &P) {
  if(P.size()==0) return false;
  ld sum = 0;
  for(int i=0;i<P.size()-1;i++) {
    if(ccw(pt, P[i], P[i+1]))
      sum += angle(P[i], pt, P[i+1]);
    else sum -= angle(P[i], pt, P[i+1]);
  }
  return fabs(fabs(sum)-2*PI) < 0.00001;
}

vector<point> P;

int main() { _
  int n;
  cin >> n;
  for(int i=0;i<n;i++) {
    int x, y;
    cin >> x >> y;
    P.pb(point(x,y));
  }
  P.pb(P[0]);
  int m;
  cin >> m;
  for(int i=0;i<m;i++) {
    int x,y;
    cin >> x >> y;
    bool skip=false;
    for(int i=0;i<P.size()-1;i++) {
      // line a -> b
      point a = P[i];
      point b = P[i+1];
      ll minx = min(a.x, b.x);
      ll maxx = max(a.x, b.x);
      ll miny = min(a.y, b.y);
      ll maxy = max(a.y, b.y);
      if(coll(a, b, point(x, y))
        && (x >= minx && x <= maxx && y >= miny && y <= maxy)) {
        cout << "border" << endl;
        skip=true;
        break;
      }
    }
    if(skip) continue;
    if(inPoly(point(x,y), P)) {
      cout << "inside" << endl;
    } else {
      cout << "outside" << endl;
    }
  }
  return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
9
0 10
-2 0
-1 -4
-7 1
...

correct output
inside
inside
inside
outside
inside
...

user output
inside
inside
inside
outside
inside
...

Test 2

Verdict: ACCEPTED

input
99
13 4
14 8
10 5
9 6
...

correct output
inside
border
inside
outside
inside
...

user output
inside
border
inside
outside
inside
...

Test 3

Verdict: ACCEPTED

input
99
50 33
28 57
80 28
37 60
...

correct output
outside
inside
outside
inside
outside
...

user output
outside
inside
outside
inside
outside
...

Test 4

Verdict: ACCEPTED

input
999
87 -3
91 5
77 -7
41 -18
...

correct output
inside
outside
inside
outside
outside
...

user output
inside
outside
inside
outside
outside
...

Test 5

Verdict: ACCEPTED

input
999
915887 494689
950720 189774
823677 443456
879821 402443
...

correct output
outside
outside
inside
inside
inside
...

user output
outside
outside
inside
inside
inside
...