Submission #609823

# Submission time Handle Problem Language Result Execution time Memory
609823 2022-07-28T00:27:58 Z StrawHatWess Fountain Parks (IOI21_parks) C++17
30 / 100
385 ms 91828 KB
#include "parks.h"

#include <bits/stdc++.h>
using namespace std; 

#define FOR(i,a,b) for(int i=a; i<b; i++)
typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)


typedef pair<int,int>pi; 
#define fi first
#define se second
typedef vector<pi>vpi;
#define eb emplace_back

bool ckmin(int &x, int y){
    bool f=(x>y); 
    x=min(x,y); 
    return f; 
}

bool ckmax(int &x, int y){
    bool f=(x<y); 
    x=max(x,y); 
    return f; 
}

//-------


const int MX=2e5+100;


vi rnk(MX,0), p(MX); 
int findSet(int i){return p[i]==i ? i : p[i]=findSet(p[i]); }

void unionSet(int u, int v){
    u=findSet(u), v=findSet(v); 

    if(rnk[u]<rnk[v]) swap(u,v); 
    if(rnk[u]==rnk[v]) rnk[u]++; 

    p[v]=u; 
}



int N; 
vi X, Y; 

unordered_map<int,int>pos[MX], vis[MX]; 

vpi ver[MX], hor[MX]; 
int construct_roads(vi X, vi Y) {
    N=sz(X); 
    ::X=X; ::Y=Y; 

    if (N==1) {
        build({}, {}, {}, {});
        return 1;
    }
    
   
    FOR(i,0,N) pos[X[i]][Y[i]]=i, p[i]=i; 


    //building vertical 
    vpi roads; 
    FOR(i,0,N){
        int x=X[i], y=Y[i]; 
        if(pos[x].count(y-2)){
            int j=pos[x][y-2]; 
            if(findSet(i)!=findSet(j)){
                roads.eb(j,i);
                unionSet(i,j); 
            }
            
        }
    }
    //building horizontal
    FOR(i,0,N){
        int x=X[i], y=Y[i]; 
        if(pos[x-2].count(y)){
            int j=pos[x-2][y]; 
            if(findSet(i)!=findSet(j)){
                roads.eb(j,i);
                unionSet(i,j); 
            }
        }
    }


    //checking connectivity
    FOR(i,0,N) if(findSet(i)!=findSet(0)) return 0; 

    for(auto it: roads){
        int i=it.fi, j=it.se; 
        if(X[i]==X[j]) ver[X[i]].eb(i,j); 
        else hor[X[i]].eb(i,j); 
    }

    vpi nw; 
    FOR(x,0,MX){
        for(pi cur: ver[x]) nw.pb(cur); 
        for(pi cur: hor[x]) nw.pb(cur); 
    }
    roads=nw; 

    vi u,v,A,B; 
    for(auto it: roads){
        int i=it.fi, j=it.se; 
        u.pb(i); v.pb(j); 

        if(X[i]==X[j]){
            //vertical
            int x=X[i], y=Y[i]; 

            if(!vis[x-1].count(y+1)){
                A.pb(x-1); B.pb(y+1); 
                vis[x-1][y+1]=1; 
            }
            else{
                if(vis[x+1].count(y+1)) return 0; 

                A.pb(x+1); B.pb(y+1); 
                vis[x+1][y+1]=1; 
            }
        }
        else{
            //horizontal
            int x=X[i], y=Y[i];  

            if(!pos[x].count(y-2)){
                if(!vis[x+1].count(y+1)){
                    A.pb(x+1); B.pb(y+1); 
                    vis[x+1][y+1]=1; 
                }
                else{
                    if(vis[x+1].count(y-1)) return 0; 

                    A.pb(x+1); B.pb(y-1); 
                    vis[x+1][y-1]=1; 
                }
            }
            else{
                if(!vis[x+1].count(y-1)){
                    A.pb(x+1); B.pb(y-1); 
                    vis[x+1][y-1]=1; 
                }
                else if(!vis[x+1].count(y+1)){
                    A.pb(x+1); B.pb(y+1); 
                    vis[x+1][y+1]=1; 
                }
                else return 0; 
            }
            

        }
    }



    build(u, v, A, B);
    return 1;
}


