Task: | Point in Polygon |
Sender: | laluj |
Submission time: | 2024-11-11 17:26:17 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.01 s | details |
#2 | WRONG ANSWER | 0.04 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | WRONG ANSWER | 0.00 s | details |
#6 | WRONG ANSWER | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | WRONG ANSWER | 0.01 s | details |
#9 | WRONG ANSWER | 0.00 s | details |
#10 | WRONG ANSWER | 0.00 s | details |
#11 | WRONG ANSWER | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
Code
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; }; bool onSegment(Point a, Point b, Point p) { return p.x <= max(a.x, b.x) && p.x >= min(a.x, b.x) && p.y <= max(a.y, b.y) && p.y >= min(a.y, b.y); } // Find the orientation of the triplet (a, b, c) // 0 -> a, b and c are collinear // 1 -> Clockwise // 2 -> Counterclockwise int orientation(Point a, Point b, Point c) { long long val = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y); if (val == 0) return 0; return (val > 0) ? 1 : 2; } // Check if two line segments intersect bool doIntersect(Point a, Point b, Point c, Point d) { int o1 = orientation(a, b, c); int o2 = orientation(a, b, d); int o3 = orientation(c, d, a); int o4 = orientation(c, d, b); if (o1 != o2 && o3 != o4) return true; if (o1 == 0 && onSegment(a, b, c)) return true; if (o2 == 0 && onSegment(a, b, d)) return true; if (o3 == 0 && onSegment(c, d, a)) return true; if (o4 == 0 && onSegment(c, d, b)) return true; return false; } // Check if a point is inside a polygon string pointInPolygon(Point point, const vector<Point>& polygon) { int n = polygon.size(); Point extreme = {LLONG_MAX, point.y}; int count = 0; for (int i = 0; i < n; i++) { Point next = polygon[(i + 1) % n]; if (doIntersect(polygon[i], next, point, extreme)) { if (orientation(polygon[i], next, point) == 0 && onSegment(polygon[i], next, point)) return "BOUNDARY"; count++; } } return (count % 2 == 1) ? "INSIDE" : "OUTSIDE"; } int main() { int n, m; cin >> n >> m; vector<Point> polygon(n); vector<Point> test_points(m); for (int i = 0; i < n; i++) { cin >> polygon[i].x >> polygon[i].y; } for (int i = 0; i < m; i++) { cin >> test_points[i].x >> test_points[i].y; } for (int i = 0; i < m; i++) { Point p = test_points[i]; cout << pointInPolygon(p, polygon) << endl; } return 0; }
Test details
Test 1
Verdict: WRONG ANSWER
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: WRONG ANSWER
input |
---|
1000 1000 365625896 -113418831 278762563 38777445 250367343 -96991975 175866909 -129766978 ... |
correct output |
---|
OUTSIDE OUTSIDE INSIDE OUTSIDE OUTSIDE ... |
user output |
---|
INSIDE OUTSIDE INSIDE OUTSIDE OUTSIDE ... |
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: WRONG ANSWER
input |
---|
4 1 1 100 2 50 1 20 0 50 ... |
correct output |
---|
INSIDE |
user output |
---|
OUTSIDE |
Test 6
Verdict: WRONG ANSWER
input |
---|
8 1 0 0 0 2 1 1 2 2 ... |
correct output |
---|
INSIDE |
user output |
---|
OUTSIDE |
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: WRONG ANSWER
input |
---|
6 1 0 0 0 2 3 1 2 2 ... |
correct output |
---|
INSIDE |
user output |
---|
OUTSIDE |
Test 9
Verdict: WRONG ANSWER
input |
---|
3 1 0 0 1 1000000000 -3 0 1 1 |
correct output |
---|
OUTSIDE |
user output |
---|
INSIDE |
Test 10
Verdict: WRONG ANSWER
input |
---|
3 1 -100000 0 -1000000000 -999999999 1000000000 1000000000 0 0 |
correct output |
---|
OUTSIDE |
user output |
---|
INSIDE |
Test 11
Verdict: WRONG ANSWER
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: ACCEPTED
input |
---|
3 1 0 10 0 -10 10 0 1 0 |
correct output |
---|
INSIDE |
user output |
---|
INSIDE |