CSES - Aalto Competitive Programming 2024 - wk10 - Mon - Results
Submission details
Task:Point in Polygon
Sender:Nallue
Submission time:2024-11-11 17:06:33 +0200
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#10.01 sdetails
#20.02 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#70.00 sdetails
#8ACCEPTED0.00 sdetails
#90.00 sdetails
#100.00 sdetails
#110.00 sdetails
#120.00 sdetails
#130.00 sdetails

Compiler report

input/code.cpp: In function 'int crossings(std::pair<long long int, long long int>, const std::vector<std::pair<long long int, long long int> >&)':
input/code.cpp:22:17: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
   22 |         if( (y1 <= y <y2) and (x-x1) * (y2 - y1) == (x2 -x1) * (y - y1)) return 2;
      |              ~~~^~~~
input/code.cpp:24:17: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
   24 |         if( (y1 <= y <y2) and (x-x1) * (y2 - y1) < (x2 -x1) * (y - y1)){
      |              ~~~^~~~

Code

#include <iostream>
#include <vector>

using namespace std;

#define ll long long

int crossings(pair<ll,ll> point, const vector<pair<ll,ll>>& poli){
    ll x = point.first;
    ll y = point.second;
    ll n = poli.size();

    ll crossings = 0;

    for(int i=0; i<n; i++){
        ll x1 = poli[i].first;
        ll y1 = poli[i].second;

        ll x2 = poli[ (i+1) % n].first;
        ll y2 = poli[ (i+1) % n].second;

        if( (y1 <= y <y2) and (x-x1) * (y2 - y1) == (x2 -x1) * (y - y1)) return 2;

        if( (y1 <= y <y2) and (x-x1) * (y2 - y1) < (x2 -x1) * (y - y1)){
            crossings += 1;
        }

    }

    if(crossings%2==1) return 0;


    return 1;
}

int main(){

    int n,m;

    cin >> n >> m;

    vector<pair<ll,ll>> poli(n);

    for(int i=0; i<n; i++){
        ll a,b;
        cin >> a >> b;
        poli[i] = make_pair(a,b);
    }

    for(int i=0; i<m; i++){
        ll a,b;
        cin >> a >> b;
        int cross = crossings(make_pair(a,b), poli);
        if(cross==0)cout << "OUTSIDE" << endl;
        else if (cross==1)cout << "INSIDE" << endl;
        else cout << "BOUNDARY" << endl;
    }


}

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
OUTSIDE
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
OUTSIDE
INSIDE
INSIDE
INSIDE
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: ACCEPTED

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

correct output
INSIDE

user output
INSIDE

Test 6

Verdict: ACCEPTED

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

correct output
INSIDE

user output
INSIDE

Test 7

Verdict:

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

correct output
INSIDE
BOUNDARY
OUTSIDE
BOUNDARY

user output
INSIDE
BOUNDARY
INSIDE
INSIDE

Test 8

Verdict: ACCEPTED

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

correct output
INSIDE

user output
INSIDE

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:

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

correct output
INSIDE

user output
OUTSIDE

Test 12

Verdict:

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

correct output
INSIDE

user output
OUTSIDE

Test 13

Verdict:

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

correct output
INSIDE

user output
OUTSIDE