Submission #894818

# Submission time Handle Problem Language Result Execution time Memory
894818 2023-12-29T04:26:40 Z Sir_Ahmed_Imran Fountain Parks (IOI21_parks) C++17
30 / 100
364 ms 56524 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({{x[i],y[i]},i+1});
        z[{x[i],y[i]}]=i+1;
        siz[i+1]=1;
    }
    sort(all(w));
    for(auto& i:w){
        p=i.ff.ff;
        q=i.ff.ss;
        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;
            }
        }
        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;
            }
        }
    }
    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 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 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 344 KB Output is correct
9 Correct 156 ms 28672 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 63 ms 15620 KB Output is correct
12 Correct 16 ms 4776 KB Output is correct
13 Correct 39 ms 11272 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 145 ms 28100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 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 344 KB Output is correct
9 Correct 156 ms 28672 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 63 ms 15620 KB Output is correct
12 Correct 16 ms 4776 KB Output is correct
13 Correct 39 ms 11272 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 145 ms 28100 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 344 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 1 ms 348 KB Output is correct
23 Correct 339 ms 49940 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 105 ms 20188 KB Output is correct
29 Correct 175 ms 29812 KB Output is correct
30 Correct 244 ms 40548 KB Output is correct
31 Correct 317 ms 49840 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 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 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 3 ms 1112 KB Output is correct
45 Correct 153 ms 26712 KB Output is correct
46 Correct 222 ms 39172 KB Output is correct
47 Correct 230 ms 40108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 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 344 KB Output is correct
9 Correct 156 ms 28672 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 63 ms 15620 KB Output is correct
12 Correct 16 ms 4776 KB Output is correct
13 Correct 39 ms 11272 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 145 ms 28100 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 344 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 1 ms 348 KB Output is correct
23 Correct 339 ms 49940 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 105 ms 20188 KB Output is correct
29 Correct 175 ms 29812 KB Output is correct
30 Correct 244 ms 40548 KB Output is correct
31 Correct 317 ms 49840 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 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 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 3 ms 1112 KB Output is correct
45 Correct 153 ms 26712 KB Output is correct
46 Correct 222 ms 39172 KB Output is correct
47 Correct 230 ms 40108 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 600 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 332 ms 47524 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 2 ms 860 KB Output is correct
58 Correct 6 ms 1880 KB Output is correct
59 Correct 8 ms 2392 KB Output is correct
60 Correct 142 ms 23756 KB Output is correct
61 Correct 190 ms 33024 KB Output is correct
62 Correct 254 ms 39512 KB Output is correct
63 Correct 340 ms 47368 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 337 ms 55664 KB Output is correct
68 Correct 357 ms 56204 KB Output is correct
69 Correct 337 ms 55232 KB Output is correct
70 Correct 5 ms 1116 KB Output is correct
71 Correct 7 ms 2128 KB Output is correct
72 Correct 170 ms 26356 KB Output is correct
73 Correct 241 ms 39832 KB Output is correct
74 Correct 350 ms 52616 KB Output is correct
75 Correct 319 ms 50860 KB Output is correct
76 Correct 339 ms 56236 KB Output is correct
77 Correct 6 ms 1372 KB Output is correct
78 Correct 8 ms 2240 KB Output is correct
79 Correct 152 ms 25540 KB Output is correct
80 Correct 228 ms 38784 KB Output is correct
81 Correct 364 ms 51536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 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 344 KB Output is correct
9 Correct 156 ms 28672 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 63 ms 15620 KB Output is correct
12 Correct 16 ms 4776 KB Output is correct
13 Correct 39 ms 11272 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 145 ms 28100 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 301 ms 49588 KB Output is correct
21 Correct 336 ms 56236 KB Output is correct
22 Correct 311 ms 49576 KB Output is correct
23 Correct 297 ms 47384 KB Output is correct
24 Correct 272 ms 44056 KB Output is correct
25 Correct 311 ms 48388 KB Output is correct
26 Correct 280 ms 48264 KB Output is correct
27 Correct 330 ms 54960 KB Output is correct
28 Correct 323 ms 54992 KB Output is correct
29 Correct 345 ms 55024 KB Output is correct
30 Correct 334 ms 54852 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 7 ms 1756 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 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 344 KB Output is correct
9 Correct 156 ms 28672 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 63 ms 15620 KB Output is correct
12 Correct 16 ms 4776 KB Output is correct
13 Correct 39 ms 11272 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 145 ms 28100 KB Output is correct
17 Correct 333 ms 55856 KB Output is correct
18 Correct 335 ms 56524 KB Output is correct
19 Correct 330 ms 53036 KB Output is correct
20 Correct 292 ms 45532 KB Output is correct
21 Correct 287 ms 45880 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Incorrect 16 ms 3588 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 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 344 KB Output is correct
9 Correct 156 ms 28672 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 63 ms 15620 KB Output is correct
12 Correct 16 ms 4776 KB Output is correct
13 Correct 39 ms 11272 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 145 ms 28100 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 344 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 1 ms 348 KB Output is correct
23 Correct 339 ms 49940 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 105 ms 20188 KB Output is correct
29 Correct 175 ms 29812 KB Output is correct
30 Correct 244 ms 40548 KB Output is correct
31 Correct 317 ms 49840 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 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 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 3 ms 1112 KB Output is correct
45 Correct 153 ms 26712 KB Output is correct
46 Correct 222 ms 39172 KB Output is correct
47 Correct 230 ms 40108 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 600 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 332 ms 47524 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 2 ms 860 KB Output is correct
58 Correct 6 ms 1880 KB Output is correct
59 Correct 8 ms 2392 KB Output is correct
60 Correct 142 ms 23756 KB Output is correct
61 Correct 190 ms 33024 KB Output is correct
62 Correct 254 ms 39512 KB Output is correct
63 Correct 340 ms 47368 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 337 ms 55664 KB Output is correct
68 Correct 357 ms 56204 KB Output is correct
69 Correct 337 ms 55232 KB Output is correct
70 Correct 5 ms 1116 KB Output is correct
71 Correct 7 ms 2128 KB Output is correct
72 Correct 170 ms 26356 KB Output is correct
73 Correct 241 ms 39832 KB Output is correct
74 Correct 350 ms 52616 KB Output is correct
75 Correct 319 ms 50860 KB Output is correct
76 Correct 339 ms 56236 KB Output is correct
77 Correct 6 ms 1372 KB Output is correct
78 Correct 8 ms 2240 KB Output is correct
79 Correct 152 ms 25540 KB Output is correct
80 Correct 228 ms 38784 KB Output is correct
81 Correct 364 ms 51536 KB Output is correct
82 Correct 0 ms 344 KB Output is correct
83 Correct 1 ms 344 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 301 ms 49588 KB Output is correct
86 Correct 336 ms 56236 KB Output is correct
87 Correct 311 ms 49576 KB Output is correct
88 Correct 297 ms 47384 KB Output is correct
89 Correct 272 ms 44056 KB Output is correct
90 Correct 311 ms 48388 KB Output is correct
91 Correct 280 ms 48264 KB Output is correct
92 Correct 330 ms 54960 KB Output is correct
93 Correct 323 ms 54992 KB Output is correct
94 Correct 345 ms 55024 KB Output is correct
95 Correct 334 ms 54852 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Incorrect 7 ms 1756 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -