Submission #1020214

# Submission time Handle Problem Language Result Execution time Memory
1020214 2024-07-11T17:15:34 Z bachhoangxuan Hamburg Steak (JOI20_hamburg) C++17
100 / 100
992 ms 163180 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
const int inf = 1e9;
#define pii pair<int,int>
#define piii pair<pii,int>
#define fi first
#define se second

struct rec{
    int l,r,u,d;
    rec(int l=0,int r=0,int u=0,int d=0):l(l),r(r),u(u),d(d){}
};

int N,K;
vector<rec> A;
int rev(int x){
    return (x>2*N?x-2*N:x+2*N);
}

int T,f[maxn],lt[4],rt[4];
vector<int> edge[8*maxn];
vector<piii> cc[4];

void add_edge(int u,int v){
    edge[u].push_back(v);
}

int num[8*maxn],low[8*maxn],scc[8*maxn],cnt;
bool inst[8*maxn];
vector<int> st;

void dfs(int u){
    num[u]=low[u]=++T;
    inst[u]=true;st.push_back(u);
    for(int v:edge[u]){
        if(!num[v]){
            dfs(v);
            low[u]=min(low[u],low[v]);
        }
        else if(inst[v]) low[u]=min(low[u],num[v]);
    }
    if(low[u]==num[u]){
        int v=-1;cnt++;
        do{
            v=st.back();
            scc[v]=cnt;
            st.pop_back();
            inst[v]=false;
        }while(v!=u);
    }
}

void solve(){
    int L=0,R=inf,U=inf,D=0;
    for(auto [l,r,u,d]:A) L=max(L,l),R=min(R,r),U=min(U,u),D=max(D,d);
    for(int i=0;i<4;i++) lt[i]=0,rt[i]=inf;

    auto add = [&](int l,int r,int u,int d){
        int k=0,op=-1,oq=-1;
        pii p,q;
        if(l<=L && L<=r) q={d,u},oq=0,swap(p,q),swap(op,oq),k++;
        if(l<=R && R<=r) q={d,u},oq=1,swap(p,q),swap(op,oq),k++;
        if(d<=D && D<=u) q={l,r},oq=2,swap(p,q),swap(op,oq),k++;
        if(d<=U && U<=u) q={l,r},oq=3,swap(p,q),swap(op,oq),k++;
        if(k>=3) return;
        if(k==1){
            lt[op]=max(lt[op],p.fi);
            rt[op]=min(rt[op],p.se);
        }
        else{
            cc[op].push_back({p,++T});
            cc[oq].push_back({q,++T});
            add_edge(rev(T-1),T);
            add_edge(rev(T),T-1);
        }
    };
    for(auto [l,r,u,d]:A) add(l,r,u,d);

    int S=T;T+=2*N;
    for(int t=0;t<4;t++){
        sort(cc[t].begin(),cc[t].end(),[&](piii a,piii b){
            return a.fi.se<b.fi.se;
        });
        int sz=(int)cc[t].size();
        for(int i=0;i<sz;i++){
            auto [p,id]=cc[t][i];
            if(p.se<lt[t] || rt[t]<p.fi) add_edge(id,rev(id));
            f[i]=++T;add_edge(f[i],rev(id));
            if(i) add_edge(f[i],f[i-1]);
            int l=-1,r=i-1;
            while(l<r){
                int m=(l+r+1)>>1;
                if(cc[t][m].fi.se<p.fi) l=m;
                else r=m-1;
            }
            if(l>=0) add_edge(id,f[l]);
        }
        sort(cc[t].begin(),cc[t].end(),[&](piii a,piii b){
            return a.fi.fi<b.fi.fi;
        });
        for(int i=sz-1;i>=0;i--){
            auto [p,id]=cc[t][i];
            f[i]=++T;add_edge(f[i],rev(id));
            if(i<sz-1) add_edge(f[i],f[i+1]);
            int l=i+1,r=sz;
            while(l<r){
                int m=(l+r)>>1;
                if(cc[t][m].fi.fi>p.se) r=m;
                else l=m+1;
            }
            if(l<sz) add_edge(id,f[l]);
        }
    }
    int M=T;T=0;
    for(int i=1;i<=M;i++) if(!num[i]) dfs(i);

    vector<bool> use(S+1);
    for(int i=1;i<=S;i++) use[i]=(scc[i]<scc[rev(i)]);
    for(int t=0;t<4;t++){
        for(auto [p,id]:cc[t]){
            if(use[id]) lt[t]=max(lt[t],p.fi),rt[t]=min(rt[t],p.se);
        }
    }
    cout << L << ' ' << lt[0] << '\n';
    cout << R << ' ' << lt[1] << '\n';
    cout << lt[2] << ' ' << D << '\n';
    cout << lt[3] << ' ' << U << '\n';
}

