QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#208855 | #5155. Faster Than Light | JooDdae | WA | 0ms | 3648kb | C++20 | 2.2kb | 2023-10-09 21:26:05 | 2023-10-09 21:26:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct point {
ll x, y;
bool operator < (const point &o) const {
return tie(x, y) < tie(o.x, o.y);
}
point operator - (const point &a)const{
return {x-a.x, y-a.y};
}
};
ll cross(point a, point b){
return a.x * b.y - a.y * b.x;
}
int ccw(point a, point b, point c){
auto re = cross(b-a, c-a);
return (re > 0) - (re < 0);
}
bool solve(vector<array<point, 2>> p) {
sort(p.begin(), p.end(), [&](auto a, auto b){
return tie(a[0].x, b[0].y, a[1]) < tie(b[0].x, a[0].y, b[1]);
});
vector<point> dh, uh;
for(auto [u, X] : p) {
while(dh.size() > 1 && ccw(dh[dh.size()-2], dh.back(), u) >= 0) dh.pop_back();
dh.push_back(u);
}
for(auto &[x, y] : p) swap(x, y);
sort(p.begin(), p.end(), [&](auto a, auto b){
return tie(a[0].x, b[0].y, a[1]) < tie(b[0].x, a[0].y, b[1]);
});
for(auto [u, X] : p) {
while(uh.size() > 1 && ccw(uh[uh.size()-2], uh.back(), u) <= 0) uh.pop_back();
uh.push_back(u);
}
// for(int i=0;i+1<dh.size();i++) cout << dh[i].x << " " << dh[i].y << " " << dh[i+1].x << " " << dh[i+1].y << "\n";
// cout << "----------------------------------\n";
// for(int i=0;i+1<uh.size();i++) cout << uh[i].x << " " << uh[i].y << " " << uh[i+1].x << " " << uh[i+1].y << "\n";
// cout << "\n";
for(int i=0, j=0;i+1<dh.size();i++) {
while(j < uh.size() && uh[j].x <= dh[i+1].x) {
if(ccw(dh[i], dh[i+1], uh[j]) < 0) return false;
j++;
}
}
for(int i=0, j=0;i+1<uh.size();i++) {
while(j < dh.size() && dh[j].x <= uh[i+1].x) {
if(ccw(uh[i], uh[i+1], dh[j]) > 0) return false;
j++;
}
}
return true;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vector<array<point, 2>> p(n);
for(auto &[p1, p2] : p) {
cin >> p1.x >> p1.y;
cin >> p2.x >> p2.y;
}
if(solve(p)) return cout << "possible", 0;
for(auto &[p1, p2] : p) swap(p1.x, p2.x);
cout << (solve(p) ? "possible" : "impossible");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
5 1 3 3 4 2 2 4 3 4 1 5 3 5 2 7 3 6 3 8 4
output:
possible
result:
ok single line: 'possible'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
4 1 1 2 2 1 3 2 4 3 1 4 2 3 3 4 4
output:
impossible
result:
ok single line: 'impossible'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3648kb
input:
3 1 1 2 2 1 3 2 4 3 3 4 4
output:
impossible
result:
wrong answer 1st lines differ - expected: 'possible', found: 'impossible'