Submission #894827

# Submission time Handle Problem Language Result Execution time Memory
894827 2023-12-29T04:56:51 Z Sir_Ahmed_Imran Fountain Parks (IOI21_parks) C++17
30 / 100
490 ms 56328 KB
                              ///~~~LOTA~~~///
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long 
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define N 200001
int siz[N];
int par[N];
int root(int v){
    if(!par[v]) return v;
    par[v]=root(par[v]);
    return par[v];
}
void merge(int v,int u){
    v=root(v);
    u=root(u);
    par[u]=v;
    siz[v]+=siz[u];
}
bool same(int v,int u){
    return (root(v)==root(u));
}
int construct_roads(vector<int> x,vector<int> y){
    map<pii,int> c,z;
    int n,m,o,p,q,r;
    n=x.size();
    vector<int> v,u,a,b;
    vector<pair<pii,int>> w;
    for(int i=0;i<n;i++){
        w.append({{y[i],x[i]},i+1});
        z[{x[i],y[i]}]=i+1;
        siz[i+1]=1;
    }
    sort(all(w));
    for(auto& i:w){
        q=i.ff.ff;
        p=i.ff.ss;
        r=z[{p,q-2}];
        if(r){
            if(!same(i.ss,r)){
                merge(i.ss,r);
                v.append(i.ss-1);
                u.append(r-1);
                if(!c[{p-1,q-1}]){
                    a.append(p-1);
                    b.append(q-1);
                    c[{p-1,q-1}]=1;
                }
                else if(!c[{p+1,q-1}]){
                    a.append(p+1);
                    b.append(q-1);
                    c[{p+1,q-1}]=1;
                }
                else return 0;
            }
        }
        r=z[{p-2,q}];
        if(r){
            if(!same(i.ss,r)){
                merge(i.ss,r);
                v.append(i.ss-1);
                u.append(r-1);
                if(!c[{p-1,q-1}]){
                    a.append(p-1);
                    b.append(q-1);
                    c[{p-1,q-1}]=1;
                }
                else if(!c[{p-1,q+1}]){
                    a.append(p-1);
                    b.append(q+1);
                    c[{p-1,q+1}]=1;
                }
                else return 0;
            }
        }
    }
    if(siz[root(1)]!=n) return 0;
    build(u,v,a,b);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:31:11: warning: unused variable 'm' [-Wunused-variable]
   31 |     int n,m,o,p,q,r;
      |           ^
parks.cpp:31:13: warning: unused variable 'o' [-Wunused-variable]
   31 |     int n,m,o,p,q,r;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 145 ms 28640 KB Output is correct
10 Correct 12 ms 3296 KB Output is correct
11 Correct 72 ms 15684 KB Output is correct
12 Correct 16 ms 4780 KB Output is correct
13 Correct 39 ms 11276 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 149 ms 28220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 145 ms 28640 KB Output is correct
10 Correct 12 ms 3296 KB Output is correct
11 Correct 72 ms 15684 KB Output is correct
12 Correct 16 ms 4780 KB Output is correct
13 Correct 39 ms 11276 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 149 ms 28220 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 345 ms 48884 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 756 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 107 ms 19852 KB Output is correct
29 Correct 169 ms 30260 KB Output is correct
30 Correct 244 ms 41220 KB Output is correct
31 Correct 334 ms 49076 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 142 ms 26800 KB Output is correct
46 Correct 243 ms 39172 KB Output is correct
47 Correct 232 ms 39936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 145 ms 28640 KB Output is correct
10 Correct 12 ms 3296 KB Output is correct
11 Correct 72 ms 15684 KB Output is correct
12 Correct 16 ms 4780 KB Output is correct
13 Correct 39 ms 11276 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 149 ms 28220 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 345 ms 48884 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 756 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 107 ms 19852 KB Output is correct
29 Correct 169 ms 30260 KB Output is correct
30 Correct 244 ms 41220 KB Output is correct
31 Correct 334 ms 49076 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 142 ms 26800 KB Output is correct
46 Correct 243 ms 39172 KB Output is correct
47 Correct 232 ms 39936 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 327 ms 46772 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 3 ms 860 KB Output is correct
58 Correct 6 ms 1884 KB Output is correct
59 Correct 9 ms 2392 KB Output is correct
60 Correct 139 ms 23956 KB Output is correct
61 Correct 214 ms 33592 KB Output is correct
62 Correct 252 ms 39000 KB Output is correct
63 Correct 385 ms 47536 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 382 ms 55520 KB Output is correct
68 Correct 386 ms 56328 KB Output is correct
69 Correct 417 ms 56076 KB Output is correct
70 Correct 4 ms 1116 KB Output is correct
71 Correct 9 ms 2140 KB Output is correct
72 Correct 147 ms 26688 KB Output is correct
73 Correct 256 ms 40400 KB Output is correct
74 Correct 363 ms 53248 KB Output is correct
75 Correct 354 ms 52224 KB Output is correct
76 Correct 379 ms 55824 KB Output is correct
77 Correct 4 ms 1368 KB Output is correct
78 Correct 8 ms 2396 KB Output is correct
79 Correct 148 ms 25824 KB Output is correct
80 Correct 245 ms 38784 KB Output is correct
81 Correct 362 ms 52768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 145 ms 28640 KB Output is correct
10 Correct 12 ms 3296 KB Output is correct
11 Correct 72 ms 15684 KB Output is correct
12 Correct 16 ms 4780 KB Output is correct
13 Correct 39 ms 11276 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 149 ms 28220 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 333 ms 50604 KB Output is correct
21 Correct 332 ms 56236 KB Output is correct
22 Correct 342 ms 50208 KB Output is correct
23 Correct 304 ms 48152 KB Output is correct
24 Correct 352 ms 44176 KB Output is correct
25 Correct 416 ms 48384 KB Output is correct
26 Correct 451 ms 49156 KB Output is correct
27 Correct 469 ms 54960 KB Output is correct
28 Correct 490 ms 54944 KB Output is correct
29 Correct 440 ms 55016 KB Output is correct
30 Correct 418 ms 54840 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 9 ms 1624 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 145 ms 28640 KB Output is correct
10 Correct 12 ms 3296 KB Output is correct
11 Correct 72 ms 15684 KB Output is correct
12 Correct 16 ms 4780 KB Output is correct
13 Correct 39 ms 11276 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 149 ms 28220 KB Output is correct
17 Correct 361 ms 55908 KB Output is correct
18 Correct 413 ms 55984 KB Output is correct
19 Correct 347 ms 52516 KB Output is correct
20 Correct 399 ms 45564 KB Output is correct
21 Correct 389 ms 45964 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Incorrect 17 ms 3480 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 145 ms 28640 KB Output is correct
10 Correct 12 ms 3296 KB Output is correct
11 Correct 72 ms 15684 KB Output is correct
12 Correct 16 ms 4780 KB Output is correct
13 Correct 39 ms 11276 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 149 ms 28220 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 345 ms 48884 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 756 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 107 ms 19852 KB Output is correct
29 Correct 169 ms 30260 KB Output is correct
30 Correct 244 ms 41220 KB Output is correct
31 Correct 334 ms 49076 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 142 ms 26800 KB Output is correct
46 Correct 243 ms 39172 KB Output is correct
47 Correct 232 ms 39936 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 327 ms 46772 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 3 ms 860 KB Output is correct
58 Correct 6 ms 1884 KB Output is correct
59 Correct 9 ms 2392 KB Output is correct
60 Correct 139 ms 23956 KB Output is correct
61 Correct 214 ms 33592 KB Output is correct
62 Correct 252 ms 39000 KB Output is correct
63 Correct 385 ms 47536 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 382 ms 55520 KB Output is correct
68 Correct 386 ms 56328 KB Output is correct
69 Correct 417 ms 56076 KB Output is correct
70 Correct 4 ms 1116 KB Output is correct
71 Correct 9 ms 2140 KB Output is correct
72 Correct 147 ms 26688 KB Output is correct
73 Correct 256 ms 40400 KB Output is correct
74 Correct 363 ms 53248 KB Output is correct
75 Correct 354 ms 52224 KB Output is correct
76 Correct 379 ms 55824 KB Output is correct
77 Correct 4 ms 1368 KB Output is correct
78 Correct 8 ms 2396 KB Output is correct
79 Correct 148 ms 25824 KB Output is correct
80 Correct 245 ms 38784 KB Output is correct
81 Correct 362 ms 52768 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 333 ms 50604 KB Output is correct
86 Correct 332 ms 56236 KB Output is correct
87 Correct 342 ms 50208 KB Output is correct
88 Correct 304 ms 48152 KB Output is correct
89 Correct 352 ms 44176 KB Output is correct
90 Correct 416 ms 48384 KB Output is correct
91 Correct 451 ms 49156 KB Output is correct
92 Correct 469 ms 54960 KB Output is correct
93 Correct 490 ms 54944 KB Output is correct
94 Correct 440 ms 55016 KB Output is correct
95 Correct 418 ms 54840 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Incorrect 9 ms 1624 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -