Submission #894824

# Submission time Handle Problem Language Result Execution time Memory
894824 2023-12-29T04:50:43 Z Sir_Ahmed_Imran Fountain Parks (IOI21_parks) C++17
15 / 100
456 ms 56072 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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 344 KB Output is correct
9 Correct 154 ms 28612 KB Output is correct
10 Correct 11 ms 3552 KB Output is correct
11 Correct 60 ms 15636 KB Output is correct
12 Correct 15 ms 4776 KB Output is correct
13 Correct 38 ms 11292 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 145 ms 28220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 344 KB Output is correct
9 Correct 154 ms 28612 KB Output is correct
10 Correct 11 ms 3552 KB Output is correct
11 Correct 60 ms 15636 KB Output is correct
12 Correct 15 ms 4776 KB Output is correct
13 Correct 38 ms 11292 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 145 ms 28220 KB Output is correct
17 Correct 0 ms 344 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 352 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 344 ms 48772 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 111 ms 19644 KB Output is correct
29 Correct 177 ms 29648 KB Output is correct
30 Correct 257 ms 40640 KB Output is correct
31 Correct 340 ms 48968 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 344 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 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 139 ms 26904 KB Output is correct
46 Correct 220 ms 39080 KB Output is correct
47 Correct 282 ms 39428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 344 KB Output is correct
9 Correct 154 ms 28612 KB Output is correct
10 Correct 11 ms 3552 KB Output is correct
11 Correct 60 ms 15636 KB Output is correct
12 Correct 15 ms 4776 KB Output is correct
13 Correct 38 ms 11292 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 145 ms 28220 KB Output is correct
17 Correct 0 ms 344 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 352 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 344 ms 48772 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 111 ms 19644 KB Output is correct
29 Correct 177 ms 29648 KB Output is correct
30 Correct 257 ms 40640 KB Output is correct
31 Correct 340 ms 48968 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 344 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 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 139 ms 26904 KB Output is correct
46 Correct 220 ms 39080 KB Output is correct
47 Correct 282 ms 39428 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Incorrect 0 ms 348 KB Solution announced impossible, but it is possible.
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 344 KB Output is correct
9 Correct 154 ms 28612 KB Output is correct
10 Correct 11 ms 3552 KB Output is correct
11 Correct 60 ms 15636 KB Output is correct
12 Correct 15 ms 4776 KB Output is correct
13 Correct 38 ms 11292 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 145 ms 28220 KB Output is correct
17 Correct 1 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 320 ms 50680 KB Output is correct
21 Correct 336 ms 56072 KB Output is correct
22 Correct 340 ms 50088 KB Output is correct
23 Correct 311 ms 47476 KB Output is correct
24 Correct 365 ms 44204 KB Output is correct
25 Correct 456 ms 48236 KB Output is correct
26 Correct 439 ms 48788 KB Output is correct
27 Incorrect 147 ms 20116 KB Solution announced impossible, but it is possible.
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 344 KB Output is correct
9 Correct 154 ms 28612 KB Output is correct
10 Correct 11 ms 3552 KB Output is correct
11 Correct 60 ms 15636 KB Output is correct
12 Correct 15 ms 4776 KB Output is correct
13 Correct 38 ms 11292 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 145 ms 28220 KB Output is correct
17 Correct 369 ms 55896 KB Output is correct
18 Incorrect 274 ms 37888 KB Solution announced impossible, but it is possible.
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 344 KB Output is correct
9 Correct 154 ms 28612 KB Output is correct
10 Correct 11 ms 3552 KB Output is correct
11 Correct 60 ms 15636 KB Output is correct
12 Correct 15 ms 4776 KB Output is correct
13 Correct 38 ms 11292 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 145 ms 28220 KB Output is correct
17 Correct 0 ms 344 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 352 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 344 ms 48772 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 111 ms 19644 KB Output is correct
29 Correct 177 ms 29648 KB Output is correct
30 Correct 257 ms 40640 KB Output is correct
31 Correct 340 ms 48968 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 344 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 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 139 ms 26904 KB Output is correct
46 Correct 220 ms 39080 KB Output is correct
47 Correct 282 ms 39428 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Incorrect 0 ms 348 KB Solution announced impossible, but it is possible.
52 Halted 0 ms 0 KB -