QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#208889#5155. Faster Than LightJooDdaeWA 1ms3444kbC++202.7kb2023-10-09 21:49:232023-10-09 21:49:23

Judging History

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

  • [2023-10-09 21:49:23]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3444kb
  • [2023-10-09 21:49:23]
  • 提交

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) {
    vector<point> X, Y, dh, uh;
    for(auto [x, y] : p) X.push_back(x), Y.push_back(y);


    swap(*min_element(X.begin(), X.end()), X[0]);
    sort(X.begin()+1, X.end(), [&](auto a, auto b){
        auto re = ccw(X[0], a, b);
        return re ? re > 0 : tie(a.x, b.y) < tie(b.x, a.y);
    });
    // reverse(X.begin()+1, X.end());

    for(auto p : X) {
        // cout << p.x << " " << p.y << "\n";
        while(dh.size() > 1 && ccw(dh[dh.size()-2], dh.back(), p) >= 0) dh.pop_back();
        dh.push_back(p);
    }



    swap(*min_element(Y.begin(), Y.end(), [&](auto a, auto b){ return tie(a.x, b.y) < tie(b.x, a.y); }), Y[0]);
    sort(Y.begin()+1, Y.end(), [&](auto a, auto b){
        auto re = ccw(Y[0], a, b);
        return re ? re > 0 : tie(a.x, b.y) < tie(b.x, a.y);
    });

    for(auto p : Y) {
        // cout << p.x << " " << p.y << "\n";
        while(uh.size() > 1 && ccw(uh[uh.size()-2], uh.back(), p) <= 0) uh.pop_back();
        uh.push_back(p);
    }

    // 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);
    if(solve(p)) return cout << "possible", 0;

    for(auto &[p1, p2] : p) swap(p1.x, p1.y), swap(p2.x, p2.y);
    cout << (solve(p) ? "possible" : "impossible");
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3444kb

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: -100
Wrong Answer
time: 1ms
memory: 3432kb

input:

4
1 1 2 2
1 3 2 4
3 1 4 2
3 3 4 4

output:

possible

result:

wrong answer 1st lines differ - expected: 'impossible', found: 'possible'