Task: | Line Segment Intersection |
Sender: | htoik |
Submission time: | 2024-11-11 15:08:09 +0200 |
Language: | C++ (C++20) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.07 s | details |
#2 | ACCEPTED | 0.08 s | details |
#3 | ACCEPTED | 0.10 s | details |
#4 | ACCEPTED | 0.12 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
Code
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; struct pt{ ll x; ll y; }; pt operator+(const pt& a, const pt& b){ return pt{.x=a.x+b.x, .y=a.y+b.y}; }; pt operator-(const pt& a, const pt& b){ return pt{.x=a.x-b.x, .y=a.y-b.y}; }; bool operator==(const pt& a, const pt& b){ return a.x == b.x && a.y == b.y; }; ostream& operator<<(ostream& os, const pt& a){ return os << "(" << a.x << "," << a.y << ")"; } ll cross(pt p1, pt p2){ return p1.x*p2.y - p1.y*p2.x; } ll orient(pt a, pt b, pt c) { return cross(b-a, c-a); } int main() { ios::sync_with_stdio(0); cin.tie(0); ull t; cin >> t; for(ull i=0; i<t; i++){ pt p1, p2, p3, p4; cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y >> p4.x >> p4.y; ll cp1 = orient(p3,p4,p1); ll cp2 = orient(p3,p4,p2); ll cp3 = orient(p1,p2,p3); ll cp4 = orient(p1,p2,p4); bool inter = ((((cp1>0)==(cp2<=0))) && (((cp3>0)==(cp4<=0)))) || ((cp1 == 0 || cp2 == 0) && (cp3 == 0 || cp4 == 0)) || p1 == p3 || p2 == p3 || p1 == p4 || p2 == p4; // cout << p1 << " " << p2 << " " << p3 << " " << p4 << " " << inter << "\n"; cout << (inter ? "YES\n" : "NO\n"); } }
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 ... |
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 |