Submission #499910

# Submission time Handle Problem Language Result Execution time Memory
499910 2021-12-30T00:18:36 Z ETK Fountain Parks (IOI21_parks) C++17
100 / 100
170 ms 19904 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define sz(A) int(A.size())
#define pii pair<int,int>
const int N = 2e5+5;
vi U,V,A,B;
int p[N],fa[N],lst[N];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void add(int u,int v,int a,int b){
    fa[find(u)]=find(v);
    U.push_back(u-1),V.push_back(v-1);
    A.push_back(a),B.push_back(b);
    if(a>lst[b])lst[b] = a;
}
struct node{int x,y;}v[N];
bool cmp(int x,int y){return v[x].x==v[y].x?v[x].y<v[y].y:v[x].x<v[y].x;}
int construct_roads(vi x,vi y){
    int n = sz(x);
    for(int i=1;i<=n;i++)fa[i]=p[i]=i,v[i]={x[i-1],y[i-1]};
    sort(p+1,p+n+1,cmp);
    for(int i=1;i<=n;i++){
        int id = p[i];
        auto [x,y] = v[id];
        bool odd = (x^y)&2;
        if(i>1 && v[p[i-1]].x==x && v[p[i-1]].y==y-2){//vertical
            int k = p[i-1];
            if(find(k)!=find(id)){
                if(odd){
                    if(lst[y-1]==x-1)add(lst[y],id,x-1,y+1);
                    else add(k,id,x-1,y-1);
                }else add(k,id,x+1,y-1);
            }
        }
        if(lst[y] && v[lst[y]].x == x-2){//horizontal
            int k = lst[y];
            if(find(k)!=find(id)){
                if(odd)add(k,id,x-1,y+1);
                else{
                    if(lst[y-1]==x-1){}
                    else add(k,id,x-1,y-1);
                }
            }
        }
        lst[y] = id;
    }
    int c=0;
    for(int i=1;i<=n;i++)c+=(fa[i]==i);
    if(c>1)return 0;
    build(U,V,A,B);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 63 ms 9008 KB Output is correct
10 Correct 6 ms 1412 KB Output is correct
11 Correct 28 ms 5088 KB Output is correct
12 Correct 8 ms 1860 KB Output is correct
13 Correct 12 ms 2844 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 63 ms 9148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 63 ms 9008 KB Output is correct
10 Correct 6 ms 1412 KB Output is correct
11 Correct 28 ms 5088 KB Output is correct
12 Correct 8 ms 1860 KB Output is correct
13 Correct 12 ms 2844 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 63 ms 9148 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 308 KB Output is correct
23 Correct 147 ms 18160 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 432 KB Output is correct
26 Correct 1 ms 456 KB Output is correct
27 Correct 2 ms 448 KB Output is correct
28 Correct 49 ms 7564 KB Output is correct
29 Correct 79 ms 11088 KB Output is correct
30 Correct 109 ms 14640 KB Output is correct
31 Correct 132 ms 18124 KB Output is correct
32 Correct 0 ms 304 KB Output is correct
33 Correct 0 ms 296 KB Output is correct
34 Correct 1 ms 308 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 67 ms 8880 KB Output is correct
46 Correct 94 ms 13724 KB Output is correct
47 Correct 93 ms 13788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 63 ms 9008 KB Output is correct
10 Correct 6 ms 1412 KB Output is correct
11 Correct 28 ms 5088 KB Output is correct
12 Correct 8 ms 1860 KB Output is correct
13 Correct 12 ms 2844 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 63 ms 9148 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 308 KB Output is correct
23 Correct 147 ms 18160 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 432 KB Output is correct
26 Correct 1 ms 456 KB Output is correct
27 Correct 2 ms 448 KB Output is correct
28 Correct 49 ms 7564 KB Output is correct
29 Correct 79 ms 11088 KB Output is correct
30 Correct 109 ms 14640 KB Output is correct
31 Correct 132 ms 18124 KB Output is correct
32 Correct 0 ms 304 KB Output is correct
33 Correct 0 ms 296 KB Output is correct
34 Correct 1 ms 308 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 67 ms 8880 KB Output is correct
46 Correct 94 ms 13724 KB Output is correct
47 Correct 93 ms 13788 KB Output is correct
48 Correct 1 ms 248 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 0 ms 204 KB Output is correct
55 Correct 133 ms 18956 KB Output is correct
56 Correct 0 ms 308 KB Output is correct
57 Correct 2 ms 444 KB Output is correct
58 Correct 4 ms 952 KB Output is correct
59 Correct 5 ms 972 KB Output is correct
60 Correct 66 ms 9628 KB Output is correct
61 Correct 87 ms 12696 KB Output is correct
62 Correct 114 ms 15872 KB Output is correct
63 Correct 170 ms 17980 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 0 ms 204 KB Output is correct
67 Correct 136 ms 18540 KB Output is correct
68 Correct 152 ms 19460 KB Output is correct
69 Correct 149 ms 18956 KB Output is correct
70 Correct 2 ms 568 KB Output is correct
71 Correct 3 ms 828 KB Output is correct
72 Correct 63 ms 9436 KB Output is correct
73 Correct 107 ms 13956 KB Output is correct
74 Correct 139 ms 18456 KB Output is correct
75 Correct 138 ms 19216 KB Output is correct
76 Correct 140 ms 19724 KB Output is correct
77 Correct 2 ms 620 KB Output is correct
78 Correct 5 ms 940 KB Output is correct
79 Correct 72 ms 9372 KB Output is correct
80 Correct 98 ms 13928 KB Output is correct
81 Correct 144 ms 18444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 63 ms 9008 KB Output is correct
10 Correct 6 ms 1412 KB Output is correct
11 Correct 28 ms 5088 KB Output is correct
12 Correct 8 ms 1860 KB Output is correct
13 Correct 12 ms 2844 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 63 ms 9148 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 304 KB Output is correct
20 Correct 153 ms 19888 KB Output is correct
21 Correct 154 ms 19052 KB Output is correct
22 Correct 169 ms 19004 KB Output is correct
23 Correct 112 ms 15884 KB Output is correct
24 Correct 69 ms 8248 KB Output is correct
25 Correct 82 ms 11424 KB Output is correct
26 Correct 69 ms 11412 KB Output is correct
27 Correct 133 ms 17724 KB Output is correct
28 Correct 134 ms 17672 KB Output is correct
29 Correct 149 ms 17672 KB Output is correct
30 Correct 137 ms 17672 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 9 ms 1928 KB Output is correct
33 Correct 34 ms 5412 KB Output is correct
34 Correct 144 ms 19880 KB Output is correct
35 Correct 4 ms 996 KB Output is correct
36 Correct 25 ms 3368 KB Output is correct
37 Correct 41 ms 6412 KB Output is correct
38 Correct 57 ms 8008 KB Output is correct
39 Correct 77 ms 10620 KB Output is correct
40 Correct 111 ms 13408 KB Output is correct
41 Correct 118 ms 16304 KB Output is correct
42 Correct 147 ms 19128 KB Output is correct
43 Correct 1 ms 304 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 304 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 1 ms 296 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 1 ms 460 KB Output is correct
55 Correct 1 ms 572 KB Output is correct
56 Correct 63 ms 9616 KB Output is correct
57 Correct 99 ms 13704 KB Output is correct
58 Correct 97 ms 13680 KB Output is correct
59 Correct 0 ms 296 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 0 ms 204 KB Output is correct
62 Correct 131 ms 18544 KB Output is correct
63 Correct 127 ms 19612 KB Output is correct
64 Correct 143 ms 19100 KB Output is correct
65 Correct 2 ms 568 KB Output is correct
66 Correct 3 ms 820 KB Output is correct
67 Correct 70 ms 9356 KB Output is correct
68 Correct 106 ms 13980 KB Output is correct
69 Correct 133 ms 18456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 63 ms 9008 KB Output is correct
10 Correct 6 ms 1412 KB Output is correct
11 Correct 28 ms 5088 KB Output is correct
12 Correct 8 ms 1860 KB Output is correct
13 Correct 12 ms 2844 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 63 ms 9148 KB Output is correct
17 Correct 138 ms 17192 KB Output is correct
18 Correct 134 ms 17088 KB Output is correct
19 Correct 131 ms 16980 KB Output is correct
20 Correct 130 ms 17292 KB Output is correct
21 Correct 137 ms 15652 KB Output is correct
22 Correct 1 ms 288 KB Output is correct
23 Correct 21 ms 3832 KB Output is correct
24 Correct 7 ms 1740 KB Output is correct
25 Correct 28 ms 4796 KB Output is correct
26 Correct 51 ms 7596 KB Output is correct
27 Correct 67 ms 9592 KB Output is correct
28 Correct 86 ms 12324 KB Output is correct
29 Correct 108 ms 14828 KB Output is correct
30 Correct 119 ms 16344 KB Output is correct
31 Correct 138 ms 19120 KB Output is correct
32 Correct 136 ms 19276 KB Output is correct
33 Correct 130 ms 19612 KB Output is correct
34 Correct 2 ms 616 KB Output is correct
35 Correct 3 ms 952 KB Output is correct
36 Correct 62 ms 9368 KB Output is correct
37 Correct 95 ms 13948 KB Output is correct
38 Correct 132 ms 18440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 63 ms 9008 KB Output is correct
10 Correct 6 ms 1412 KB Output is correct
11 Correct 28 ms 5088 KB Output is correct
12 Correct 8 ms 1860 KB Output is correct
13 Correct 12 ms 2844 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 63 ms 9148 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 308 KB Output is correct
23 Correct 147 ms 18160 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 432 KB Output is correct
26 Correct 1 ms 456 KB Output is correct
27 Correct 2 ms 448 KB Output is correct
28 Correct 49 ms 7564 KB Output is correct
29 Correct 79 ms 11088 KB Output is correct
30 Correct 109 ms 14640 KB Output is correct
31 Correct 132 ms 18124 KB Output is correct
32 Correct 0 ms 304 KB Output is correct
33 Correct 0 ms 296 KB Output is correct
34 Correct 1 ms 308 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 67 ms 8880 KB Output is correct
46 Correct 94 ms 13724 KB Output is correct
47 Correct 93 ms 13788 KB Output is correct
48 Correct 1 ms 248 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 0 ms 204 KB Output is correct
55 Correct 133 ms 18956 KB Output is correct
56 Correct 0 ms 308 KB Output is correct
57 Correct 2 ms 444 KB Output is correct
58 Correct 4 ms 952 KB Output is correct
59 Correct 5 ms 972 KB Output is correct
60 Correct 66 ms 9628 KB Output is correct
61 Correct 87 ms 12696 KB Output is correct
62 Correct 114 ms 15872 KB Output is correct
63 Correct 170 ms 17980 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 0 ms 204 KB Output is correct
67 Correct 136 ms 18540 KB Output is correct
68 Correct 152 ms 19460 KB Output is correct
69 Correct 149 ms 18956 KB Output is correct
70 Correct 2 ms 568 KB Output is correct
71 Correct 3 ms 828 KB Output is correct
72 Correct 63 ms 9436 KB Output is correct
73 Correct 107 ms 13956 KB Output is correct
74 Correct 139 ms 18456 KB Output is correct
75 Correct 138 ms 19216 KB Output is correct
76 Correct 140 ms 19724 KB Output is correct
77 Correct 2 ms 620 KB Output is correct
78 Correct 5 ms 940 KB Output is correct
79 Correct 72 ms 9372 KB Output is correct
80 Correct 98 ms 13928 KB Output is correct
81 Correct 144 ms 18444 KB Output is correct
82 Correct 0 ms 204 KB Output is correct
83 Correct 0 ms 204 KB Output is correct
84 Correct 0 ms 304 KB Output is correct
85 Correct 153 ms 19888 KB Output is correct
86 Correct 154 ms 19052 KB Output is correct
87 Correct 169 ms 19004 KB Output is correct
88 Correct 112 ms 15884 KB Output is correct
89 Correct 69 ms 8248 KB Output is correct
90 Correct 82 ms 11424 KB Output is correct
91 Correct 69 ms 11412 KB Output is correct
92 Correct 133 ms 17724 KB Output is correct
93 Correct 134 ms 17672 KB Output is correct
94 Correct 149 ms 17672 KB Output is correct
95 Correct 137 ms 17672 KB Output is correct
96 Correct 0 ms 204 KB Output is correct
97 Correct 9 ms 1928 KB Output is correct
98 Correct 34 ms 5412 KB Output is correct
99 Correct 144 ms 19880 KB Output is correct
100 Correct 4 ms 996 KB Output is correct
101 Correct 25 ms 3368 KB Output is correct
102 Correct 41 ms 6412 KB Output is correct
103 Correct 57 ms 8008 KB Output is correct
104 Correct 77 ms 10620 KB Output is correct
105 Correct 111 ms 13408 KB Output is correct
106 Correct 118 ms 16304 KB Output is correct
107 Correct 147 ms 19128 KB Output is correct
108 Correct 1 ms 304 KB Output is correct
109 Correct 0 ms 204 KB Output is correct
110 Correct 0 ms 204 KB Output is correct
111 Correct 0 ms 304 KB Output is correct
112 Correct 0 ms 204 KB Output is correct
113 Correct 1 ms 204 KB Output is correct
114 Correct 0 ms 204 KB Output is correct
115 Correct 0 ms 204 KB Output is correct
116 Correct 1 ms 296 KB Output is correct
117 Correct 0 ms 204 KB Output is correct
118 Correct 1 ms 204 KB Output is correct
119 Correct 1 ms 460 KB Output is correct
120 Correct 1 ms 572 KB Output is correct
121 Correct 63 ms 9616 KB Output is correct
122 Correct 99 ms 13704 KB Output is correct
123 Correct 97 ms 13680 KB Output is correct
124 Correct 0 ms 296 KB Output is correct
125 Correct 0 ms 204 KB Output is correct
126 Correct 0 ms 204 KB Output is correct
127 Correct 131 ms 18544 KB Output is correct
128 Correct 127 ms 19612 KB Output is correct
129 Correct 143 ms 19100 KB Output is correct
130 Correct 2 ms 568 KB Output is correct
131 Correct 3 ms 820 KB Output is correct
132 Correct 70 ms 9356 KB Output is correct
133 Correct 106 ms 13980 KB Output is correct
134 Correct 133 ms 18456 KB Output is correct
135 Correct 138 ms 17192 KB Output is correct
136 Correct 134 ms 17088 KB Output is correct
137 Correct 131 ms 16980 KB Output is correct
138 Correct 130 ms 17292 KB Output is correct
139 Correct 137 ms 15652 KB Output is correct
140 Correct 1 ms 288 KB Output is correct
141 Correct 21 ms 3832 KB Output is correct
142 Correct 7 ms 1740 KB Output is correct
143 Correct 28 ms 4796 KB Output is correct
144 Correct 51 ms 7596 KB Output is correct
145 Correct 67 ms 9592 KB Output is correct
146 Correct 86 ms 12324 KB Output is correct
147 Correct 108 ms 14828 KB Output is correct
148 Correct 119 ms 16344 KB Output is correct
149 Correct 138 ms 19120 KB Output is correct
150 Correct 136 ms 19276 KB Output is correct
151 Correct 130 ms 19612 KB Output is correct
152 Correct 2 ms 616 KB Output is correct
153 Correct 3 ms 952 KB Output is correct
154 Correct 62 ms 9368 KB Output is correct
155 Correct 95 ms 13948 KB Output is correct
156 Correct 132 ms 18440 KB Output is correct
157 Correct 0 ms 300 KB Output is correct
158 Correct 0 ms 300 KB Output is correct
159 Correct 0 ms 204 KB Output is correct
160 Correct 1 ms 204 KB Output is correct
161 Correct 141 ms 18068 KB Output is correct
162 Correct 140 ms 19904 KB Output is correct
163 Correct 141 ms 19388 KB Output is correct
164 Correct 138 ms 19376 KB Output is correct
165 Correct 142 ms 18908 KB Output is correct
166 Correct 138 ms 18208 KB Output is correct
167 Correct 31 ms 4664 KB Output is correct
168 Correct 11 ms 2372 KB Output is correct
169 Correct 32 ms 5252 KB Output is correct
170 Correct 62 ms 9520 KB Output is correct
171 Correct 82 ms 12428 KB Output is correct
172 Correct 68 ms 9596 KB Output is correct
173 Correct 82 ms 11676 KB Output is correct
174 Correct 101 ms 13400 KB Output is correct
175 Correct 110 ms 15064 KB Output is correct
176 Correct 128 ms 17272 KB Output is correct
177 Correct 140 ms 19132 KB Output is correct