| Task: | Line Segment Intersection |
| Sender: | aalto26jh_034 |
| Submission time: | 2026-11-10 16:52:45 +0200 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | TIME LIMIT EXCEEDED |
| test | verdict | time | |
|---|---|---|---|
| #1 | TIME LIMIT EXCEEDED | -- | details |
| #2 | TIME LIMIT EXCEEDED | -- | details |
| #3 | TIME LIMIT EXCEEDED | -- | details |
| #4 | TIME LIMIT EXCEEDED | -- | details |
| #5 | ACCEPTED | 0.04 s | details |
| #6 | ACCEPTED | 0.04 s | details |
Code
import sys
def cross(a, b, c):
return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])
def on_segment(a, b, p):
return (min(a[0], b[0]) <= p[0] <= max(a[0], b[0]) and
min(a[1], b[1]) <= p[1] <= max(a[1], b[1]) and
cross(a, b, p) == 0)
def sign(x):
return (x > 0) - (x < 0)
def solve():
input_data = sys.stdin.read().split()
if not input_data:
return
t = int(input_data[0])
idx = 1
out = []
for _ in range(t):
x1, y1, x2, y2, x3, y3, x4, y4 = map(int, input_data[idx:idx+8])
idx += 8
a, b, c, d = (x1, y1), (x2, y2), (x3, y3), (x4, y4)
cp1, cp2 = cross(a, b, c), cross(a, b, d)
cp3, cp4 = cross(c, d, a), cross(c, d, b)
if sign(cp1) * sign(cp2) < 0 and sign(cp3) * sign(cp4) < 0:
out.append("YES")
elif on_segment(a, b, c) or on_segment(a, b, d) or \
on_segment(c, d, a) or on_segment(c, d, b):
out.append("YES")
else:
out.append("NO")
print('\n'.join(out))
if __name__ == '__main__':
solve()Test details
Test 1
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 9 7 1 8 8 -5 0 2 10 1 -1 2 -4 1 -7 3 10 2 -8 6 1 2 2 -1 -10 1 9 -7 4 -3 -5 0 ... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| (empty) |
Test 2
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 81 745 -967 768 -451 -490 -454... |
| correct output |
|---|
| NO NO YES NO YES ... |
| user output |
|---|
| (empty) |
Test 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 492853 -452834 -657156 -282543... |
| correct output |
|---|
| YES YES NO YES YES ... |
| user output |
|---|
| (empty) |
Test 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 788522666 939776556 -831492125... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| (empty) |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 1 1 6 6 6 4 4 1000000000 1000000... |
| correct output |
|---|
| YES |
| user output |
|---|
| YES |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 1 -1000000000 1000000000 9999999... |
| correct output |
|---|
| NO |
| user output |
|---|
| NO |
