| Task: | Line Segment Intersection |
| Sender: | aalto26jh_011 |
| Submission time: | 2026-11-09 14:15:21 +0200 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.40 s | details |
| #2 | ACCEPTED | 0.40 s | details |
| #3 | ACCEPTED | 0.51 s | details |
| #4 | ACCEPTED | 0.53 s | details |
| #5 | ACCEPTED | 0.04 s | details |
| #6 | ACCEPTED | 0.04 s | details |
Code
import sys
def main():
n = int(input())
for _ in range(n):
x1, y1, x2, y2, x3, y3, x4, y4 = map(int, input().split())
a1, b1 = y2 - y1, x1 - x2
a2, b2 = y4 - y3, x3 - x4
c1 = x1 * a1 + y1 * b1
c2 = x3 * a2 + y3 * b2
def get_val(a,b, xp, yp):
return xp*b + yp *(-a)
r1 = sorted([get_val(a1,b1, x1, y1), get_val(a1,b1, x2, y2)])
r2 = sorted([get_val(a2,b2, x3, y3), get_val(a2,b2, x4, y4)])
d = a1 * b2 - a2 * b1
if d==0: # parallel
# if c1 /a1 == c2 /a2:
r12 = sorted([get_val(a1,b1, x3, y3), get_val(a1,b1, x4, y4)])
if c1 *a2 == c2 *a1:
if (r1[0] <= r12[0] <= r1[1] or r1[0] <= r12[1] <= r1[1] or r12[0] <= r1[0] <= r12[1]):
print("YES")
else:
print("NO")
continue
else:
print("NO")
continue
x = (c1 * b2 - c2 * b1) / d
y = (a1 * c2 - a2 * c1) / d
# def check_line(xl1, yl1, xl2, yl2):
r = get_val(a1, b1, x,y)
if not r1[0] <= r <= r1[1]:
print("NO")
continue
r = get_val(a2, b2, x,y)
if not r2[0] <= r <= r2[1]:
print("NO")
continue
print("YES")
main()Test details
Test 1
Verdict: WRONG ANSWER
| 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 |
|---|
| NO NO NO NO NO ... |
Feedback: Incorrect character on line 860 col 1: expected "NO", got "YES"
Test 2
Verdict: ACCEPTED
| input |
|---|
| 100000 81 745 -967 768 -451 -490 -454... |
| correct output |
|---|
| NO NO YES NO YES ... |
| user output |
|---|
| NO NO YES NO YES ... |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 100000 492853 -452834 -657156 -282543... |
| correct output |
|---|
| YES YES NO YES YES ... |
| user output |
|---|
| YES YES NO YES YES ... |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 100000 788522666 939776556 -831492125... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
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 |
