| Task: | Line Segment Intersection |
| Sender: | aalto26jh_012 |
| Submission time: | 2026-11-06 13:08:01 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.31 s | details |
| #2 | ACCEPTED | 0.37 s | details |
| #3 | ACCEPTED | 0.47 s | details |
| #4 | ACCEPTED | 0.56 s | details |
| #5 | ACCEPTED | 0.00 s | details |
| #6 | ACCEPTED | 0.00 s | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:83:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
83 | if ((d1 > 0 && d2 > 0) || (d1 < 0) && (d2 < 0)) {
| ~~~~~~~~~^~~~~~~~~~~
input/code.cpp:91:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
91 | if ((d3 > 0 && d4 > 0) || (d3 < 0) && (d4 < 0)) {
| ~~~~~~~~~^~~~~~~~~~~Code
#include <complex>
typedef long long C;
typedef std::complex<C> Point;
#define X real()
#define Y imag()
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
int t;
std::cin >> t;
std::vector<bool> results(t);
for (int i = 0; i < t; ++i) {
long long x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4;
std::cin >> x_1 >> y_1 >> x_2 >> y_2 >> x_3 >> y_3 >> x_4 >> y_4;
Point a = {x_1, y_1}, b = {x_2, y_2}, c = {x_3, y_3}, d = {x_4, y_4};
if (a == c || a == d || b == c || b == d) {
results[i] = true;
continue;
}
long long d1 = (std::conj(c-a)*(c-b)).Y;
long long d2 = (std::conj(d-a)*(d-b)).Y;
if (d1 == 0 && d2 == 0) {
std::vector<std::pair<long long, int>> lengths = {
{std::abs(a), 0},
{std::abs(b), 1},
{std::abs(c), 2},
{std::abs(d), 3}
};
std::sort(lengths.begin(), lengths.end());
if ((lengths[0].second < 2 && lengths[1].second < 2)
|| (lengths[0].second >= 2 && lengths[1].second >= 2)) {
results[i] = false;
continue;
} else {
results[i] = true;
continue;
}
}
if (d1 == 0) {
std::vector<std::pair<long long, int>> lengths = {
{std::abs(a), 0},
{std::abs(b), 1},
{std::abs(c), 2}
};
std::sort(lengths.begin(), lengths.end());
if (lengths[1].second != 2) {
results[i] = false;
continue;
} else {
results[i] = true;
continue;
}
}
if (d2 == 0) {
std::vector<std::pair<long long, int>> lengths = {
{std::abs(a), 0},
{std::abs(b), 1},
{std::abs(d), 2}
};
std::sort(lengths.begin(), lengths.end());
if (lengths[1].second != 2) {
results[i] = false;
continue;
} else {
results[i] = true;
continue;
}
}
if ((d1 > 0 && d2 > 0) || (d1 < 0) && (d2 < 0)) {
results[i] = false;
continue;
}
long long d3 = (std::conj(a-c)*(a-d)).Y;
long long d4 = (std::conj(b-c)*(b-d)).Y;
if ((d3 > 0 && d4 > 0) || (d3 < 0) && (d4 < 0)) {
results[i] = false;
continue;
}
results[i] = true;
}
for (auto result : results) {
std::cout << (result? "YES" : "NO") << std::endl;
}
}
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 20 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 |
