| Task: | Line Segment Intersection |
| Sender: | aalto26jh_031 |
| Submission time: | 2026-11-08 22:49:22 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.08 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;
#define int long long
#define die(x) return cout << x << endl, 0
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define FILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define SZ(x) ((int)(x).size())
typedef long double ld;
typedef long long ll;
int gcd(int x, int y){ return (!y ? x : gcd(y, x%y)); }
int to_int(string sconvert){stringstream geek(sconvert);int xconvert = 0; geek >> xconvert; return xconvert;}
const int MAXN=2e6+30, MAX_LOG=40, MOD=1e9+7, INF=1e9;
const double PI = acos(-1);
int mod(int x) { return (x % MOD + MOD) % MOD; }
int power(int x, int y){
if(y==0)return 1;
int c=power(x,y/2);
c=(c*c)%MOD;
if(y%2)c=(c*x)%MOD;
return c;
}
int crs(int ax, int ay, int bx, int by, int cx, int cy){
return (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
}
int inside(int ax, int ay, int bx, int by, int cx, int cy){
if(min(ax,bx) <= cx){
if(cx <= max(ax,bx)){
if(min(ay, by) <= cy){
if(cy <= max(ay, by)){
return 1;
}
}
}
}
return 0;
}
int intersec(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){
int c1 = crs(x1, y1, x2, y2, x3,y3);
int c2 = crs(x1, y1, x2, y2, x4,y4);
int c3 = crs(x3, y3, x4, y4, x1,y1);
int c4 = crs(x3, y3, x4, y4, x2,y2);
if(c1==0 && inside(x1, y1, x2, y2, x3, y3)){
return 1;
}
if(c2==0 && inside(x1, y1, x2, y2, x4, y4)){
return 1;
}
if(c3==0 && inside(x3, y3, x4, y4, x1, y1)){
return 1;
}
if(c4==0 && inside(x3, y3, x4, y4, x2, y2)){
return 1;
}
if(((c1>0) != (c2>0))){
if((c3>0) != (c4>0))return 1;
}
return 0;
}
int MAIN(){
int x1, y1, x2, y2, x3, y3, x4, y4;
cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
if(intersec(x1, y1, x2, y2, x3, y3, x4, y4)){
cout<<"YES"<<endl;
}
else cout<<"NO"<<endl;
return 0;
}
int32_t main(){
IOS;
int t;
cin>>t;
while(t--)MAIN();
return 0;
}
Test details
Test 1
Verdict: ACCEPTED
| 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 |
