답안 #894815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894815 2023-12-29T04:20:40 Z Sir_Ahmed_Imran 분수 공원 (IOI21_parks) C++17
30 / 100
380 ms 55300 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();
    for(int i=1;i<=n;i++)
        siz[i]=1;
    vector<int> v,u,a,b;
    for(int i=0;i<n;i++)
        z[{x[i],y[i]}]=i+1;
    for(auto& i:z){
        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;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 151 ms 27360 KB Output is correct
10 Correct 10 ms 3164 KB Output is correct
11 Correct 71 ms 14900 KB Output is correct
12 Correct 15 ms 4696 KB Output is correct
13 Correct 40 ms 10832 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 155 ms 26676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 151 ms 27360 KB Output is correct
10 Correct 10 ms 3164 KB Output is correct
11 Correct 71 ms 14900 KB Output is correct
12 Correct 15 ms 4696 KB Output is correct
13 Correct 40 ms 10832 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 155 ms 26676 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 352 KB Output is correct
22 Correct 0 ms 356 KB Output is correct
23 Correct 312 ms 46940 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 1 ms 612 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 101 ms 19568 KB Output is correct
29 Correct 168 ms 29264 KB Output is correct
30 Correct 244 ms 39084 KB Output is correct
31 Correct 336 ms 48616 KB Output is correct
32 Correct 0 ms 600 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 448 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 2 ms 1008 KB Output is correct
45 Correct 137 ms 26200 KB Output is correct
46 Correct 234 ms 37876 KB Output is correct
47 Correct 222 ms 37772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 151 ms 27360 KB Output is correct
10 Correct 10 ms 3164 KB Output is correct
11 Correct 71 ms 14900 KB Output is correct
12 Correct 15 ms 4696 KB Output is correct
13 Correct 40 ms 10832 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 155 ms 26676 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 352 KB Output is correct
22 Correct 0 ms 356 KB Output is correct
23 Correct 312 ms 46940 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 1 ms 612 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 101 ms 19568 KB Output is correct
29 Correct 168 ms 29264 KB Output is correct
30 Correct 244 ms 39084 KB Output is correct
31 Correct 336 ms 48616 KB Output is correct
32 Correct 0 ms 600 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 448 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 2 ms 1008 KB Output is correct
45 Correct 137 ms 26200 KB Output is correct
46 Correct 234 ms 37876 KB Output is correct
47 Correct 222 ms 37772 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 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 317 ms 45980 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 2 ms 860 KB Output is correct
58 Correct 8 ms 1816 KB Output is correct
59 Correct 7 ms 2392 KB Output is correct
60 Correct 127 ms 23088 KB Output is correct
61 Correct 194 ms 31144 KB Output is correct
62 Correct 239 ms 38312 KB Output is correct
63 Correct 322 ms 46148 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 1 ms 600 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 364 ms 54184 KB Output is correct
68 Correct 354 ms 55048 KB Output is correct
69 Correct 346 ms 53924 KB Output is correct
70 Correct 3 ms 1112 KB Output is correct
71 Correct 6 ms 2140 KB Output is correct
72 Correct 145 ms 25856 KB Output is correct
73 Correct 244 ms 38696 KB Output is correct
74 Correct 380 ms 51296 KB Output is correct
75 Correct 340 ms 49576 KB Output is correct
76 Correct 340 ms 54948 KB Output is correct
77 Correct 4 ms 1372 KB Output is correct
78 Correct 7 ms 2256 KB Output is correct
79 Correct 142 ms 25448 KB Output is correct
80 Correct 267 ms 37456 KB Output is correct
81 Correct 341 ms 50388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 151 ms 27360 KB Output is correct
10 Correct 10 ms 3164 KB Output is correct
11 Correct 71 ms 14900 KB Output is correct
12 Correct 15 ms 4696 KB Output is correct
13 Correct 40 ms 10832 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 155 ms 26676 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 45852 KB Output is correct
21 Correct 355 ms 54748 KB Output is correct
22 Correct 305 ms 48368 KB Output is correct
23 Correct 276 ms 46252 KB Output is correct
24 Correct 234 ms 43744 KB Output is correct
25 Correct 307 ms 47400 KB Output is correct
26 Correct 257 ms 47272 KB Output is correct
27 Correct 353 ms 53668 KB Output is correct
28 Correct 347 ms 53672 KB Output is correct
29 Correct 345 ms 53640 KB Output is correct
30 Correct 342 ms 53668 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Incorrect 6 ms 1880 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 151 ms 27360 KB Output is correct
10 Correct 10 ms 3164 KB Output is correct
11 Correct 71 ms 14900 KB Output is correct
12 Correct 15 ms 4696 KB Output is correct
13 Correct 40 ms 10832 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 155 ms 26676 KB Output is correct
17 Correct 339 ms 52648 KB Output is correct
18 Correct 378 ms 55300 KB Output is correct
19 Correct 321 ms 51808 KB Output is correct
20 Correct 286 ms 44432 KB Output is correct
21 Correct 252 ms 44712 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Incorrect 13 ms 3676 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 151 ms 27360 KB Output is correct
10 Correct 10 ms 3164 KB Output is correct
11 Correct 71 ms 14900 KB Output is correct
12 Correct 15 ms 4696 KB Output is correct
13 Correct 40 ms 10832 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 155 ms 26676 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 352 KB Output is correct
22 Correct 0 ms 356 KB Output is correct
23 Correct 312 ms 46940 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 1 ms 612 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 101 ms 19568 KB Output is correct
29 Correct 168 ms 29264 KB Output is correct
30 Correct 244 ms 39084 KB Output is correct
31 Correct 336 ms 48616 KB Output is correct
32 Correct 0 ms 600 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 448 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 2 ms 1008 KB Output is correct
45 Correct 137 ms 26200 KB Output is correct
46 Correct 234 ms 37876 KB Output is correct
47 Correct 222 ms 37772 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 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 317 ms 45980 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 2 ms 860 KB Output is correct
58 Correct 8 ms 1816 KB Output is correct
59 Correct 7 ms 2392 KB Output is correct
60 Correct 127 ms 23088 KB Output is correct
61 Correct 194 ms 31144 KB Output is correct
62 Correct 239 ms 38312 KB Output is correct
63 Correct 322 ms 46148 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 1 ms 600 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 364 ms 54184 KB Output is correct
68 Correct 354 ms 55048 KB Output is correct
69 Correct 346 ms 53924 KB Output is correct
70 Correct 3 ms 1112 KB Output is correct
71 Correct 6 ms 2140 KB Output is correct
72 Correct 145 ms 25856 KB Output is correct
73 Correct 244 ms 38696 KB Output is correct
74 Correct 380 ms 51296 KB Output is correct
75 Correct 340 ms 49576 KB Output is correct
76 Correct 340 ms 54948 KB Output is correct
77 Correct 4 ms 1372 KB Output is correct
78 Correct 7 ms 2256 KB Output is correct
79 Correct 142 ms 25448 KB Output is correct
80 Correct 267 ms 37456 KB Output is correct
81 Correct 341 ms 50388 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 45852 KB Output is correct
86 Correct 355 ms 54748 KB Output is correct
87 Correct 305 ms 48368 KB Output is correct
88 Correct 276 ms 46252 KB Output is correct
89 Correct 234 ms 43744 KB Output is correct
90 Correct 307 ms 47400 KB Output is correct
91 Correct 257 ms 47272 KB Output is correct
92 Correct 353 ms 53668 KB Output is correct
93 Correct 347 ms 53672 KB Output is correct
94 Correct 345 ms 53640 KB Output is correct
95 Correct 342 ms 53668 KB Output is correct
96 Correct 0 ms 344 KB Output is correct
97 Incorrect 6 ms 1880 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -