답안 #549907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549907 2022-04-16T20:06:10 Z AmirElarbi 분수 공원 (IOI21_parks) C++17
30 / 100
449 ms 62444 KB
#include <bits/stdc++.h>
#include "parks.h"
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18+5
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9+7;
const int nax = 2e5+5;
const int nax2 = 105;
vii srt1[nax], srt2[nax];
ve<pair<int,ii>> ysrt[nax];
int parent[nax];
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b)
        parent[b] = a;
}

set<int> xs,ys;
map<ll, bool> vis;
int construct_roads(vi x, vi  y) {
    int n = x.size();
    vi u,v,a,b;
    for (int i = 0; i < n; ++i)
    {
        xs.insert(x[i]);
        ys.insert(y[i]);
        srt1[x[i]].pb({y[i], i});
        srt2[y[i]].pb({x[i], i});
        parent[i] = i;
    }
    for(auto cury : ys){
        vii srt = srt2[cury];
        sort(srt.begin(), srt.end());
        for (int i = 0; i < srt.size()-1; ++i)
        {
            int curx = srt[i].fi;
            if(srt[i+1].fi-srt[i].fi == 2)
                ysrt[curx].pb({cury,{srt[i].se,srt[i+1].se}});
        }
    }
    int cnt = 0;
    for(auto curx : xs){
        vii srt = srt1[curx];
        sort(srt.begin(), srt.end());
        for (int i = 0; i < (int)srt.size()-1; ++i)
        {
            if(srt[i+1].fi-srt[i].fi == 2){
                if(find_set(srt[i].se) == find_set(srt[i+1].se)) continue;
                u.pb(0), v.pb(0),a.pb(0),b.pb(0);
                union_sets(srt[i].se,srt[i+1].se);
                int ny = (srt[i].fi+srt[i+1].fi)/2;
                u[cnt] = srt[i].se,v[cnt] = srt[i+1].se, b[cnt] = ny;
                if(vis[ny*nax+curx-1]){
                    a[cnt] = curx+1;   
                    vis[ny*nax+curx+1] = 1;
                }
                else{
                    vis[ny*nax+curx-1] = 1;
                    a[cnt] = curx-1;  
                }
                cnt++;
            }
        }
        for(auto cury : ysrt[curx]){
            if(find_set(cury.se.fi) == find_set(cury.se.se)) continue;
            u.pb(0), v.pb(0),a.pb(0),b.pb(0);
            union_sets(cury.se.fi,cury.se.se);
            u[cnt] = cury.se.fi,v[cnt] = cury.se.se;
            a[cnt] = curx+1;
            if(!vis[(cury.fi-1)*nax+curx+1]){
                b[cnt] = cury.fi-1;   
                vis[(cury.fi-1)*nax+curx+1] = 1;
            }
            else{
                b[cnt] = cury.fi+1;   
                vis[(cury.fi+1)*nax+curx+1] = 1;
            }
            cnt++;
        }
    }
    int un = find_set(0);
    for (int i = 1; i < n; ++i)
    {
        if(find_set(i) != un) 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:58:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for (int i = 0; i < srt.size()-1; ++i)
      |                         ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14312 KB Output is correct
2 Correct 8 ms 14396 KB Output is correct
3 Correct 8 ms 14404 KB Output is correct
4 Correct 8 ms 14320 KB Output is correct
5 Correct 8 ms 14292 KB Output is correct
6 Correct 8 ms 14360 KB Output is correct
7 Correct 8 ms 14292 KB Output is correct
8 Correct 8 ms 14292 KB Output is correct
9 Correct 156 ms 38104 KB Output is correct
10 Correct 21 ms 16852 KB Output is correct
11 Correct 63 ms 27060 KB Output is correct
12 Correct 23 ms 18004 KB Output is correct
13 Correct 37 ms 23236 KB Output is correct
14 Correct 8 ms 14548 KB Output is correct
15 Correct 10 ms 14804 KB Output is correct
16 Correct 178 ms 38092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14312 KB Output is correct
2 Correct 8 ms 14396 KB Output is correct
3 Correct 8 ms 14404 KB Output is correct
4 Correct 8 ms 14320 KB Output is correct
5 Correct 8 ms 14292 KB Output is correct
6 Correct 8 ms 14360 KB Output is correct
7 Correct 8 ms 14292 KB Output is correct
8 Correct 8 ms 14292 KB Output is correct
9 Correct 156 ms 38104 KB Output is correct
10 Correct 21 ms 16852 KB Output is correct
11 Correct 63 ms 27060 KB Output is correct
12 Correct 23 ms 18004 KB Output is correct
13 Correct 37 ms 23236 KB Output is correct
14 Correct 8 ms 14548 KB Output is correct
15 Correct 10 ms 14804 KB Output is correct
16 Correct 178 ms 38092 KB Output is correct
17 Correct 7 ms 14396 KB Output is correct
18 Correct 8 ms 14296 KB Output is correct
19 Correct 8 ms 14292 KB Output is correct
20 Correct 8 ms 14292 KB Output is correct
21 Correct 8 ms 14292 KB Output is correct
22 Correct 8 ms 14292 KB Output is correct
23 Correct 311 ms 52652 KB Output is correct
24 Correct 9 ms 14292 KB Output is correct
25 Correct 9 ms 14664 KB Output is correct
26 Correct 10 ms 14856 KB Output is correct
27 Correct 10 ms 15048 KB Output is correct
28 Correct 95 ms 29752 KB Output is correct
29 Correct 153 ms 37268 KB Output is correct
30 Correct 213 ms 45544 KB Output is correct
31 Correct 277 ms 52616 KB Output is correct
32 Correct 8 ms 14292 KB Output is correct
33 Correct 8 ms 14292 KB Output is correct
34 Correct 8 ms 14292 KB Output is correct
35 Correct 8 ms 14400 KB Output is correct
36 Correct 8 ms 14292 KB Output is correct
37 Correct 8 ms 14296 KB Output is correct
38 Correct 8 ms 14292 KB Output is correct
39 Correct 8 ms 14360 KB Output is correct
40 Correct 8 ms 14304 KB Output is correct
41 Correct 9 ms 14392 KB Output is correct
42 Correct 10 ms 14400 KB Output is correct
43 Correct 10 ms 14676 KB Output is correct
44 Correct 11 ms 14932 KB Output is correct
45 Correct 149 ms 34836 KB Output is correct
46 Correct 245 ms 44688 KB Output is correct
47 Correct 252 ms 44936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14312 KB Output is correct
2 Correct 8 ms 14396 KB Output is correct
3 Correct 8 ms 14404 KB Output is correct
4 Correct 8 ms 14320 KB Output is correct
5 Correct 8 ms 14292 KB Output is correct
6 Correct 8 ms 14360 KB Output is correct
7 Correct 8 ms 14292 KB Output is correct
8 Correct 8 ms 14292 KB Output is correct
9 Correct 156 ms 38104 KB Output is correct
10 Correct 21 ms 16852 KB Output is correct
11 Correct 63 ms 27060 KB Output is correct
12 Correct 23 ms 18004 KB Output is correct
13 Correct 37 ms 23236 KB Output is correct
14 Correct 8 ms 14548 KB Output is correct
15 Correct 10 ms 14804 KB Output is correct
16 Correct 178 ms 38092 KB Output is correct
17 Correct 7 ms 14396 KB Output is correct
18 Correct 8 ms 14296 KB Output is correct
19 Correct 8 ms 14292 KB Output is correct
20 Correct 8 ms 14292 KB Output is correct
21 Correct 8 ms 14292 KB Output is correct
22 Correct 8 ms 14292 KB Output is correct
23 Correct 311 ms 52652 KB Output is correct
24 Correct 9 ms 14292 KB Output is correct
25 Correct 9 ms 14664 KB Output is correct
26 Correct 10 ms 14856 KB Output is correct
27 Correct 10 ms 15048 KB Output is correct
28 Correct 95 ms 29752 KB Output is correct
29 Correct 153 ms 37268 KB Output is correct
30 Correct 213 ms 45544 KB Output is correct
31 Correct 277 ms 52616 KB Output is correct
32 Correct 8 ms 14292 KB Output is correct
33 Correct 8 ms 14292 KB Output is correct
34 Correct 8 ms 14292 KB Output is correct
35 Correct 8 ms 14400 KB Output is correct
36 Correct 8 ms 14292 KB Output is correct
37 Correct 8 ms 14296 KB Output is correct
38 Correct 8 ms 14292 KB Output is correct
39 Correct 8 ms 14360 KB Output is correct
40 Correct 8 ms 14304 KB Output is correct
41 Correct 9 ms 14392 KB Output is correct
42 Correct 10 ms 14400 KB Output is correct
43 Correct 10 ms 14676 KB Output is correct
44 Correct 11 ms 14932 KB Output is correct
45 Correct 149 ms 34836 KB Output is correct
46 Correct 245 ms 44688 KB Output is correct
47 Correct 252 ms 44936 KB Output is correct
48 Correct 8 ms 14292 KB Output is correct
49 Correct 9 ms 14292 KB Output is correct
50 Correct 7 ms 14392 KB Output is correct
51 Correct 7 ms 14396 KB Output is correct
52 Correct 9 ms 14396 KB Output is correct
53 Correct 8 ms 14292 KB Output is correct
54 Correct 8 ms 14292 KB Output is correct
55 Correct 302 ms 53052 KB Output is correct
56 Correct 8 ms 14292 KB Output is correct
57 Correct 10 ms 14796 KB Output is correct
58 Correct 13 ms 15564 KB Output is correct
59 Correct 16 ms 16020 KB Output is correct
60 Correct 122 ms 33996 KB Output is correct
61 Correct 176 ms 40608 KB Output is correct
62 Correct 235 ms 46244 KB Output is correct
63 Correct 258 ms 53256 KB Output is correct
64 Correct 8 ms 14292 KB Output is correct
65 Correct 8 ms 14292 KB Output is correct
66 Correct 8 ms 14292 KB Output is correct
67 Correct 300 ms 51664 KB Output is correct
68 Correct 298 ms 52004 KB Output is correct
69 Correct 303 ms 52436 KB Output is correct
70 Correct 10 ms 15060 KB Output is correct
71 Correct 16 ms 15644 KB Output is correct
72 Correct 197 ms 33628 KB Output is correct
73 Correct 229 ms 43048 KB Output is correct
74 Correct 303 ms 52824 KB Output is correct
75 Correct 332 ms 52804 KB Output is correct
76 Correct 319 ms 52440 KB Output is correct
77 Correct 12 ms 15224 KB Output is correct
78 Correct 17 ms 15824 KB Output is correct
79 Correct 143 ms 33500 KB Output is correct
80 Correct 229 ms 43252 KB Output is correct
81 Correct 305 ms 52864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14312 KB Output is correct
2 Correct 8 ms 14396 KB Output is correct
3 Correct 8 ms 14404 KB Output is correct
4 Correct 8 ms 14320 KB Output is correct
5 Correct 8 ms 14292 KB Output is correct
6 Correct 8 ms 14360 KB Output is correct
7 Correct 8 ms 14292 KB Output is correct
8 Correct 8 ms 14292 KB Output is correct
9 Correct 156 ms 38104 KB Output is correct
10 Correct 21 ms 16852 KB Output is correct
11 Correct 63 ms 27060 KB Output is correct
12 Correct 23 ms 18004 KB Output is correct
13 Correct 37 ms 23236 KB Output is correct
14 Correct 8 ms 14548 KB Output is correct
15 Correct 10 ms 14804 KB Output is correct
16 Correct 178 ms 38092 KB Output is correct
17 Correct 8 ms 14292 KB Output is correct
18 Correct 8 ms 14292 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 449 ms 62444 KB Output is correct
21 Correct 373 ms 53800 KB Output is correct
22 Correct 365 ms 54224 KB Output is correct
23 Correct 278 ms 47968 KB Output is correct
24 Correct 103 ms 24012 KB Output is correct
25 Correct 143 ms 41612 KB Output is correct
26 Correct 144 ms 39224 KB Output is correct
27 Correct 205 ms 45556 KB Output is correct
28 Correct 229 ms 45320 KB Output is correct
29 Correct 229 ms 48324 KB Output is correct
30 Correct 224 ms 48668 KB Output is correct
31 Correct 9 ms 14292 KB Output is correct
32 Incorrect 26 ms 17224 KB Tree @(185725, 20413) appears more than once: for edges on positions 631 and 647
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14312 KB Output is correct
2 Correct 8 ms 14396 KB Output is correct
3 Correct 8 ms 14404 KB Output is correct
4 Correct 8 ms 14320 KB Output is correct
5 Correct 8 ms 14292 KB Output is correct
6 Correct 8 ms 14360 KB Output is correct
7 Correct 8 ms 14292 KB Output is correct
8 Correct 8 ms 14292 KB Output is correct
9 Correct 156 ms 38104 KB Output is correct
10 Correct 21 ms 16852 KB Output is correct
11 Correct 63 ms 27060 KB Output is correct
12 Correct 23 ms 18004 KB Output is correct
13 Correct 37 ms 23236 KB Output is correct
14 Correct 8 ms 14548 KB Output is correct
15 Correct 10 ms 14804 KB Output is correct
16 Correct 178 ms 38092 KB Output is correct
17 Correct 311 ms 53624 KB Output is correct
18 Correct 322 ms 53700 KB Output is correct
19 Incorrect 364 ms 54172 KB Tree @(69227, 80777) appears more than once: for edges on positions 138446 and 138448
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14312 KB Output is correct
2 Correct 8 ms 14396 KB Output is correct
3 Correct 8 ms 14404 KB Output is correct
4 Correct 8 ms 14320 KB Output is correct
5 Correct 8 ms 14292 KB Output is correct
6 Correct 8 ms 14360 KB Output is correct
7 Correct 8 ms 14292 KB Output is correct
8 Correct 8 ms 14292 KB Output is correct
9 Correct 156 ms 38104 KB Output is correct
10 Correct 21 ms 16852 KB Output is correct
11 Correct 63 ms 27060 KB Output is correct
12 Correct 23 ms 18004 KB Output is correct
13 Correct 37 ms 23236 KB Output is correct
14 Correct 8 ms 14548 KB Output is correct
15 Correct 10 ms 14804 KB Output is correct
16 Correct 178 ms 38092 KB Output is correct
17 Correct 7 ms 14396 KB Output is correct
18 Correct 8 ms 14296 KB Output is correct
19 Correct 8 ms 14292 KB Output is correct
20 Correct 8 ms 14292 KB Output is correct
21 Correct 8 ms 14292 KB Output is correct
22 Correct 8 ms 14292 KB Output is correct
23 Correct 311 ms 52652 KB Output is correct
24 Correct 9 ms 14292 KB Output is correct
25 Correct 9 ms 14664 KB Output is correct
26 Correct 10 ms 14856 KB Output is correct
27 Correct 10 ms 15048 KB Output is correct
28 Correct 95 ms 29752 KB Output is correct
29 Correct 153 ms 37268 KB Output is correct
30 Correct 213 ms 45544 KB Output is correct
31 Correct 277 ms 52616 KB Output is correct
32 Correct 8 ms 14292 KB Output is correct
33 Correct 8 ms 14292 KB Output is correct
34 Correct 8 ms 14292 KB Output is correct
35 Correct 8 ms 14400 KB Output is correct
36 Correct 8 ms 14292 KB Output is correct
37 Correct 8 ms 14296 KB Output is correct
38 Correct 8 ms 14292 KB Output is correct
39 Correct 8 ms 14360 KB Output is correct
40 Correct 8 ms 14304 KB Output is correct
41 Correct 9 ms 14392 KB Output is correct
42 Correct 10 ms 14400 KB Output is correct
43 Correct 10 ms 14676 KB Output is correct
44 Correct 11 ms 14932 KB Output is correct
45 Correct 149 ms 34836 KB Output is correct
46 Correct 245 ms 44688 KB Output is correct
47 Correct 252 ms 44936 KB Output is correct
48 Correct 8 ms 14292 KB Output is correct
49 Correct 9 ms 14292 KB Output is correct
50 Correct 7 ms 14392 KB Output is correct
51 Correct 7 ms 14396 KB Output is correct
52 Correct 9 ms 14396 KB Output is correct
53 Correct 8 ms 14292 KB Output is correct
54 Correct 8 ms 14292 KB Output is correct
55 Correct 302 ms 53052 KB Output is correct
56 Correct 8 ms 14292 KB Output is correct
57 Correct 10 ms 14796 KB Output is correct
58 Correct 13 ms 15564 KB Output is correct
59 Correct 16 ms 16020 KB Output is correct
60 Correct 122 ms 33996 KB Output is correct
61 Correct 176 ms 40608 KB Output is correct
62 Correct 235 ms 46244 KB Output is correct
63 Correct 258 ms 53256 KB Output is correct
64 Correct 8 ms 14292 KB Output is correct
65 Correct 8 ms 14292 KB Output is correct
66 Correct 8 ms 14292 KB Output is correct
67 Correct 300 ms 51664 KB Output is correct
68 Correct 298 ms 52004 KB Output is correct
69 Correct 303 ms 52436 KB Output is correct
70 Correct 10 ms 15060 KB Output is correct
71 Correct 16 ms 15644 KB Output is correct
72 Correct 197 ms 33628 KB Output is correct
73 Correct 229 ms 43048 KB Output is correct
74 Correct 303 ms 52824 KB Output is correct
75 Correct 332 ms 52804 KB Output is correct
76 Correct 319 ms 52440 KB Output is correct
77 Correct 12 ms 15224 KB Output is correct
78 Correct 17 ms 15824 KB Output is correct
79 Correct 143 ms 33500 KB Output is correct
80 Correct 229 ms 43252 KB Output is correct
81 Correct 305 ms 52864 KB Output is correct
82 Correct 8 ms 14292 KB Output is correct
83 Correct 8 ms 14292 KB Output is correct
84 Correct 8 ms 14420 KB Output is correct
85 Correct 449 ms 62444 KB Output is correct
86 Correct 373 ms 53800 KB Output is correct
87 Correct 365 ms 54224 KB Output is correct
88 Correct 278 ms 47968 KB Output is correct
89 Correct 103 ms 24012 KB Output is correct
90 Correct 143 ms 41612 KB Output is correct
91 Correct 144 ms 39224 KB Output is correct
92 Correct 205 ms 45556 KB Output is correct
93 Correct 229 ms 45320 KB Output is correct
94 Correct 229 ms 48324 KB Output is correct
95 Correct 224 ms 48668 KB Output is correct
96 Correct 9 ms 14292 KB Output is correct
97 Incorrect 26 ms 17224 KB Tree @(185725, 20413) appears more than once: for edges on positions 631 and 647
98 Halted 0 ms 0 KB -