Submission #894820

# Submission time Handle Problem Language Result Execution time Memory
894820 2023-12-29T04:32:59 Z Sir_Ahmed_Imran Fountain Parks (IOI21_parks) C++17
30 / 100
492 ms 56648 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-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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 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 348 KB Output is correct
9 Correct 147 ms 28580 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 63 ms 15652 KB Output is correct
12 Correct 15 ms 4776 KB Output is correct
13 Correct 38 ms 11224 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 151 ms 28000 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 0 ms 344 KB Output is correct
4 Correct 0 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 348 KB Output is correct
9 Correct 147 ms 28580 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 63 ms 15652 KB Output is correct
12 Correct 15 ms 4776 KB Output is correct
13 Correct 38 ms 11224 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 151 ms 28000 KB Output is correct
17 Correct 0 ms 600 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 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 359 ms 48868 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 856 KB Output is correct
27 Correct 4 ms 1112 KB Output is correct
28 Correct 103 ms 19716 KB Output is correct
29 Correct 170 ms 29648 KB Output is correct
30 Correct 266 ms 40192 KB Output is correct
31 Correct 324 ms 49036 KB Output is correct
32 Correct 0 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 1 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 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 3 ms 860 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 142 ms 26916 KB Output is correct
46 Correct 251 ms 39680 KB Output is correct
47 Correct 228 ms 40000 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 0 ms 344 KB Output is correct
4 Correct 0 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 348 KB Output is correct
9 Correct 147 ms 28580 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 63 ms 15652 KB Output is correct
12 Correct 15 ms 4776 KB Output is correct
13 Correct 38 ms 11224 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 151 ms 28000 KB Output is correct
17 Correct 0 ms 600 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 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 359 ms 48868 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 856 KB Output is correct
27 Correct 4 ms 1112 KB Output is correct
28 Correct 103 ms 19716 KB Output is correct
29 Correct 170 ms 29648 KB Output is correct
30 Correct 266 ms 40192 KB Output is correct
31 Correct 324 ms 49036 KB Output is correct
32 Correct 0 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 1 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 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 3 ms 860 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 142 ms 26916 KB Output is correct
46 Correct 251 ms 39680 KB Output is correct
47 Correct 228 ms 40000 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 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 348 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 354 ms 46748 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 2 ms 860 KB Output is correct
58 Correct 6 ms 1884 KB Output is correct
59 Correct 9 ms 2396 KB Output is correct
60 Correct 152 ms 23696 KB Output is correct
61 Correct 200 ms 33940 KB Output is correct
62 Correct 254 ms 39432 KB Output is correct
63 Correct 359 ms 47164 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 371 ms 55372 KB Output is correct
68 Correct 385 ms 56648 KB Output is correct
69 Correct 369 ms 56160 KB Output is correct
70 Correct 3 ms 1112 KB Output is correct
71 Correct 7 ms 2136 KB Output is correct
72 Correct 185 ms 26548 KB Output is correct
73 Correct 246 ms 40720 KB Output is correct
74 Correct 396 ms 53256 KB Output is correct
75 Correct 356 ms 51176 KB Output is correct
76 Correct 375 ms 55852 KB Output is correct
77 Correct 4 ms 1368 KB Output is correct
78 Correct 8 ms 2396 KB Output is correct
79 Correct 145 ms 25744 KB Output is correct
80 Correct 245 ms 38788 KB Output is correct
81 Correct 350 ms 52392 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 0 ms 344 KB Output is correct
4 Correct 0 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 348 KB Output is correct
9 Correct 147 ms 28580 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 63 ms 15652 KB Output is correct
12 Correct 15 ms 4776 KB Output is correct
13 Correct 38 ms 11224 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 151 ms 28000 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 322 ms 50728 KB Output is correct
21 Correct 340 ms 56336 KB Output is correct
22 Correct 323 ms 50096 KB Output is correct
23 Correct 297 ms 47564 KB Output is correct
24 Correct 376 ms 44264 KB Output is correct
25 Correct 394 ms 48372 KB Output is correct
26 Correct 441 ms 49240 KB Output is correct
27 Correct 492 ms 54884 KB Output is correct
28 Correct 481 ms 55216 KB Output is correct
29 Correct 431 ms 55188 KB Output is correct
30 Correct 427 ms 55040 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 8 ms 1884 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 0 ms 344 KB Output is correct
4 Correct 0 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 348 KB Output is correct
9 Correct 147 ms 28580 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 63 ms 15652 KB Output is correct
12 Correct 15 ms 4776 KB Output is correct
13 Correct 38 ms 11224 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 151 ms 28000 KB Output is correct
17 Correct 362 ms 56048 KB Output is correct
18 Correct 380 ms 56192 KB Output is correct
19 Incorrect 221 ms 32512 KB Solution announced impossible, but it is possible.
20 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 0 ms 344 KB Output is correct
4 Correct 0 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 348 KB Output is correct
9 Correct 147 ms 28580 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 63 ms 15652 KB Output is correct
12 Correct 15 ms 4776 KB Output is correct
13 Correct 38 ms 11224 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 151 ms 28000 KB Output is correct
17 Correct 0 ms 600 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 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 359 ms 48868 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 856 KB Output is correct
27 Correct 4 ms 1112 KB Output is correct
28 Correct 103 ms 19716 KB Output is correct
29 Correct 170 ms 29648 KB Output is correct
30 Correct 266 ms 40192 KB Output is correct
31 Correct 324 ms 49036 KB Output is correct
32 Correct 0 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 1 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 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 3 ms 860 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 142 ms 26916 KB Output is correct
46 Correct 251 ms 39680 KB Output is correct
47 Correct 228 ms 40000 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 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 348 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 354 ms 46748 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 2 ms 860 KB Output is correct
58 Correct 6 ms 1884 KB Output is correct
59 Correct 9 ms 2396 KB Output is correct
60 Correct 152 ms 23696 KB Output is correct
61 Correct 200 ms 33940 KB Output is correct
62 Correct 254 ms 39432 KB Output is correct
63 Correct 359 ms 47164 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 371 ms 55372 KB Output is correct
68 Correct 385 ms 56648 KB Output is correct
69 Correct 369 ms 56160 KB Output is correct
70 Correct 3 ms 1112 KB Output is correct
71 Correct 7 ms 2136 KB Output is correct
72 Correct 185 ms 26548 KB Output is correct
73 Correct 246 ms 40720 KB Output is correct
74 Correct 396 ms 53256 KB Output is correct
75 Correct 356 ms 51176 KB Output is correct
76 Correct 375 ms 55852 KB Output is correct
77 Correct 4 ms 1368 KB Output is correct
78 Correct 8 ms 2396 KB Output is correct
79 Correct 145 ms 25744 KB Output is correct
80 Correct 245 ms 38788 KB Output is correct
81 Correct 350 ms 52392 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 1 ms 348 KB Output is correct
84 Correct 1 ms 344 KB Output is correct
85 Correct 322 ms 50728 KB Output is correct
86 Correct 340 ms 56336 KB Output is correct
87 Correct 323 ms 50096 KB Output is correct
88 Correct 297 ms 47564 KB Output is correct
89 Correct 376 ms 44264 KB Output is correct
90 Correct 394 ms 48372 KB Output is correct
91 Correct 441 ms 49240 KB Output is correct
92 Correct 492 ms 54884 KB Output is correct
93 Correct 481 ms 55216 KB Output is correct
94 Correct 431 ms 55188 KB Output is correct
95 Correct 427 ms 55040 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Incorrect 8 ms 1884 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -