Task: | Point in Polygon |
Sender: | arnxxau |
Submission time: | 2024-11-11 17:00:32 +0200 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.18 s | details |
#2 | ACCEPTED | 0.22 s | details |
#3 | ACCEPTED | 0.04 s | details |
#4 | ACCEPTED | 0.05 s | details |
#5 | ACCEPTED | 0.04 s | details |
#6 | ACCEPTED | 0.04 s | details |
#7 | ACCEPTED | 0.04 s | details |
#8 | ACCEPTED | 0.04 s | details |
#9 | ACCEPTED | 0.04 s | details |
#10 | ACCEPTED | 0.04 s | details |
#11 | ACCEPTED | 0.04 s | details |
#12 | ACCEPTED | 0.05 s | details |
#13 | ACCEPTED | 0.04 s | details |
Code
class Point: def __init__(self, x, y): self.x = x self.y = y def cross(a, b, c): u = Point(b.x - a.x, b.y - a.y) v = Point(c.x - a.x, c.y - a.y) cp = u.x * v.y - u.y * v.x return cp def mid(a, b, c): if (c.x >= min(a.x, b.x) and c.x <= max(a.x, b.x) and c.y >= min(a.y, b.y) and c.y <= max(a.y, b.y)): cp = cross(a, b, c) if cp == 0: return True return False def check(a, b, c, d): cp1 = cross(a, b, c) cp2 = cross(a, b, d) cp3 = cross(c, d, a) cp4 = cross(c, d, b) if cp1 * cp2 < 0 and cp3 * cp4 < 0: return True if cp3 == 0 and mid(c, d, a) and cp4 < 0: return True if cp4 == 0 and mid(c, d, b) and cp3 < 0: return True return False inp = input().split(' ') n = int(inp[0]) m = int(inp[1]) vertices = [] for i in range(n): inp = input().split(' ') x = int(inp[0]) y = int(inp[1]) vertices.append(Point(x, y)) points = [] for i in range(m): inp = input().split(' ') x = int(inp[0]) y = int(inp[1]) points.append(Point(x, y)) polygon = vertices + [vertices[0]] INF = 10 ** 9 + 7 for point in points: cnt = 0 flag = 0 infinity = Point(INF, INF) for j in range(n): cp = cross(polygon[j], polygon[j + 1], point) if cp == 0 and mid(polygon[j], polygon[j + 1], point): flag = 1 break cnt += 1 if check(polygon[j], polygon[j + 1], point, infinity) else 0 if flag == 1: print("BOUNDARY") else: print("INSIDE" if cnt % 2 == 1 else "OUTSIDE")
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: ACCEPTED
input |
---|
1000 1000 365625896 -113418831 278762563 38777445 250367343 -96991975 175866909 -129766978 ... |
correct output |
---|
OUTSIDE OUTSIDE INSIDE OUTSIDE OUTSIDE ... |
user output |
---|
OUTSIDE 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: 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 |