답안 #796303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796303 2023-07-28T09:05:13 Z Khizri 분수 공원 (IOI21_parks) C++17
5 / 100
349 ms 56680 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=2e5+5;
int n,x[mxn],y[mxn],p[mxn],sz[mxn];
int ax[4]={1,1,-1,-1};
int ay[4]={-1,1,1,-1};
vector<pii>vt;
map<pii,int>mp;
int fnd(int u){
    if(p[u]==u) return u;
    return p[u]=fnd(p[u]);
}
void Union(int u,int v){
    u=fnd(u);
    v=fnd(v);
    if(u!=v){
        if(sz[u]>sz[v]) swap(u,v);
        sz[u]+=sz[v];
        p[v]=u;
    }
}
bool cmp(pii a,pii b){
    return a.F+a.S<b.F+b.S;
}
int construct_roads(vector<int> xx, vector<int> yy) {
    n=xx.size();
    if(n==1){
        build({},{},{},{});
        return 1;
    }
    for(int i=0;i<n;i++){
        vt.pb({xx[i],yy[i]});
        mp[{xx[i],yy[i]}]=i+1;
        x[i+1]=xx[i];
        y[i+1]=yy[i];
    }
    set<pii>st;
    for(int i=1;i<=n;i++){
        p[i]=i;
        sz[i]=1;
    }
    vector<int>idxl,idxr,posl,posr;
    sort(all(vt),cmp);
    for(int i=1;i<n;i++){
        int l=vt[i].F,r=vt[i].S;
        int a=l-2,b=r;
        int c=l,d=r-2;
        int u=mp[{l,r}];
        int idx=mp[{a,b}];
        int idx2=mp[{c,d}];
        if(!idx&&!idx2){
            return 0;
        }
        if(idx&&idx2){
            int p1=(a+l)/2,p2=(b+r)/2;
            if(p1%2){
                if(!st.count({p1,p2-1})){
                    idxl.pb(u-1);
                    idxr.pb(idx-1);
                    posl.pb(p1);
                    posr.pb(p2-1);
                    st.insert({p1,p2-1});
                    continue;
                }
                else if(!st.count({p1,p2+1})){
                    idxl.pb(u-1);
                    idxr.pb(idx-1);
                    posl.pb(p1);
                    posr.pb(p2+1);
                    st.insert({p1,p2+1});
                    continue;
                }
            }
            else{
                if(!st.count({p1-1,p2})){
                    idxl.pb(u-1);
                    idxr.pb(idx-1);
                    posl.pb(p1-1);
                    posr.pb(p2);
                    st.insert({p1-1,p2});
                    continue;
                }
                else if(!st.count({p1+1,p2})){
                    idxl.pb(u-1);
                    idxr.pb(idx-1);
                    posl.pb(p1+1);
                    posr.pb(p2);
                    st.insert({p1+1,p2});
                    continue;
                }
            }
            p1=(c+l)/2,p2=(d+r)/2;
            if(p1%2){
                if(!st.count({p1,p2-1})){
                    idxl.pb(u-1);
                    idxr.pb(idx2-1);
                    posl.pb(p1);
                    posr.pb(p2-1);
                    st.insert({p1,p2-1});
                    continue;
                }
                else if(!st.count({p1,p2+1})){
                    idxl.pb(u-1);
                    idxr.pb(idx2-1);
                    posl.pb(p1);
                    posr.pb(p2+1);
                    st.insert({p1,p2+1});
                    continue;
                }
            }
            else{
                if(!st.count({p1-1,p2})){
                    idxl.pb(u-1);
                    idxr.pb(idx2-1);
                    posl.pb(p1-1);
                    posr.pb(p2);
                    st.insert({p1-1,p2});
                    continue;
                }
                else if(!st.count({p1+1,p2})){
                    idxl.pb(u-1);
                    idxr.pb(idx2-1);
                    posl.pb(p1+1);
                    posr.pb(p2);
                    st.insert({p1+1,p2});
                    continue;
                }
            }
        }
        else if(idx){
            int p1=(a+l)/2,p2=(b+r)/2;
            if(p1%2){
                if(!st.count({p1,p2-1})){
                    idxl.pb(u-1);
                    idxr.pb(idx-1);
                    posl.pb(p1);
                    posr.pb(p2-1);
                    st.insert({p1,p2-1});
                    continue;
                }
                else if(!st.count({p1,p2+1})){
                    idxl.pb(u-1);
                    idxr.pb(idx-1);
                    posl.pb(p1);
                    posr.pb(p2+1);
                    st.insert({p1,p2+1});
                    continue;
                }
            }
            else{
                if(!st.count({p1-1,p2})){
                    idxl.pb(u-1);
                    idxr.pb(idx-1);
                    posl.pb(p1-1);
                    posr.pb(p2);
                    st.insert({p1-1,p2});
                    continue;
                }
                else if(!st.count({p1+1,p2})){
                    idxl.pb(u-1);
                    idxr.pb(idx-1);
                    posl.pb(p1+1);
                    posr.pb(p2);
                    st.insert({p1+1,p2});
                    continue;
                }
            }
        }
        else if(idx2){
            int p1=(c+l)/2,p2=(d+r)/2;
            if(p1%2){
                if(!st.count({p1,p2-1})){
                    idxl.pb(u-1);
                    idxr.pb(idx2-1);
                    posl.pb(p1);
                    posr.pb(p2-1);
                    st.insert({p1,p2-1});
                    continue;
                }
                else if(!st.count({p1,p2+1})){
                    idxl.pb(u-1);
                    idxr.pb(idx2-1);
                    posl.pb(p1);
                    posr.pb(p2+1);
                    st.insert({p1,p2+1});
                    continue;
                }
            }
            else{
                if(!st.count({p1-1,p2})){
                    idxl.pb(u-1);
                    idxr.pb(idx2-1);
                    posl.pb(p1-1);
                    posr.pb(p2);
                    st.insert({p1-1,p2});
                    continue;
                }
                else if(!st.count({p1+1,p2})){
                    idxl.pb(u-1);
                    idxr.pb(idx2-1);
                    posl.pb(p1+1);
                    posr.pb(p2);
                    st.insert({p1+1,p2});
                    continue;
                }
            }
        }
    }
    build(idxl,idxr,posl,posr);
    return 1;
}
/*
cd "c:\Users\User\Desktop\parks (4)\cpp\" ; if ($?) { g++ parks.cpp grader.cpp -o parks } ; if ($?) { .\a.exe }
5
4 4 
4 6 
6 4
4 2
2 4
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 155 ms 27524 KB Output is correct
10 Correct 11 ms 3028 KB Output is correct
11 Correct 75 ms 14904 KB Output is correct
12 Correct 16 ms 4388 KB Output is correct
13 Correct 33 ms 8652 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 156 ms 27508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 155 ms 27524 KB Output is correct
10 Correct 11 ms 3028 KB Output is correct
11 Correct 75 ms 14904 KB Output is correct
12 Correct 16 ms 4388 KB Output is correct
13 Correct 33 ms 8652 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 156 ms 27508 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 339 ms 49668 KB Output is correct
24 Incorrect 1 ms 212 KB Solution announced impossible, but it is possible.
25 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 155 ms 27524 KB Output is correct
10 Correct 11 ms 3028 KB Output is correct
11 Correct 75 ms 14904 KB Output is correct
12 Correct 16 ms 4388 KB Output is correct
13 Correct 33 ms 8652 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 156 ms 27508 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 339 ms 49668 KB Output is correct
24 Incorrect 1 ms 212 KB Solution announced impossible, but it is possible.
25 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 155 ms 27524 KB Output is correct
10 Correct 11 ms 3028 KB Output is correct
11 Correct 75 ms 14904 KB Output is correct
12 Correct 16 ms 4388 KB Output is correct
13 Correct 33 ms 8652 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 156 ms 27508 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Incorrect 1 ms 212 KB Solution announced impossible, but it is possible.
19 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 155 ms 27524 KB Output is correct
10 Correct 11 ms 3028 KB Output is correct
11 Correct 75 ms 14904 KB Output is correct
12 Correct 16 ms 4388 KB Output is correct
13 Correct 33 ms 8652 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 156 ms 27508 KB Output is correct
17 Correct 349 ms 55328 KB Output is correct
18 Correct 329 ms 56680 KB Output is correct
19 Incorrect 147 ms 21820 KB Solution announced impossible, but it is possible.
20 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 155 ms 27524 KB Output is correct
10 Correct 11 ms 3028 KB Output is correct
11 Correct 75 ms 14904 KB Output is correct
12 Correct 16 ms 4388 KB Output is correct
13 Correct 33 ms 8652 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 156 ms 27508 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 339 ms 49668 KB Output is correct
24 Incorrect 1 ms 212 KB Solution announced impossible, but it is possible.
25 Halted 0 ms 0 KB -