Submission details
Task:Line Segment Intersection
Sender:aalto26jh_032
Submission time:2026-11-11 15:50:47 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.09 sdetails
#20.10 sdetails
#30.12 sdetails
#40.13 sdetails
#50.00 sdetails
#60.00 sdetails

Compiler report

input/code.cpp: In member function 'bool point::operator==(const point&) const':
input/code.cpp:25:17: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   25 |         return x==b.x &y==b.y;
      |                ~^~~~~
input/code.cpp: In member function 'bool line::intersect(line&)':
input/code.cpp:32:15: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   32 |         if ( a==o.a|a==o.b|b==o.a|b==o.b) return true;
      |              ~^~~~~
input/code.cpp:32:29: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   32 |         if ( a==o.a|a==o.b|b==o.a|b==o.b) return true;
      |                            ~^~~~~
input/code.cpp:32:36: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   32 |         if ( a==o.a|a==o.b|b==o.a|b==o.b) return true;
      |                                   ~^~~~~
input/code.cpp:42:19: warning: suggest parentheses around compar...

Code

#include <array>
#include <iostream>
#include <vector>
#include <climits>
#include <cstdint>

using namespace std;
#define DEBUG std::cout<<"LINE"<<__LINE__;
#define IN(A) int A;std::cin>>A;

template<typename T> void printV(vector<T> V) {
    for (int i=0;i<V.size()-1;i++) {
        cout<<V[i]<<" ";
    }

    cout<<V[V.size()-1];
    cout<<endl;
}
int64_t max3(int64_t a,int64_t b,int64_t c) {
    return max(a,max(b,c));
}
struct point {
    int x,y;
    bool operator==(const point &b) const {
        return x==b.x &y==b.y;
    }

};
struct line {
    point a,b;
    bool intersect(line &o ) {
        if ( a==o.a|a==o.b|b==o.a|b==o.b) return true;
        int64_t e,f=0;
        int t1=min(a.x,b.x);
        int t2=max(a.x,b.x);
        int t3=min(o.a.x,o.b.x);
        int t4=max(o.a.x,o.b.x);
        auto ta=o*a;
        auto tb=o*b;

        if ((*this)*o==0) {
            if (t1<t3&t2>t3) return true;
            if (t3<t1&t4>t1) return true;
        }

        if ((ta<0&tb>0)||(ta>0&tb<0)) return true;
        return false;
    }
   __inline int64_t operator*(const line &o) {
        return (a.x-b.x)*(o.a.y-o.b.y)-(o.a.x-o.b.x)*(a.y-b.y);
    }
    __inline int64_t operator*(const point &o) {
        return (o.x-a.x)*(o.y-b.y)-(o.y-a.y)*(o.x-b.x);
    }
};
struct compute {
    int tests=1;
    vector<array<line,2>> data;
    vector<pair<int,int>> result;
    vector<bool> visited;
    bool start() {
        IN(n);
        data.assign(n,{});
        for (int j=0;j<n;j++) {
            for (int i=0;i<2;i++) {
                cin>>data[j][i].a.x;
                cin>>data[j][i].a.y;
                cin>>data[j][i].b.x;
                cin>>data[j][i].b.y;
            }
        }
        for (auto &l:data ) {
          if (  l[0].intersect(l[1]))
          { cout<< "TRUE\n";}
            else cout<<"FALSE\n";
        }

        return true;
    }
    void readV(int n) {
        //for (int i=0;i<n;i++) cin>>data[i];

    }
    void testloop(){
        while (tests-->0) {
            start();
        }
    }
};

int main() {
    ios_base::sync_with_stdio(false);
   // cin.tie(NULL);
    compute comp;
    comp.start();


}

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
FALSE
FALSE
TRUE
FALSE
FALSE
...

Feedback: Incorrect character on line 1 col 1: expected "NO", got "FALSE"

Test 2

Verdict:

input
100000
81 745 -967 768 -451 -490 -454...

correct output
NO
NO
YES
NO
YES
...

user output
TRUE
FALSE
TRUE
FALSE
TRUE
...

Feedback: Incorrect character on line 1 col 1: expected "NO", got "TRUE"

Test 3

Verdict:

input
100000
492853 -452834 -657156 -282543...

correct output
YES
YES
NO
YES
YES
...

user output
FALSE
TRUE
FALSE
FALSE
FALSE
...

Feedback: Incorrect character on line 1 col 1: expected "YES", got "FALSE"

Test 4

Verdict:

input
100000
788522666 939776556 -831492125...

correct output
NO
NO
NO
NO
NO
...

user output
TRUE
TRUE
FALSE
FALSE
FALSE
...

Feedback: Incorrect character on line 1 col 1: expected "NO", got "TRUE"

Test 5

Verdict:

input
1
1 6 6 6 4 4 1000000000 1000000...

correct output
YES

user output
FALSE

Feedback: Incorrect character on line 1 col 1: expected "YES", got "FALSE"

Test 6

Verdict:

input
1
-1000000000 1000000000 9999999...

correct output
NO

user output
FALSE

Feedback: Incorrect character on line 1 col 1: expected "NO", got "FALSE"