QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#208855#5155. Faster Than LightJooDdaeWA 0ms3648kbC++202.2kb2023-10-09 21:26:052023-10-09 21:26:05

Judging History

你现在查看的是最新测评结果

  • [2023-10-09 21:26:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3648kb
  • [2023-10-09 21:26:05]
  • 提交

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");
}

詳細信息

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'