| Task: | Line Segment Intersection |
| Sender: | aalto26jh_001 |
| Submission time: | 2026-11-06 12:59:51 +0200 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.49 s | details |
| #2 | ACCEPTED | 0.43 s | details |
| #3 | ACCEPTED | 0.44 s | details |
| #4 | ACCEPTED | 0.46 s | details |
| #5 | ACCEPTED | 0.04 s | details |
| #6 | ACCEPTED | 0.04 s | details |
Code
for t in range(int(input())):
a=list(map(int,input().split()))
c1= (a[2]-a[0])*(a[5]-a[1]) - (a[3]-a[1])*(a[4]-a[0])
c2= (a[2]-a[0])*(a[7]-a[1]) - (a[3]-a[1])*(a[6]-a[0])
c3= (a[6]-a[4])*(a[1]-a[5]) - (a[7]-a[5])*(a[0]-a[4])
c4= (a[6]-a[4])*(a[3]-a[5]) - (a[7]-a[5])*(a[2]-a[4])
if c1 > 0:
s1 = 1
elif c1<0:
s1= -1
else:
s1= 0
if c2> 0:
s2= 1
elif c2<0:
s2= -1
else:
s2=0
if c3 > 0:
s3 = 1
elif c3 < 0:
s3 = -1
else:
s3 = 0
if c4 > 0:
s4 = 1
elif c4 < 0:
s4 = -1
else:
s4 = 0
if s1!=s2 and s3!=s4:
print("YES")
elif s1==0 and min(a[0],a[2])<=a[4]<=max(a[0],a[2]) and min(a[1],a[3])<=a[5]<=max(a[1],a[3]):
print("YES")
elif s2==0 and min(a[0],a[2])<=a[6]<=max(a[0],a[2]) and min(a[1],a[3])<=a[7]<=max(a[1],a[3]):
print("YES")
elif s3==0 and min(a[4],a[6])<=a[0]<=max(a[4],a[6]) and min(a[5],a[7])<=a[1]<=max(a[5],a[7]):
print("YES")
elif s4==0 and min(a[4],a[6])<=a[2]<=max(a[4],a[6]) and min(a[5],a[7])<=a[3]<=max(a[5],a[7]):
print("YES")
else:
print("NO")Test details
Test 1
Verdict: ACCEPTED
| 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 ... |
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 |