bool check=false;
vector<pii> cur;

vector<rec> get(int x,int y,vector<rec> a){
    cur.push_back({x,y});
    vector<rec> res;
    for(auto [l,r,u,d]:a) if(x<l || r<x || y<d || u<y) res.push_back(rec(l,r,u,d));
    return res;
}

void dfs(int k,vector<rec> a){
    if(check) return;
    if(!k){
        if(!a.empty() || check) return;
        check=true;
        for(auto [x,y]:cur) cout << x << ' ' << y << '\n';
        return;
    }
    int L=0,R=inf,U=inf,D=0;
    for(auto [l,r,u,d]:a) L=max(L,l),R=min(R,r),U=min(U,u),D=max(D,d);
    dfs(k-1,get(L,U,a));cur.pop_back();
    dfs(k-1,get(L,D,a));cur.pop_back();
    dfs(k-1,get(R,U,a));cur.pop_back();
    dfs(k-1,get(R,D,a));cur.pop_back();
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin >> N >> K;
    for(int i=0;i<N;i++){
        int l,r,u,d;cin >> l >> d >> r >> u;
        A.push_back(rec(l,r,u,d));
    }
    dfs(K,A);
    if(check) return 0;
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 38232 KB Output is correct
2 Correct 18 ms 37980 KB Output is correct
3 Correct 19 ms 38236 KB Output is correct
4 Correct 19 ms 37976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 38232 KB Output is correct
2 Correct 18 ms 38236 KB Output is correct
3 Correct 18 ms 38236 KB Output is correct
4 Correct 19 ms 38236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 38212 KB Output is correct
2 Correct 19 ms 38236 KB Output is correct
3 Correct 18 ms 38080 KB Output is correct
4 Correct 18 ms 38236 KB Output is correct
5 Correct 22 ms 38060 KB Output is correct
6 Correct 19 ms 38236 KB Output is correct
7 Correct 19 ms 38232 KB Output is correct
8 Correct 19 ms 38236 KB Output is correct
9 Correct 19 ms 38236 KB Output is correct
10 Correct 19 ms 38232 KB Output is correct
11 Correct 19 ms 38232 KB Output is correct
12 Correct 19 ms 38232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 38236 KB Output is correct
2 Correct 19 ms 38236 KB Output is correct
3 Correct 20 ms 38236 KB Output is correct
4 Correct 19 ms 38220 KB Output is correct
5 Correct 19 ms 38236 KB Output is correct
6 Correct 18 ms 38232 KB Output is correct
7 Correct 25 ms 38396 KB Output is correct
8 Correct 20 ms 38360 KB Output is correct
9 Correct 19 ms 38232 KB Output is correct
10 Correct 20 ms 38420 KB Output is correct
11 Correct 21 ms 38408 KB Output is correct
12 Correct 19 ms 38236 KB Output is correct
13 Correct 19 ms 38236 KB Output is correct
14 Correct 21 ms 38440 KB Output is correct
15 Correct 18 ms 38236 KB Output is correct
16 Correct 19 ms 38232 KB Output is correct
17 Correct 23 ms 38588 KB Output is correct
18 Correct 20 ms 38236 KB Output is correct
19 Correct 20 ms 38348 KB Output is correct
20 Correct 24 ms 38460 KB Output is correct
21 Correct 20 ms 38428 KB Output is correct
22 Correct 17 ms 38296 KB Output is correct
23 Correct 25 ms 38576 KB Output is correct
24 Correct 18 ms 38236 KB Output is correct
25 Correct 22 ms 38448 KB Output is correct
26 Correct 22 ms 38448 KB Output is correct
27 Correct 22 ms 38408 KB Output is correct
28 Correct 22 ms 38116 KB Output is correct
29 Correct 21 ms 38384 KB Output is correct
30 Correct 18 ms 38236 KB Output is correct
31 Correct 23 ms 38436 KB Output is correct
32 Correct 21 ms 38380 KB Output is correct
33 Correct 21 ms 38372 KB Output is correct
34 Correct 21 ms 38400 KB Output is correct
35 Correct 26 ms 38448 KB Output is correct
36 Correct 21 ms 38468 KB Output is correct
37 Correct 26 ms 38560 KB Output is correct
38 Correct 28 ms 38480 KB Output is correct
39 Correct 23 ms 38572 KB Output is correct
40 Correct 21 ms 38380 KB Output is correct
41 Correct 23 ms 38600 KB Output is correct
42 Correct 23 ms 38548 KB Output is correct
43 Correct 22 ms 38592 KB Output is correct
44 Correct 25 ms 38488 KB Output is correct
45 Correct 23 ms 38628 KB Output is correct
46 Correct 23 ms 38444 KB Output is correct
47 Correct 23 ms 38452 KB Output is correct
48 Correct 22 ms 38540 KB Output is correct
49 Correct 24 ms 38444 KB Output is correct
50 Correct 25 ms 38364 KB Output is correct
51 Correct 28 ms 38480 KB Output is correct
52 Correct 23 ms 38460 KB Output is correct
53 Correct 24 ms 38412 KB Output is correct
54 Correct 24 ms 38528 KB Output is correct
55 Correct 21 ms 38492 KB Output is correct
56 Correct 21 ms 38380 KB Output is correct
57 Correct 20 ms 38348 KB Output is correct
58 Correct 22 ms 38480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 38232 KB Output is correct
2 Correct 18 ms 37980 KB Output is correct
3 Correct 19 ms 38236 KB Output is correct
4 Correct 19 ms 37976 KB Output is correct
5 Correct 85 ms 51908 KB Output is correct
6 Correct 86 ms 51900 KB Output is correct
7 Correct 95 ms 51792 KB Output is correct
8 Correct 81 ms 51908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 38232 KB Output is correct
2 Correct 18 ms 38236 KB Output is correct
3 Correct 18 ms 38236 KB Output is correct
4 Correct 19 ms 38236 KB Output is correct
5 Correct 107 ms 59324 KB Output is correct
6 Correct 90 ms 55440 KB Output is correct
7 Correct 100 ms 57524 KB Output is correct
8 Correct 95 ms 58316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 38212 KB Output is correct
2 Correct 19 ms 38236 KB Output is correct
3 Correct 18 ms 38080 KB Output is correct
4 Correct 18 ms 38236 KB Output is correct
5 Correct 22 ms 38060 KB Output is correct
6 Correct 19 ms 38236 KB Output is correct
7 Correct 19 ms 38232 KB Output is correct
8 Correct 19 ms 38236 KB Output is correct
9 Correct 19 ms 38236 KB Output is correct
10 Correct 19 ms 38232 KB Output is correct
11 Correct 19 ms 38232 KB Output is correct
12 Correct 19 ms 38232 KB Output is correct
13 Correct 98 ms 56768 KB Output is correct
14 Correct 102 ms 56252 KB Output is correct
15 Correct 92 ms 57280 KB Output is correct
16 Correct 88 ms 55248 KB Output is correct
17 Correct 100 ms 57020 KB Output is correct
18 Correct 87 ms 54460 KB Output is correct
19 Correct 133 ms 68144 KB Output is correct
20 Correct 155 ms 69176 KB Output is correct
21 Correct 150 ms 70428 KB Output is correct
22 Correct 98 ms 59580 KB Output is correct
23 Correct 172 ms 70620 KB Output is correct
24 Correct 104 ms 59848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 38236 KB Output is correct
2 Correct 19 ms 38236 KB Output is correct
3 Correct 20 ms 38236 KB Output is correct
4 Correct 19 ms 38220 KB Output is correct
5 Correct 19 ms 38236 KB Output is correct
6 Correct 18 ms 38232 KB Output is correct
7 Correct 25 ms 38396 KB Output is correct
8 Correct 20 ms 38360 KB Output is correct
9 Correct 19 ms 38232 KB Output is correct
10 Correct 20 ms 38420 KB Output is correct
11 Correct 21 ms 38408 KB Output is correct
12 Correct 19 ms 38236 KB Output is correct
13 Correct 19 ms 38236 KB Output is correct
14 Correct 21 ms 38440 KB Output is correct
15 Correct 18 ms 38236 KB Output is correct
16 Correct 19 ms 38232 KB Output is correct
17 Correct 23 ms 38588 KB Output is correct
18 Correct 20 ms 38236 KB Output is correct
19 Correct 20 ms 38348 KB Output is correct
20 Correct 24 ms 38460 KB Output is correct
21 Correct 20 ms 38428 KB Output is correct
22 Correct 17 ms 38296 KB Output is correct
23 Correct 25 ms 38576 KB Output is correct
24 Correct 18 ms 38236 KB Output is correct
25 Correct 22 ms 38448 KB Output is correct
26 Correct 22 ms 38448 KB Output is correct
27 Correct 22 ms 38408 KB Output is correct
28 Correct 22 ms 38116 KB Output is correct
29 Correct 21 ms 38384 KB Output is correct
30 Correct 18 ms 38236 KB Output is correct
31 Correct 23 ms 38436 KB Output is correct
32 Correct 21 ms 38380 KB Output is correct
33 Correct 21 ms 38372 KB Output is correct
34 Correct 21 ms 38400 KB Output is correct
35 Correct 26 ms 38448 KB Output is correct
36 Correct 21 ms 38468 KB Output is correct
37 Correct 26 ms 38560 KB Output is correct
38 Correct 28 ms 38480 KB Output is correct
39 Correct 23 ms 38572 KB Output is correct
40 Correct 21 ms 38380 KB Output is correct
41 Correct 23 ms 38600 KB Output is correct
42 Correct 23 ms 38548 KB Output is correct
43 Correct 22 ms 38592 KB Output is correct
44 Correct 25 ms 38488 KB Output is correct
45 Correct 23 ms 38628 KB Output is correct
46 Correct 23 ms 38444 KB Output is correct
47 Correct 23 ms 38452 KB Output is correct
48 Correct 22 ms 38540 KB Output is correct
49 Correct 24 ms 38444 KB Output is correct
50 Correct 25 ms 38364 KB Output is correct
51 Correct 28 ms 38480 KB Output is correct
52 Correct 23 ms 38460 KB Output is correct
53 Correct 24 ms 38412 KB Output is correct
54 Correct 24 ms 38528 KB Output is correct
55 Correct 21 ms 38492 KB Output is correct
56 Correct 21 ms 38380 KB Output is correct
57 Correct 20 ms 38348 KB Output is correct
58 Correct 22 ms 38480 KB Output is correct
59 Correct 101 ms 63088 KB Output is correct
60 Correct 95 ms 60608 KB Output is correct
61 Correct 94 ms 61184 KB Output is correct
62 Correct 92 ms 59488 KB Output is correct
63 Correct 93 ms 62092 KB Output is correct
64 Correct 93 ms 58240 KB Output is correct
65 Correct 169 ms 68804 KB Output is correct
66 Correct 257 ms 70844 KB Output is correct
67 Correct 275 ms 79320 KB Output is correct
68 Correct 335 ms 80080 KB Output is correct
69 Correct 457 ms 81836 KB Output is correct
70 Correct 325 ms 75536 KB Output is correct
71 Correct 299 ms 80736 KB Output is correct
72 Correct 827 ms 97904 KB Output is correct
73 Correct 220 ms 77584 KB Output is correct
74 Correct 134 ms 70208 KB Output is correct
75 Correct 507 ms 83700 KB Output is correct
76 Correct 130 ms 68756 KB Output is correct
77 Correct 216 ms 77376 KB Output is correct
78 Correct 948 ms 89400 KB Output is correct
79 Correct 190 ms 74492 KB Output is correct
80 Correct 115 ms 67480 KB Output is correct
81 Correct 823 ms 97572 KB Output is correct
82 Correct 98 ms 62656 KB Output is correct
83 Correct 406 ms 80652 KB Output is correct
84 Correct 415 ms 78872 KB Output is correct
85 Correct 650 ms 80564 KB Output is correct
86 Correct 117 ms 64872 KB Output is correct
87 Correct 708 ms 80352 KB Output is correct
88 Correct 110 ms 66288 KB Output is correct
89 Correct 636 ms 93440 KB Output is correct
90 Correct 927 ms 91492 KB Output is correct
91 Correct 624 ms 90684 KB Output is correct
92 Correct 956 ms 99708 KB Output is correct
93 Correct 796 ms 105636 KB Output is correct
94 Correct 843 ms 93636 KB Output is correct
95 Correct 950 ms 93148 KB Output is correct
96 Correct 721 ms 102432 KB Output is correct
97 Correct 842 ms 102152 KB Output is correct
98 Correct 784 ms 96364 KB Output is correct
99 Correct 619 ms 93508 KB Output is correct
100 Correct 960 ms 93572 KB Output is correct
101 Correct 884 ms 97020 KB Output is correct
102 Correct 440 ms 79912 KB Output is correct
103 Correct 992 ms 91604 KB Output is correct
104 Correct 560 ms 87712 KB Output is correct
105 Correct 946 ms 94696 KB Output is correct
106 Correct 825 ms 94124 KB Output is correct
107 Correct 778 ms 96892 KB Output is correct
108 Correct 913 ms 97456 KB Output is correct
109 Correct 934 ms 92364 KB Output is correct
110 Correct 917 ms 96392 KB Output is correct
111 Correct 835 ms 99628 KB Output is correct
112 Correct 968 ms 94772 KB Output is correct
113 Correct 410 ms 83892 KB Output is correct
114 Correct 431 ms 83772 KB Output is correct
115 Correct 412 ms 83960 KB Output is correct
116 Correct 414 ms 83880 KB Output is correct
117 Correct 868 ms 163180 KB Output is correct
118 Correct 836 ms 163148 KB Output is correct
119 Correct 856 ms 163144 KB Output is correct
120 Correct 874 ms 163164 KB Output is correct
121 Correct 846 ms 163120 KB Output is correct
122 Correct 858 ms 163120 KB Output is correct
123 Correct 877 ms 163156 KB Output is correct
124 Correct 866 ms 163044 KB Output is correct
125 Correct 839 ms 163156 KB Output is correct
126 Correct 845 ms 163044 KB Output is correct