CSES - Aalto Competitive Programming 2024 - wk10 - Mon - Results
Submission details
Task:Point in Polygon
Sender:htoik
Submission time:2024-11-11 17:36:05 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.01 sdetails
#20.01 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#60.00 sdetails
#70.00 sdetails
#80.00 sdetails
#90.00 sdetails
#100.00 sdetails
#11ACCEPTED0.00 sdetails
#120.00 sdetails
#13ACCEPTED0.00 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int i=0; i<ps.size(); i++){
      |                      ~^~~~~~~~~~
input/code.cpp:57:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             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 = a - p;
    pt d2 = b - p;
    ll dp = dot(d1, d2);
    int r2 = (dp <= 0 && cross(d1,d2) == 0 ? 10 : 0);
    // if(r2){
    //     cout << "here: " << d1 << " " << d2 << " " << dp << " " << cross(d1,d2) << " " << r2 << "\n";
    // }
    return r + r2;
}

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 k=0; k<m; k++){
        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]);
            // cout << "this: " << i << " " << a << " " << b << endl;

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

        if(br)continue;
        cout << (ci % 2 ? "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
OUTSIDE
OUTSIDE
OUTSIDE
INSIDE
INSIDE
...
Truncated

Test 2

Verdict:

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

correct output
OUTSIDE
OUTSIDE
INSIDE
OUTSIDE
OUTSIDE
...

user output
OUTSIDE
INSIDE
OUTSIDE
INSIDE
OUTSIDE
...
Truncated

Test 3

Verdict:

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

correct output
INSIDE

user output
OUTSIDE

Test 4

Verdict:

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

correct output
OUTSIDE

user output
INSIDE

Test 5

Verdict:

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

correct output
INSIDE

user output
BOUNDARY

Test 6

Verdict:

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

correct output
INSIDE

user output
BOUNDARY

Test 7

Verdict:

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

correct output
INSIDE
BOUNDARY
OUTSIDE
BOUNDARY

user output
OUTSIDE
BOUNDARY
INSIDE
BOUNDARY

Test 8

Verdict:

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

correct output
INSIDE

user output
OUTSIDE

Test 9

Verdict:

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

correct output
OUTSIDE

user output
INSIDE

Test 10

Verdict:

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

correct output
OUTSIDE

user output
INSIDE

Test 11

Verdict: ACCEPTED

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

correct output
INSIDE

user output
INSIDE

Test 12

Verdict:

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

correct output
INSIDE

user output
OUTSIDE

Test 13

Verdict: ACCEPTED

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

correct output
INSIDE

user output
INSIDE