답안 #609814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
609814 2022-07-27T23:22:11 Z StrawHatWess 분수 공원 (IOI21_parks) C++17
30 / 100
332 ms 91964 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(!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; 
            }

        }
    }



    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


*/
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 33108 KB Output is correct
2 Correct 18 ms 33108 KB Output is correct
3 Correct 18 ms 33204 KB Output is correct
4 Correct 19 ms 33152 KB Output is correct
5 Correct 22 ms 33204 KB Output is correct
6 Correct 19 ms 33128 KB Output is correct
7 Correct 17 ms 33192 KB Output is correct
8 Correct 17 ms 33108 KB Output is correct
9 Correct 107 ms 51904 KB Output is correct
10 Correct 25 ms 35000 KB Output is correct
11 Correct 52 ms 42972 KB Output is correct
12 Correct 27 ms 36080 KB Output is correct
13 Correct 28 ms 37060 KB Output is correct
14 Correct 19 ms 33256 KB Output is correct
15 Correct 17 ms 33252 KB Output is correct
16 Correct 100 ms 51908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 33108 KB Output is correct
2 Correct 18 ms 33108 KB Output is correct
3 Correct 18 ms 33204 KB Output is correct
4 Correct 19 ms 33152 KB Output is correct
5 Correct 22 ms 33204 KB Output is correct
6 Correct 19 ms 33128 KB Output is correct
7 Correct 17 ms 33192 KB Output is correct
8 Correct 17 ms 33108 KB Output is correct
9 Correct 107 ms 51904 KB Output is correct
10 Correct 25 ms 35000 KB Output is correct
11 Correct 52 ms 42972 KB Output is correct
12 Correct 27 ms 36080 KB Output is correct
13 Correct 28 ms 37060 KB Output is correct
14 Correct 19 ms 33256 KB Output is correct
15 Correct 17 ms 33252 KB Output is correct
16 Correct 100 ms 51908 KB Output is correct
17 Correct 17 ms 33112 KB Output is correct
18 Correct 17 ms 33108 KB Output is correct
19 Correct 17 ms 33104 KB Output is correct
20 Correct 18 ms 33332 KB Output is correct
21 Correct 17 ms 33172 KB Output is correct
22 Correct 18 ms 33156 KB Output is correct
23 Correct 251 ms 70484 KB Output is correct
24 Correct 18 ms 33108 KB Output is correct
25 Correct 21 ms 33552 KB Output is correct
26 Correct 22 ms 33476 KB Output is correct
27 Correct 18 ms 33532 KB Output is correct
28 Correct 83 ms 47820 KB Output is correct
29 Correct 125 ms 55236 KB Output is correct
30 Correct 165 ms 62032 KB Output is correct
31 Correct 240 ms 70856 KB Output is correct
32 Correct 18 ms 33216 KB Output is correct
33 Correct 18 ms 33096 KB Output is correct
34 Correct 18 ms 33136 KB Output is correct
35 Correct 17 ms 33216 KB Output is correct
36 Correct 18 ms 33224 KB Output is correct
37 Correct 18 ms 33108 KB Output is correct
38 Correct 18 ms 33108 KB Output is correct
39 Correct 18 ms 33100 KB Output is correct
40 Correct 18 ms 33108 KB Output is correct
41 Correct 18 ms 33140 KB Output is correct
42 Correct 18 ms 33104 KB Output is correct
43 Correct 19 ms 33364 KB Output is correct
44 Correct 19 ms 33492 KB Output is correct
45 Correct 110 ms 52040 KB Output is correct
46 Correct 155 ms 60388 KB Output is correct
47 Correct 164 ms 60556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 33108 KB Output is correct
2 Correct 18 ms 33108 KB Output is correct
3 Correct 18 ms 33204 KB Output is correct
4 Correct 19 ms 33152 KB Output is correct
5 Correct 22 ms 33204 KB Output is correct
6 Correct 19 ms 33128 KB Output is correct
7 Correct 17 ms 33192 KB Output is correct
8 Correct 17 ms 33108 KB Output is correct
9 Correct 107 ms 51904 KB Output is correct
10 Correct 25 ms 35000 KB Output is correct
11 Correct 52 ms 42972 KB Output is correct
12 Correct 27 ms 36080 KB Output is correct
13 Correct 28 ms 37060 KB Output is correct
14 Correct 19 ms 33256 KB Output is correct
15 Correct 17 ms 33252 KB Output is correct
16 Correct 100 ms 51908 KB Output is correct
17 Correct 17 ms 33112 KB Output is correct
18 Correct 17 ms 33108 KB Output is correct
19 Correct 17 ms 33104 KB Output is correct
20 Correct 18 ms 33332 KB Output is correct
21 Correct 17 ms 33172 KB Output is correct
22 Correct 18 ms 33156 KB Output is correct
23 Correct 251 ms 70484 KB Output is correct
24 Correct 18 ms 33108 KB Output is correct
25 Correct 21 ms 33552 KB Output is correct
26 Correct 22 ms 33476 KB Output is correct
27 Correct 18 ms 33532 KB Output is correct
28 Correct 83 ms 47820 KB Output is correct
29 Correct 125 ms 55236 KB Output is correct
30 Correct 165 ms 62032 KB Output is correct
31 Correct 240 ms 70856 KB Output is correct
32 Correct 18 ms 33216 KB Output is correct
33 Correct 18 ms 33096 KB Output is correct
34 Correct 18 ms 33136 KB Output is correct
35 Correct 17 ms 33216 KB Output is correct
36 Correct 18 ms 33224 KB Output is correct
37 Correct 18 ms 33108 KB Output is correct
38 Correct 18 ms 33108 KB Output is correct
39 Correct 18 ms 33100 KB Output is correct
40 Correct 18 ms 33108 KB Output is correct
41 Correct 18 ms 33140 KB Output is correct
42 Correct 18 ms 33104 KB Output is correct
43 Correct 19 ms 33364 KB Output is correct
44 Correct 19 ms 33492 KB Output is correct
45 Correct 110 ms 52040 KB Output is correct
46 Correct 155 ms 60388 KB Output is correct
47 Correct 164 ms 60556 KB Output is correct
48 Correct 17 ms 33108 KB Output is correct
49 Correct 19 ms 33108 KB Output is correct
50 Correct 18 ms 33212 KB Output is correct
51 Correct 17 ms 33108 KB Output is correct
52 Correct 18 ms 33108 KB Output is correct
53 Correct 18 ms 33112 KB Output is correct
54 Correct 18 ms 33108 KB Output is correct
55 Correct 233 ms 69768 KB Output is correct
56 Correct 18 ms 33108 KB Output is correct
57 Correct 20 ms 33476 KB Output is correct
58 Correct 26 ms 34412 KB Output is correct
59 Correct 23 ms 34072 KB Output is correct
60 Correct 133 ms 51736 KB Output is correct
61 Correct 160 ms 60788 KB Output is correct
62 Correct 230 ms 64464 KB Output is correct
63 Correct 247 ms 69784 KB Output is correct
64 Correct 18 ms 33108 KB Output is correct
65 Correct 18 ms 33216 KB Output is correct
66 Correct 17 ms 33212 KB Output is correct
67 Correct 233 ms 71128 KB Output is correct
68 Correct 215 ms 70812 KB Output is correct
69 Correct 213 ms 71028 KB Output is correct
70 Correct 18 ms 33492 KB Output is correct
71 Correct 20 ms 33968 KB Output is correct
72 Correct 109 ms 51608 KB Output is correct
73 Correct 173 ms 61620 KB Output is correct
74 Correct 228 ms 69848 KB Output is correct
75 Correct 259 ms 68760 KB Output is correct
76 Correct 224 ms 70832 KB Output is correct
77 Correct 19 ms 33620 KB Output is correct
78 Correct 22 ms 34004 KB Output is correct
79 Correct 107 ms 51508 KB Output is correct
80 Correct 183 ms 62216 KB Output is correct
81 Correct 230 ms 69456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 33108 KB Output is correct
2 Correct 18 ms 33108 KB Output is correct
3 Correct 18 ms 33204 KB Output is correct
4 Correct 19 ms 33152 KB Output is correct
5 Correct 22 ms 33204 KB Output is correct
6 Correct 19 ms 33128 KB Output is correct
7 Correct 17 ms 33192 KB Output is correct
8 Correct 17 ms 33108 KB Output is correct
9 Correct 107 ms 51904 KB Output is correct
10 Correct 25 ms 35000 KB Output is correct
11 Correct 52 ms 42972 KB Output is correct
12 Correct 27 ms 36080 KB Output is correct
13 Correct 28 ms 37060 KB Output is correct
14 Correct 19 ms 33256 KB Output is correct
15 Correct 17 ms 33252 KB Output is correct
16 Correct 100 ms 51908 KB Output is correct
17 Correct 21 ms 33108 KB Output is correct
18 Correct 18 ms 33200 KB Output is correct
19 Correct 18 ms 33148 KB Output is correct
20 Correct 332 ms 91964 KB Output is correct
21 Correct 315 ms 77540 KB Output is correct
22 Correct 329 ms 77464 KB Output is correct
23 Correct 263 ms 73148 KB Output is correct
24 Correct 115 ms 45936 KB Output is correct
25 Correct 188 ms 47948 KB Output is correct
26 Correct 125 ms 48156 KB Output is correct
27 Correct 216 ms 68308 KB Output is correct
28 Correct 239 ms 68292 KB Output is correct
29 Correct 291 ms 69476 KB Output is correct
30 Correct 254 ms 69492 KB Output is correct
31 Correct 17 ms 33108 KB Output is correct
32 Incorrect 25 ms 34816 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 33108 KB Output is correct
2 Correct 18 ms 33108 KB Output is correct
3 Correct 18 ms 33204 KB Output is correct
4 Correct 19 ms 33152 KB Output is correct
5 Correct 22 ms 33204 KB Output is correct
6 Correct 19 ms 33128 KB Output is correct
7 Correct 17 ms 33192 KB Output is correct
8 Correct 17 ms 33108 KB Output is correct
9 Correct 107 ms 51904 KB Output is correct
10 Correct 25 ms 35000 KB Output is correct
11 Correct 52 ms 42972 KB Output is correct
12 Correct 27 ms 36080 KB Output is correct
13 Correct 28 ms 37060 KB Output is correct
14 Correct 19 ms 33256 KB Output is correct
15 Correct 17 ms 33252 KB Output is correct
16 Correct 100 ms 51908 KB Output is correct
17 Correct 283 ms 79352 KB Output is correct
18 Correct 278 ms 79392 KB Output is correct
19 Incorrect 301 ms 71500 KB Solution announced impossible, but it is possible.
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 33108 KB Output is correct
2 Correct 18 ms 33108 KB Output is correct
3 Correct 18 ms 33204 KB Output is correct
4 Correct 19 ms 33152 KB Output is correct
5 Correct 22 ms 33204 KB Output is correct
6 Correct 19 ms 33128 KB Output is correct
7 Correct 17 ms 33192 KB Output is correct
8 Correct 17 ms 33108 KB Output is correct
9 Correct 107 ms 51904 KB Output is correct
10 Correct 25 ms 35000 KB Output is correct
11 Correct 52 ms 42972 KB Output is correct
12 Correct 27 ms 36080 KB Output is correct
13 Correct 28 ms 37060 KB Output is correct
14 Correct 19 ms 33256 KB Output is correct
15 Correct 17 ms 33252 KB Output is correct
16 Correct 100 ms 51908 KB Output is correct
17 Correct 17 ms 33112 KB Output is correct
18 Correct 17 ms 33108 KB Output is correct
19 Correct 17 ms 33104 KB Output is correct
20 Correct 18 ms 33332 KB Output is correct
21 Correct 17 ms 33172 KB Output is correct
22 Correct 18 ms 33156 KB Output is correct
23 Correct 251 ms 70484 KB Output is correct
24 Correct 18 ms 33108 KB Output is correct
25 Correct 21 ms 33552 KB Output is correct
26 Correct 22 ms 33476 KB Output is correct
27 Correct 18 ms 33532 KB Output is correct
28 Correct 83 ms 47820 KB Output is correct
29 Correct 125 ms 55236 KB Output is correct
30 Correct 165 ms 62032 KB Output is correct
31 Correct 240 ms 70856 KB Output is correct
32 Correct 18 ms 33216 KB Output is correct
33 Correct 18 ms 33096 KB Output is correct
34 Correct 18 ms 33136 KB Output is correct
35 Correct 17 ms 33216 KB Output is correct
36 Correct 18 ms 33224 KB Output is correct
37 Correct 18 ms 33108 KB Output is correct
38 Correct 18 ms 33108 KB Output is correct
39 Correct 18 ms 33100 KB Output is correct
40 Correct 18 ms 33108 KB Output is correct
41 Correct 18 ms 33140 KB Output is correct
42 Correct 18 ms 33104 KB Output is correct
43 Correct 19 ms 33364 KB Output is correct
44 Correct 19 ms 33492 KB Output is correct
45 Correct 110 ms 52040 KB Output is correct
46 Correct 155 ms 60388 KB Output is correct
47 Correct 164 ms 60556 KB Output is correct
48 Correct 17 ms 33108 KB Output is correct
49 Correct 19 ms 33108 KB Output is correct
50 Correct 18 ms 33212 KB Output is correct
51 Correct 17 ms 33108 KB Output is correct
52 Correct 18 ms 33108 KB Output is correct
53 Correct 18 ms 33112 KB Output is correct
54 Correct 18 ms 33108 KB Output is correct
55 Correct 233 ms 69768 KB Output is correct
56 Correct 18 ms 33108 KB Output is correct
57 Correct 20 ms 33476 KB Output is correct
58 Correct 26 ms 34412 KB Output is correct
59 Correct 23 ms 34072 KB Output is correct
60 Correct 133 ms 51736 KB Output is correct
61 Correct 160 ms 60788 KB Output is correct
62 Correct 230 ms 64464 KB Output is correct
63 Correct 247 ms 69784 KB Output is correct
64 Correct 18 ms 33108 KB Output is correct
65 Correct 18 ms 33216 KB Output is correct
66 Correct 17 ms 33212 KB Output is correct
67 Correct 233 ms 71128 KB Output is correct
68 Correct 215 ms 70812 KB Output is correct
69 Correct 213 ms 71028 KB Output is correct
70 Correct 18 ms 33492 KB Output is correct
71 Correct 20 ms 33968 KB Output is correct
72 Correct 109 ms 51608 KB Output is correct
73 Correct 173 ms 61620 KB Output is correct
74 Correct 228 ms 69848 KB Output is correct
75 Correct 259 ms 68760 KB Output is correct
76 Correct 224 ms 70832 KB Output is correct
77 Correct 19 ms 33620 KB Output is correct
78 Correct 22 ms 34004 KB Output is correct
79 Correct 107 ms 51508 KB Output is correct
80 Correct 183 ms 62216 KB Output is correct
81 Correct 230 ms 69456 KB Output is correct
82 Correct 21 ms 33108 KB Output is correct
83 Correct 18 ms 33200 KB Output is correct
84 Correct 18 ms 33148 KB Output is correct
85 Correct 332 ms 91964 KB Output is correct
86 Correct 315 ms 77540 KB Output is correct
87 Correct 329 ms 77464 KB Output is correct
88 Correct 263 ms 73148 KB Output is correct
89 Correct 115 ms 45936 KB Output is correct
90 Correct 188 ms 47948 KB Output is correct
91 Correct 125 ms 48156 KB Output is correct
92 Correct 216 ms 68308 KB Output is correct
93 Correct 239 ms 68292 KB Output is correct
94 Correct 291 ms 69476 KB Output is correct
95 Correct 254 ms 69492 KB Output is correct
96 Correct 17 ms 33108 KB Output is correct
97 Incorrect 25 ms 34816 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -