| Task: | Line Segment Intersection |
| Sender: | aalto26jh_021 |
| Submission time: | 2026-11-06 00:36:54 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.08 s | details |
| #2 | WRONG ANSWER | 0.09 s | details |
| #3 | WRONG ANSWER | 0.10 s | details |
| #4 | WRONG ANSWER | 0.12 s | details |
| #5 | WRONG ANSWER | 0.00 s | details |
| #6 | WRONG ANSWER | 0.00 s | details |
Code
#include <bits/stdc++.h>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef long long C;
typedef complex<C> P;
#define X real()
#define Y imag()
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0);
C cross(P a, P b) { return (conj(a) * b).Y; }
C pointLocToLine(P point, P line1, P line2) {
return cross(point - line1, point - line2);
}
bool isPointOnLine(P point, P line1, P line2) {
return pointLocToLine(point, line1, line2) == 0;
}
bool noOverlap(P a, P b, P c, P d) {
auto lessP = [](const P &p, const P &q) {
return make_pair(p.X, p.Y) < make_pair(q.X, q.Y);
};
if (lessP(b, a))
swap(a, b); // a <= b
if (lessP(d, c))
swap(c, d); // c <= d
return lessP(b, c) || lessP(d, a);
}
int main() {
FAST;
int n;
cin >> n;
for (int dc = 0; dc < n; dc++) {
C x1, y1, x2, y2, x3, y3, x4, y4;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
P a = {x1, y1};
P b = {x2, y2};
P c = {x3, y3};
P d = {x4, y4};
// Case 1 - All on same line
bool case1 = isPointOnLine(a, c, d) && isPointOnLine(b, c, d) &&
!noOverlap(a, b, c, d);
// Case 2 - Common Verex
bool case2 = a == c || a == d || b == c || b == d;
// Case 3 - Single point intersection
bool case3 = (pointLocToLine(a, c, d) ^ pointLocToLine(b, c, d)) < 0;
cout << (case1 || case2 || case3 ? "YES" : "NO") << "\n";
}
return 0;
}
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 YES NO NO ... |
Feedback: Incorrect character on line 3 col 1: expected "NO", got "YES"
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 100000 81 745 -967 768 -451 -490 -454... |
| correct output |
|---|
| NO NO YES NO YES ... |
| user output |
|---|
| YES NO YES NO YES ... |
Feedback: Incorrect character on line 1 col 1: expected "NO", got "YES"
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 100000 492853 -452834 -657156 -282543... |
| correct output |
|---|
| YES YES NO YES YES ... |
| user output |
|---|
| YES YES NO YES YES ... |
Feedback: Incorrect character on line 6 col 1: expected "NO", got "YES"
Test 4
Verdict: WRONG ANSWER
| input |
|---|
| 100000 788522666 939776556 -831492125... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Feedback: Incorrect character on line 9 col 1: expected "NO", got "YES"
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 1 1 6 6 6 4 4 1000000000 1000000... |
| correct output |
|---|
| YES |
| user output |
|---|
| NO |
Feedback: Incorrect character on line 1 col 1: expected "YES", got "NO"
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| 1 -1000000000 1000000000 9999999... |
| correct output |
|---|
| NO |
| user output |
|---|
| YES |
Feedback: Incorrect character on line 1 col 1: expected "NO", got "YES"
