| Task: | Point in Polygon |
| Sender: | Isak |
| Submission time: | 2025-11-10 17:39:07 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | details |
| #2 | WRONG ANSWER | 0.02 s | details |
| #3 | ACCEPTED | 0.00 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | ACCEPTED | 0.00 s | details |
| #6 | ACCEPTED | 0.00 s | details |
| #7 | ACCEPTED | 0.00 s | details |
| #8 | ACCEPTED | 0.00 s | details |
| #9 | ACCEPTED | 0.00 s | details |
| #10 | ACCEPTED | 0.00 s | details |
| #11 | ACCEPTED | 0.00 s | details |
| #12 | ACCEPTED | 0.00 s | details |
| #13 | ACCEPTED | 0.00 s | details |
| #14 | UNKNOWN | -- | details |
Code
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <complex.h>
#include <limits.h>
typedef struct {
long x;
long y;
} coord;
#define cross(a,b) ( (a).x*(b).y-(b).x*(a).y )
#define minus(a,b) ((coord) {(a).x-(b).x, (a).y-(b).y})
#define plus(a,b) ((coord) {(a).x+(b).x, (a).y+(b).y})
#define dot(a,b) ((a).x*(b).x + (a).y*(b).y)
#define ceq(a,b) ((a).x == (b).x && (a).y == (b).y)
#define min(a,b) ((a)<(b)? (a) : (b))
#define max(a,b) ((a)>(b)? (a) : (b))
#define LOOP(i,s,e) for (uint64_t i = (s); i < (e); i++)
#define SCAN(...) if (scanf(__VA_ARGS__) == 0) return EXIT_FAILURE
coord *poly;
uint64_t edges;
bool intersect(coord a, coord b, coord c, coord d){
if (ceq(a,c) || ceq(a,d) || ceq(b,c) || ceq(b,d))
return true;
coord ab = minus(b,a);
coord ac = minus(c,a);
coord ad = minus(d,a);
coord cd = minus(d,c);
if (cross(ab, cd) == 0 && cross(ab, ac) == 0){
// printf("same line !\n");
long abc = dot(ab, ac);
long abd = dot(ab, ad);
long abb = dot(ab, ab);
return (0 <= abc && abc <= abb) || (0 <= abd && abd <= abb) || (min(abc, abd) <= 0 && abb <= max(abc, abd));
}
coord ca = minus(a, c);
coord cb = minus(b, c);
long abc = cross(ab, ac);
long abd = cross(ab, ad);
long cda = cross(cd, ca);
long cdb = cross(cd, cb);
// printf("abc:%d, abd:%d, cda:%d, cdb:%d\n", abc, abd, cda, cdb);
return
(abc == 0 || abd == 0 || ((abc ^ abd) & LONG_MIN) == LONG_MIN) &
(cda == 0 || cdb == 0 || ((cda ^ cdb) & LONG_MIN) == LONG_MIN);
}
bool boundary(coord a){
LOOP(i, 0, edges){
coord ba = minus(a, poly[i]);
coord bc = minus(poly[i+1], poly[i]);
if (cross(ba,bc) == 0){
long bac = dot(ba, bc);
long bcc = dot(bc, bc);
if (bac >= 0 && bac <= bcc){
return true;
}
}
}
return false;
}
bool inside(coord p){
int64_t acc = 0;
coord far_point = {4294967295, 1};
LOOP(i, 0, edges){
if (intersect(p, far_point, poly[i], poly[i+1])){
acc++;
}
}
return (acc%2==1);
}
int main() {
uint64_t m;
SCAN("%ld %ld", &edges, &m);
poly = (coord*) malloc((edges+1) * sizeof(coord));
LOOP(i, 0, edges)
SCAN("%ld %ld", &poly[i].x, &poly[i].y);
poly[edges] = poly[0];
coord p;
LOOP(i, 0, m){
SCAN("%ld %ld", &p.x, &p.y);
if (boundary(p)){
printf("BOUNDARY\n");
} else if (inside(p)){
printf("INSIDE\n");
} else {
printf("OUTSIDE\n");
}
}
return EXIT_SUCCESS;
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 100 1000 -7 -19 91 77 100 100 64 60 ... |
| correct output |
|---|
| INSIDE OUTSIDE INSIDE INSIDE INSIDE ... |
| user output |
|---|
| INSIDE OUTSIDE INSIDE INSIDE INSIDE ... |
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 1000 1000 365625896 -113418831 278762563 38777445 250367343 -96991975 175866909 -129766978 ... |
| correct output |
|---|
| OUTSIDE OUTSIDE INSIDE OUTSIDE OUTSIDE ... |
| user output |
|---|
| OUTSIDE INSIDE OUTSIDE OUTSIDE OUTSIDE ... |
Feedback: Incorrect character on line 2 col 1: expected "OUTSIDE", got "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: ACCEPTED
| input |
|---|
| 4 4 0 0 3 0 3 4 0 4 ... |
| correct output |
|---|
| INSIDE BOUNDARY OUTSIDE BOUNDARY |
| user output |
|---|
| INSIDE BOUNDARY 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: ACCEPTED
| input |
|---|
| 3 1 -100000 0 -999999999 -1000000000 1000 1000 0 0 |
| correct output |
|---|
| INSIDE |
| user output |
|---|
| INSIDE |
Test 12
Verdict: ACCEPTED
| input |
|---|
| 4 1 -4 1 -6 1 -6 -1 -4 -1 ... |
| correct output |
|---|
| INSIDE |
| user output |
|---|
| INSIDE |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 3 1 0 10 0 -10 10 0 1 0 |
| correct output |
|---|
| INSIDE |
| user output |
|---|
| INSIDE |
Test 14
Verdict: UNKNOWN
| input |
|---|
| 3 1000 -536621709 -536621709 955833081 955833081 -1 1 -439278425 -439278425 ... |
| correct output |
|---|
| BOUNDARY BOUNDARY BOUNDARY BOUNDARY BOUNDARY ... |
| user output |
|---|
| (not available) |
