CSES - Aalto Competitive Programming 2024 - wk10 - Homework - Results
Submission details
Task:Line Segment Intersection
Sender:Nallue
Submission time:2024-11-12 11:13:52 +0200
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#10.30 sdetails
#20.35 sdetails
#30.44 sdetails
#40.52 sdetails
#50.00 sdetails
#6ACCEPTED0.00 sdetails

Code

#include <iostream>
#include <ccomplex>
#include <vector>

using namespace std;

typedef long long C;
typedef complex<C> P;
#define X real()
#define Y imag()
#define cross(a,b) (conj(a)*b).Y

bool intersection(P p1, P p2, P p3, P p4){
    if(p1 == p3 or p1 == p4 or p2 == p3 or p2 == p4)return 1;

    C c1 = cross(p3-p1,p3-p2);
    C c2 = cross(p4-p1,p4-p2);

    //cout << c1 << " " << c2 << endl;
    if((c1>=0 and c2<=0) or (c1<=0 and c2>=0))return true;
    return false;
}

int main(){
    int t;
    cin >> t;
    for(int i=0; i< t; i++){
        vector<P> vec(4);
        
        for(int l=0; l<4; l++){
            C a,b;
            cin >> a >> b;
            vec[l] = {a,b};
        }

        if(intersection(vec[0], vec[1], vec[2], vec[3])){
            cout << "YES" << endl;
        }
        else cout << "NO" << 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
YES
NO
YES
YES
NO
...

Test 2

Verdict:

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

correct output
NO
NO
YES
NO
YES
...

user output
NO
NO
NO
NO
YES
...

Test 3

Verdict:

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

correct output
YES
YES
NO
YES
YES
...

user output
NO
YES
YES
YES
YES
...

Test 4

Verdict:

input
100000
788522666 939776556 -831492125...

correct output
NO
NO
NO
NO
NO
...

user output
NO
YES
YES
YES
NO
...

Test 5

Verdict:

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

correct output
YES

user output
NO

Test 6

Verdict: ACCEPTED

input
1
-1000000000 1000000000 9999999...

correct output
NO

user output
NO