답안 #596932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
596932 2022-07-15T09:29:29 Z jasmin Roads (CEOI20_roads) C++14
15 / 100
21 ms 1632 KB
#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
using pii=pair<int,int>;

const int inf=1e18;

void subtask2(int n, vector<pair<pair<int,int>, pair<int,int> > >& p, vector<pair<pair<int,int>, pair<int,int> > >& old){
    auto compare=[&](int i, int j){
        auto a=p[i];
        auto b=p[j];
        if(a.first<b.first) return true;
        else if(a.first>b.first) return false;
        else{
            if(a.second<b.second) return true;
            return false;
        }
    };
    vector<int> sorted(n);
    iota(sorted.begin(), sorted.end(), 0);
    sort(sorted.begin(), sorted.end(), compare);
    pair<int,int> last={-inf, -inf};
    for(int i=0; i<n; i++){
        auto a=old[sorted[i]].first;
        auto b=old[sorted[i]].second;

        if(last.first!=-inf){
            cout << last.first << " " << last.second << " " << a.first << " " << a.second << "\n";
        }
        last=b;
    }
}

struct point{
    int x;
    int y;
    point(int x=0, int y=0): x(x), y(y){};
};
struct frac{
    int n;
    int d;

    frac(int n=1, int d=1): n(n), d(d){};

    frac operator+(const frac& a)const{
        int lcm=a.d*d/__gcd(a.d, d);
        return frac(n*lcm/d+a.n*lcm/a.d, lcm);
    }
    frac operator*(const frac& a) const{
        return frac(n*a.n, d*a.d);
    }
    bool operator<(const frac& a) const{
        return n*a.d<d*a.n;
    }
};

struct seg{
    point p1;
    point p2;
    pii st;
    frac li;
    seg(){
        p1={0, 0};
        p2={0, 0};
        st={1, 1};
        li={1, 1};
    }
    seg(point point1, point point2){
        p1=point1;
        p2=point2;
        int dx=p2.x-p1.x;
        int dy=p2.y-p1.y;
        st={p1.y*dx-p1.x*dy, dx};
        frac m(-dx, dy);
        li=frac(p1.y,1)+m*frac(p1.x, 1);
    };

    bool operator<(const seg& a) const{
        if(li<a.li) return true;
        else if(!(a.li<li)){
            return p1.x<a.p1.x;
        }
        return false;

    }
};

bool specialsorting(seg a, seg b){
    if(a.st.first*b.st.second<a.st.second*b.st.first){
        return true;
    }
    else if(a.st.first*b.st.second==a.st.second*b.st.first){
        return a.p1.x<b.p1.x;
    }
    return false;
}

void subtask3(int n, vector<pair<pii, pii> >& p){
    // sortierpunkte finden
    vector<seg> s(n);
    for(int i=0; i<n; i++){
        s[i]=seg(point(p[i].f.f, p[i].f.s), point(p[i].s.f, p[i].s.s));
    }
    //sortieren
    sort(s.begin(), s.end());
    // verbinden
    for(int i=1; i<n; i++){
        cout << s[i-1].p2.x << " " << s[i-1].p2.y << " " << s[i].p1.x << " " << s[i].p1.y << "\n";
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<pair<pair<int,int>, pair<int,int> > >p(n);
    bool s2=true;
    for(int i=0; i<n; i++){
        cin >> p[i].first.first >> p[i].first.second;
        cin >> p[i].second.first >> p[i].second.second;
        if(p[i].first>p[i].second){
            swap(p[i].first, p[i].second);
        }

        if(p[i].first.first!=p[i].second.first) s2=false;
    }

    if(s2){
        subtask2(n, p, p);
        return 0;
    }
    subtask3(n, p);
}
# 결과 실행 시간 메모리 Grader output
1 Failed 0 ms 212 KB Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 8 ms 980 KB Output is correct
5 Correct 14 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 8 ms 1040 KB Output is correct
5 Correct 21 ms 1632 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Failed 1 ms 340 KB Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])"
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 8 ms 1032 KB Output is correct
5 Correct 15 ms 1620 KB Output is correct
6 Failed 0 ms 212 KB Condition failed: "!Cross(S[*pi], S[*pa])"
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 0 ms 212 KB Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 0 ms 212 KB Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])"
2 Halted 0 ms 0 KB -