/*
5
4 4
4 6
6 4
4 2
2 4

1
4
0 2 5 5
0 1 3 5
3 0 5 3
4 0 3 3




*/

/*

2
2 2
4 6

0


*/
# Verdict Execution time Memory Grader output
1 Correct 18 ms 33236 KB Output is correct
2 Correct 17 ms 33096 KB Output is correct
3 Correct 17 ms 33108 KB Output is correct
4 Correct 17 ms 33152 KB Output is correct
5 Correct 18 ms 33108 KB Output is correct
6 Correct 17 ms 33108 KB Output is correct
7 Correct 17 ms 33140 KB Output is correct
8 Correct 17 ms 33108 KB Output is correct
9 Correct 101 ms 51904 KB Output is correct
10 Correct 24 ms 34996 KB Output is correct
11 Correct 54 ms 42944 KB Output is correct
12 Correct 30 ms 36016 KB Output is correct
13 Correct 30 ms 37092 KB Output is correct
14 Correct 18 ms 33252 KB Output is correct
15 Correct 18 ms 33372 KB Output is correct
16 Correct 103 ms 51888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 33236 KB Output is correct
2 Correct 17 ms 33096 KB Output is correct
3 Correct 17 ms 33108 KB Output is correct
4 Correct 17 ms 33152 KB Output is correct
5 Correct 18 ms 33108 KB Output is correct
6 Correct 17 ms 33108 KB Output is correct
7 Correct 17 ms 33140 KB Output is correct
8 Correct 17 ms 33108 KB Output is correct
9 Correct 101 ms 51904 KB Output is correct
10 Correct 24 ms 34996 KB Output is correct
11 Correct 54 ms 42944 KB Output is correct
12 Correct 30 ms 36016 KB Output is correct
13 Correct 30 ms 37092 KB Output is correct
14 Correct 18 ms 33252 KB Output is correct
15 Correct 18 ms 33372 KB Output is correct
16 Correct 103 ms 51888 KB Output is correct
17 Correct 17 ms 33112 KB Output is correct
18 Correct 17 ms 33112 KB Output is correct
19 Correct 18 ms 33208 KB Output is correct
20 Correct 21 ms 33108 KB Output is correct
21 Correct 17 ms 33212 KB Output is correct
22 Correct 18 ms 33140 KB Output is correct
23 Correct 231 ms 70316 KB Output is correct
24 Correct 18 ms 33144 KB Output is correct
25 Correct 19 ms 33472 KB Output is correct
26 Correct 18 ms 33388 KB Output is correct
27 Correct 18 ms 33432 KB Output is correct
28 Correct 84 ms 47292 KB Output is correct
29 Correct 124 ms 54788 KB Output is correct
30 Correct 181 ms 61412 KB Output is correct
31 Correct 227 ms 70328 KB Output is correct
32 Correct 18 ms 33108 KB Output is correct
33 Correct 18 ms 33108 KB Output is correct
34 Correct 17 ms 33184 KB Output is correct
35 Correct 17 ms 33108 KB Output is correct
36 Correct 16 ms 33108 KB Output is correct
37 Correct 17 ms 33116 KB Output is correct
38 Correct 17 ms 33108 KB Output is correct
39 Correct 17 ms 33108 KB Output is correct
40 Correct 17 ms 33108 KB Output is correct
41 Correct 17 ms 33108 KB Output is correct
42 Correct 21 ms 33100 KB Output is correct
43 Correct 18 ms 33296 KB Output is correct
44 Correct 18 ms 33452 KB Output is correct
45 Correct 109 ms 51556 KB Output is correct
46 Correct 165 ms 59916 KB Output is correct
47 Correct 165 ms 59980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 33236 KB Output is correct
2 Correct 17 ms 33096 KB Output is correct
3 Correct 17 ms 33108 KB Output is correct
4 Correct 17 ms 33152 KB Output is correct
5 Correct 18 ms 33108 KB Output is correct
6 Correct 17 ms 33108 KB Output is correct
7 Correct 17 ms 33140 KB Output is correct
8 Correct 17 ms 33108 KB Output is correct
9 Correct 101 ms 51904 KB Output is correct
10 Correct 24 ms 34996 KB Output is correct
11 Correct 54 ms 42944 KB Output is correct
12 Correct 30 ms 36016 KB Output is correct
13 Correct 30 ms 37092 KB Output is correct
14 Correct 18 ms 33252 KB Output is correct
15 Correct 18 ms 33372 KB Output is correct
16 Correct 103 ms 51888 KB Output is correct
17 Correct 17 ms 33112 KB Output is correct
18 Correct 17 ms 33112 KB Output is correct
19 Correct 18 ms 33208 KB Output is correct
20 Correct 21 ms 33108 KB Output is correct
21 Correct 17 ms 33212 KB Output is correct
22 Correct 18 ms 33140 KB Output is correct
23 Correct 231 ms 70316 KB Output is correct
24 Correct 18 ms 33144 KB Output is correct
25 Correct 19 ms 33472 KB Output is correct
26 Correct 18 ms 33388 KB Output is correct
27 Correct 18 ms 33432 KB Output is correct
28 Correct 84 ms 47292 KB Output is correct
29 Correct 124 ms 54788 KB Output is correct
30 Correct 181 ms 61412 KB Output is correct
31 Correct 227 ms 70328 KB Output is correct
32 Correct 18 ms 33108 KB Output is correct
33 Correct 18 ms 33108 KB Output is correct
34 Correct 17 ms 33184 KB Output is correct
35 Correct 17 ms 33108 KB Output is correct
36 Correct 16 ms 33108 KB Output is correct
37 Correct 17 ms 33116 KB Output is correct
38 Correct 17 ms 33108 KB Output is correct
39 Correct 17 ms 33108 KB Output is correct
40 Correct 17 ms 33108 KB Output is correct
41 Correct 17 ms 33108 KB Output is correct
42 Correct 21 ms 33100 KB Output is correct
43 Correct 18 ms 33296 KB Output is correct
44 Correct 18 ms 33452 KB Output is correct
45 Correct 109 ms 51556 KB Output is correct
46 Correct 165 ms 59916 KB Output is correct
47 Correct 165 ms 59980 KB Output is correct
48 Correct 17 ms 33108 KB Output is correct
49 Correct 16 ms 33108 KB Output is correct
50 Correct 22 ms 33216 KB Output is correct
51 Correct 18 ms 33172 KB Output is correct
52 Correct 18 ms 33164 KB Output is correct
53 Correct 20 ms 33340 KB Output is correct
54 Correct 17 ms 33108 KB Output is correct
55 Correct 226 ms 69232 KB Output is correct
56 Correct 17 ms 33108 KB Output is correct
57 Correct 22 ms 33556 KB Output is correct
58 Correct 22 ms 34296 KB Output is correct
59 Correct 22 ms 34060 KB Output is correct
60 Correct 107 ms 51156 KB Output is correct
61 Correct 156 ms 60264 KB Output is correct
62 Correct 193 ms 63916 KB Output is correct
63 Correct 228 ms 69244 KB Output is correct
64 Correct 17 ms 33204 KB Output is correct
65 Correct 18 ms 33108 KB Output is correct
66 Correct 17 ms 33148 KB Output is correct
67 Correct 219 ms 70568 KB Output is correct
68 Correct 220 ms 70388 KB Output is correct
69 Correct 217 ms 70456 KB Output is correct
70 Correct 18 ms 33492 KB Output is correct
71 Correct 20 ms 33900 KB Output is correct
72 Correct 108 ms 51012 KB Output is correct
73 Correct 176 ms 61552 KB Output is correct
74 Correct 239 ms 69200 KB Output is correct
75 Correct 230 ms 68284 KB Output is correct
76 Correct 218 ms 70316 KB Output is correct
77 Correct 19 ms 33560 KB Output is correct
78 Correct 21 ms 34004 KB Output is correct
79 Correct 116 ms 51040 KB Output is correct
80 Correct 173 ms 61544 KB Output is correct
81 Correct 240 ms 68940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 33236 KB Output is correct
2 Correct 17 ms 33096 KB Output is correct
3 Correct 17 ms 33108 KB Output is correct
4 Correct 17 ms 33152 KB Output is correct
5 Correct 18 ms 33108 KB Output is correct
6 Correct 17 ms 33108 KB Output is correct
7 Correct 17 ms 33140 KB Output is correct
8 Correct 17 ms 33108 KB Output is correct
9 Correct 101 ms 51904 KB Output is correct
10 Correct 24 ms 34996 KB Output is correct
11 Correct 54 ms 42944 KB Output is correct
12 Correct 30 ms 36016 KB Output is correct
13 Correct 30 ms 37092 KB Output is correct
14 Correct 18 ms 33252 KB Output is correct
15 Correct 18 ms 33372 KB Output is correct
16 Correct 103 ms 51888 KB Output is correct
17 Correct 17 ms 33108 KB Output is correct
18 Correct 17 ms 33220 KB Output is correct
19 Correct 16 ms 33192 KB Output is correct
20 Correct 385 ms 91828 KB Output is correct
21 Correct 333 ms 77536 KB Output is correct
22 Correct 323 ms 77628 KB Output is correct
23 Correct 264 ms 73232 KB Output is correct
24 Correct 95 ms 45768 KB Output is correct
25 Correct 136 ms 48036 KB Output is correct
26 Correct 125 ms 48064 KB Output is correct
27 Correct 222 ms 68268 KB Output is correct
28 Correct 220 ms 68296 KB Output is correct
29 Correct 267 ms 69496 KB Output is correct
30 Correct 257 ms 69492 KB Output is correct
31 Correct 18 ms 33164 KB Output is correct
32 Incorrect 29 ms 34640 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 33236 KB Output is correct
2 Correct 17 ms 33096 KB Output is correct
3 Correct 17 ms 33108 KB Output is correct
4 Correct 17 ms 33152 KB Output is correct
5 Correct 18 ms 33108 KB Output is correct
6 Correct 17 ms 33108 KB Output is correct
7 Correct 17 ms 33140 KB Output is correct
8 Correct 17 ms 33108 KB Output is correct
9 Correct 101 ms 51904 KB Output is correct
10 Correct 24 ms 34996 KB Output is correct
11 Correct 54 ms 42944 KB Output is correct
12 Correct 30 ms 36016 KB Output is correct
13 Correct 30 ms 37092 KB Output is correct
14 Correct 18 ms 33252 KB Output is correct
15 Correct 18 ms 33372 KB Output is correct
16 Correct 103 ms 51888 KB Output is correct
17 Correct 293 ms 79356 KB Output is correct
18 Correct 307 ms 79416 KB Output is correct
19 Correct 349 ms 77540 KB Output is correct
20 Correct 259 ms 68492 KB Output is correct
21 Correct 239 ms 66204 KB Output is correct
22 Correct 18 ms 33108 KB Output is correct
23 Incorrect 36 ms 36620 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 33236 KB Output is correct
2 Correct 17 ms 33096 KB Output is correct
3 Correct 17 ms 33108 KB Output is correct
4 Correct 17 ms 33152 KB Output is correct
5 Correct 18 ms 33108 KB Output is correct
6 Correct 17 ms 33108 KB Output is correct
7 Correct 17 ms 33140 KB Output is correct
8 Correct 17 ms 33108 KB Output is correct
9 Correct 101 ms 51904 KB Output is correct
10 Correct 24 ms 34996 KB Output is correct
11 Correct 54 ms 42944 KB Output is correct
12 Correct 30 ms 36016 KB Output is correct
13 Correct 30 ms 37092 KB Output is correct
14 Correct 18 ms 33252 KB Output is correct
15 Correct 18 ms 33372 KB Output is correct
16 Correct 103 ms 51888 KB Output is correct
17 Correct 17 ms 33112 KB Output is correct
18 Correct 17 ms 33112 KB Output is correct
19 Correct 18 ms 33208 KB Output is correct
20 Correct 21 ms 33108 KB Output is correct
21 Correct 17 ms 33212 KB Output is correct
22 Correct 18 ms 33140 KB Output is correct
23 Correct 231 ms 70316 KB Output is correct
24 Correct 18 ms 33144 KB Output is correct
25 Correct 19 ms 33472 KB Output is correct
26 Correct 18 ms 33388 KB Output is correct
27 Correct 18 ms 33432 KB Output is correct
28 Correct 84 ms 47292 KB Output is correct
29 Correct 124 ms 54788 KB Output is correct
30 Correct 181 ms 61412 KB Output is correct
31 Correct 227 ms 70328 KB Output is correct
32 Correct 18 ms 33108 KB Output is correct
33 Correct 18 ms 33108 KB Output is correct
34 Correct 17 ms 33184 KB Output is correct
35 Correct 17 ms 33108 KB Output is correct
36 Correct 16 ms 33108 KB Output is correct
37 Correct 17 ms 33116 KB Output is correct
38 Correct 17 ms 33108 KB Output is correct
39 Correct 17 ms 33108 KB Output is correct
40 Correct 17 ms 33108 KB Output is correct
41 Correct 17 ms 33108 KB Output is correct
42 Correct 21 ms 33100 KB Output is correct
43 Correct 18 ms 33296 KB Output is correct
44 Correct 18 ms 33452 KB Output is correct
45 Correct 109 ms 51556 KB Output is correct
46 Correct 165 ms 59916 KB Output is correct
47 Correct 165 ms 59980 KB Output is correct
48 Correct 17 ms 33108 KB Output is correct
49 Correct 16 ms 33108 KB Output is correct
50 Correct 22 ms 33216 KB Output is correct
51 Correct 18 ms 33172 KB Output is correct
52 Correct 18 ms 33164 KB Output is correct
53 Correct 20 ms 33340 KB Output is correct
54 Correct 17 ms 33108 KB Output is correct
55 Correct 226 ms 69232 KB Output is correct
56 Correct 17 ms 33108 KB Output is correct
57 Correct 22 ms 33556 KB Output is correct
58 Correct 22 ms 34296 KB Output is correct
59 Correct 22 ms 34060 KB Output is correct
60 Correct 107 ms 51156 KB Output is correct
61 Correct 156 ms 60264 KB Output is correct
62 Correct 193 ms 63916 KB Output is correct
63 Correct 228 ms 69244 KB Output is correct
64 Correct 17 ms 33204 KB Output is correct
65 Correct 18 ms 33108 KB Output is correct
66 Correct 17 ms 33148 KB Output is correct
67 Correct 219 ms 70568 KB Output is correct
68 Correct 220 ms 70388 KB Output is correct
69 Correct 217 ms 70456 KB Output is correct
70 Correct 18 ms 33492 KB Output is correct
71 Correct 20 ms 33900 KB Output is correct
72 Correct 108 ms 51012 KB Output is correct
73 Correct 176 ms 61552 KB Output is correct
74 Correct 239 ms 69200 KB Output is correct
75 Correct 230 ms 68284 KB Output is correct
76 Correct 218 ms 70316 KB Output is correct
77 Correct 19 ms 33560 KB Output is correct
78 Correct 21 ms 34004 KB Output is correct
79 Correct 116 ms 51040 KB Output is correct
80 Correct 173 ms 61544 KB Output is correct
81 Correct 240 ms 68940 KB Output is correct
82 Correct 17 ms 33108 KB Output is correct
83 Correct 17 ms 33220 KB Output is correct
84 Correct 16 ms 33192 KB Output is correct
85 Correct 385 ms 91828 KB Output is correct
86 Correct 333 ms 77536 KB Output is correct
87 Correct 323 ms 77628 KB Output is correct
88 Correct 264 ms 73232 KB Output is correct
89 Correct 95 ms 45768 KB Output is correct
90 Correct 136 ms 48036 KB Output is correct
91 Correct 125 ms 48064 KB Output is correct
92 Correct 222 ms 68268 KB Output is correct
93 Correct 220 ms 68296 KB Output is correct
94 Correct 267 ms 69496 KB Output is correct
95 Correct 257 ms 69492 KB Output is correct
96 Correct 18 ms 33164 KB Output is correct
97 Incorrect 29 ms 34640 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -