Task: | Line Segment Intersection |
Sender: | Rasse |
Submission time: | 2024-11-08 09:16:17 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.07 s | details |
#2 | WRONG ANSWER | 0.08 s | details |
#3 | WRONG ANSWER | 0.10 s | details |
#4 | WRONG ANSWER | 0.12 s | details |
#5 | WRONG ANSWER | 0.00 s | details |
#6 | WRONG ANSWER | 0.00 s | details |
Code
#include <iostream>#include <vector>#include <array>#include <string>#include <algorithm>#include <numeric>#include <unordered_map>#include <unordered_set>#include <queue>#include <climits>#include <cmath>#include <functional>#include <type_traits>#include <fstream>#include <bitset>#include <complex>#define int long longusing namespace std;//#define cross(x, y) ((x).real()*(y).imag()-(x).imag()*(y).real())#define cross(x, y) (((x)*conj(y)).imag())#define sign(v) ((0 < (v)) - ((v) < 0))void solve(){int x1, y1, x2, y2, x3, y3, x4, y4;cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;complex<int> v1 = {x1, y1};complex<int> v2 = {x2, y2};complex<int> v3 = {x3, y3};complex<int> v4 = {x4, y4};// Case: The same lineif (cross(v2-v1, v3-v2) == 0 && cross(v3-v2, v4-v3) == 0){vector<complex<int>> ps = {v1, v2, v3, v4};sort(ps.begin(), ps.end(), [](auto v1, auto v2){ if (v1.real() == v2.real()) return v1.imag() < v2.imag(); else return v1.real() < v2.real(); });if ((ps[0] == v1 || ps[0] == v2) == (ps[1] == v1 || ps[1] == v2)){cout << "NO\n";return;}else{cout << "YES\n";return;}}// Case: end pointif (v1 == v3 || v2 == v3 || v1 == v4 || v2 == v4){cout << "Yes\n";return;}// Other on the left side and other on the right sideint r1 = sign(cross(v2-v1, v3-v1));int r2 = sign(cross(v2-v1, v4-v1));int r3 = sign(cross(v4-v3, v1-v3));int r4 = sign(cross(v4-v3, v2-v3));if (r1 != r2 && r3 != r4){cout << "Yes\n";return;}cout << "No\n";}signed main(){ios::sync_with_stdio(0);cin.tie(0);int t = 1;cin >> t;//ifstream f("testcase.txt");//cin.rdbuf(f.rdbuf());for (int i = 0; i < t; i++)solve();}
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 ... Truncated |
Test 2
Verdict: WRONG ANSWER
input |
---|
100000 81 745 -967 768 -451 -490 -454... |
correct output |
---|
NO NO YES NO YES ... |
user output |
---|
No No Yes No Yes ... Truncated |
Test 3
Verdict: WRONG ANSWER
input |
---|
100000 492853 -452834 -657156 -282543... |
correct output |
---|
YES YES NO YES YES ... |
user output |
---|
Yes Yes No Yes Yes ... Truncated |
Test 4
Verdict: WRONG ANSWER
input |
---|
100000 788522666 939776556 -831492125... |
correct output |
---|
NO NO NO NO NO ... |
user output |
---|
No No No No No ... Truncated |
Test 5
Verdict: WRONG ANSWER
input |
---|
1 1 6 6 6 4 4 1000000000 1000000... |
correct output |
---|
YES |
user output |
---|
Yes |
Test 6
Verdict: WRONG ANSWER
input |
---|
1 -1000000000 1000000000 9999999... |
correct output |
---|
NO |
user output |
---|
No |