CSES - Aalto Competitive Programming 2024 - wk10 - Mon - Results
Submission details
Task:Point in Polygon
Sender:htoik
Submission time:2024-11-11 17:17:19 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.01 sdetails
#20.01 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#50.00 sdetails
#60.00 sdetails
#70.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#110.00 sdetails
#12ACCEPTED0.00 sdetails
#130.00 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(int i=0; i<ps.size(); i++){
      |                      ~^~~~~~~~~~
input/code.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             pt b = (i == ps.size() -1 ? ps[0] : ps[i+1]);
      |                     ~~^~~~~~~~~~~~~~~

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

struct pt{ ll x; ll y; };
pt operator+(const pt& a, const pt& b){ return pt{.x=a.x+b.x, .y=a.y+b.y}; };
pt operator-(const pt& a, const pt& b){ return pt{.x=a.x-b.x, .y=a.y-b.y}; };
bool operator==(const pt& a, const pt& b){ return a.x == b.x && a.y == b.y; };
ostream& operator<<(ostream& os, const pt& a){ return os << "(" << a.x << "," << a.y << ")"; }
ll cross(pt p1, pt p2){
    return p1.x*p2.y - p1.y*p2.x;
}
ll orient(pt a, pt b, pt c) {
    return cross(b-a, c-a);
}
ll dot(pt a, pt b){
    return a.x*b.x+a.y*b.y;
}

int isintersect(pt p, pt a, pt b){
    if(a.y > b.y) swap(a.y, b.y);
    int r = a.x >= p.x && b.x >= p.x && a.y <= p.y && b.y >= p.y;
    pt d1 = p - a;
    pt d2 = p - b;
    ll dp = dot(d1, d2);
    return r + (dp < 0 && cross(d1,d2) == 0 ? 10 : 0);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n,m;
    cin >> n >> m;

    vector<pt> ps;
    ps.reserve(n);
    for(int i=0; i<n; i++){
        ll x, y;
        cin >> x >> y;
        ps.push_back({x,y});
    }

    for(int i=0; i<m; i++){
        pt p;
        cin >> p.x >> p.y;

        int ci = 0;
        int br = 0;
        for(int i=0; i<ps.size(); i++){
            pt a = ps[i];
            pt b = (i == ps.size() -1 ? ps[0] : ps[i+1]);

            auto r = (isintersect(p,a,b));
            ci += r;
            if(r > 1){
                cout << "BOUNDARY\n";
                br = 1;
                break;
            }
        }

        if(br)continue;
        cout << (ci % 2 == 0 ? "OUTSIDE" : "INSIDE") << "\n";
    }
}

Test details

Test 1

Verdict:

input
100 1000
-7 -19
91 77
100 100
64 60
...

correct output
INSIDE
OUTSIDE
INSIDE
INSIDE
INSIDE
...

user output
INSIDE
INSIDE
INSIDE
OUTSIDE
OUTSIDE
...

Test 2

Verdict:

input
1000 1000
365625896 -113418831
278762563 38777445
250367343 -96991975
175866909 -129766978
...

correct output
OUTSIDE
OUTSIDE
INSIDE
OUTSIDE
OUTSIDE
...

user output
INSIDE
OUTSIDE
INSIDE
OUTSIDE
INSIDE
...

Test 3

Verdict: ACCEPTED

input
4 1
1 5
5 5
5 1
1 1
...

correct output
INSIDE

user output
INSIDE

Test 4

Verdict: ACCEPTED

input
4 1
1 5
5 5
5 1
1 1
...

correct output
OUTSIDE

user output
OUTSIDE

Test 5

Verdict:

input
4 1
1 100
2 50
1 20
0 50
...

correct output
INSIDE

user output
OUTSIDE

Test 6

Verdict:

input
8 1
0 0
0 2
1 1
2 2
...

correct output
INSIDE

user output
OUTSIDE

Test 7

Verdict:

input
4 4
0 0
3 0
3 4
0 4
...

correct output
INSIDE
BOUNDARY
OUTSIDE
BOUNDARY

user output
INSIDE
INSIDE
OUTSIDE
BOUNDARY

Test 8

Verdict: ACCEPTED

input
6 1
0 0
0 2
3 1
2 2
...

correct output
INSIDE

user output
INSIDE

Test 9

Verdict: ACCEPTED

input
3 1
0 0
1 1000000000
-3 0
1 1

correct output
OUTSIDE

user output
OUTSIDE

Test 10

Verdict: ACCEPTED

input
3 1
-100000 0
-1000000000 -999999999
1000000000 1000000000
0 0

correct output
OUTSIDE

user output
OUTSIDE

Test 11

Verdict:

input
3 1
-100000 0
-999999999 -1000000000
1000 1000
0 0

correct output
INSIDE

user output
OUTSIDE

Test 12

Verdict: ACCEPTED

input
4 1
-4 1
-6 1
-6 -1
-4 -1
...

correct output
INSIDE

user output
INSIDE

Test 13

Verdict:

input
3 1
0 10
0 -10
10 0
1 0

correct output
INSIDE

user output
OUTSIDE