Submission details
Task:Line Segment Intersection
Sender:aalto26jh_012
Submission time:2026-11-06 13:17:15 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.31 sdetails
#2ACCEPTED0.37 sdetails
#3ACCEPTED0.47 sdetails
#4ACCEPTED0.56 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails

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;
            }
        }

        long long d3 = (std::conj(a-c)*(a-d)).Y;
        long long d4 = (std::conj(b-c)*(b-d)).Y;

        if (((d1 >= 0 && d2 <= 0) || (d1 <= 0 && d2 >= 0)) &&
            ((d3 >= 0 && d4 <= 0) || (d3 <= 0 && d4 >= 0))) {
            results[i] = true;
        } else results[i] = false;
    }

    for (auto result : results) {
        std::cout << (result? "YES" : "NO") << std::endl; 
    }
}

Test details

Test 1

Verdict:

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 4686 col 1: expected "YES", got "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