답안 #829711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829711 2023-08-18T14:18:44 Z Abrar_Al_Samit 분수 공원 (IOI21_parks) C++17
30 / 100
777 ms 47400 KB
#include <bits/stdc++.h>
#include "parks.h"
using namespace std;

const int nax = 200000;
vector<int>g[nax];
bool vis[nax];
int par[nax], sz[nax];

void trav(int v) {
    vis[v] = 1;
    for(int u : g[v]) if(!vis[u]) {
        trav(u);
    }
}

int find(int v) {
    return par[v] = (v==par[v]) ? v : find(par[v]);
}
void unite(int u, int v) {
    u = find(u), v = find(v);
    if(sz[u] < sz[v]) swap(u, v);
    sz[u] += sz[v];
    par[v] = u;
}
int construct_roads(vector<int> x, vector<int> y) {
    int n = x.size();
    map<pair<int,int>, int>ft;
    for(int i=0; i<n; ++i) {
        ft[{x[i], y[i]}] = i;
    }

    int dx[] = {2, -2, 0, 0};
    int dy[] = {0, 0, 2, -2};

    vector<int>u, v, a, b;

    map<pair<int,int>, int>ben;

    for(int i=0; i<n; ++i) {
        par[i] = i, sz[i] = 1;
    }
    for(int i=0; i<n; ++i) {
        for(int j=2; j<4; ++j) {
            int nx = x[i] + dx[j], ny = y[i] + dy[j];
            if(ft.count(make_pair(nx, ny))) {
                if(find(i) == find(ft[{nx, ny}])) continue;



                if(x[i]==2) {
                    a.push_back(x[i] - 1);
                    b.push_back(y[i] + ny >> 1);
                } else if(x[i]==6) {
                    a.push_back(x[i] + 1);
                    b.push_back(y[i] + ny >> 1);
                } else {
                    if((y[i]+ny)%8<4) {
                        a.push_back(x[i]-1);
                        b.push_back(y[i] + ny >> 1);
                        ben[{x[i]-1, y[i] + ny >> 1}] = 1;
                    } else {
                        a.push_back(x[i]+1);
                        b.push_back(y[i] + ny >> 1);
                        ben[{x[i]+1, y[i] + ny >> 1}] = 1;
                    }
                }
                g[i].push_back(ft[{nx, ny}]);
                g[ft[{nx, ny}]].push_back(i);
                unite(i, ft[{nx, ny}]);
                u.push_back(i);
                v.push_back(ft[{nx, ny}]);
            }
        }
    }

    for(int i=0; i<n; ++i) {
        if(ft.count(make_pair(x[i]+dx[0], y[i]))
            + ft.count(make_pair(x[i]+dx[1], y[i]))==1) {
            for(int j=0; j<2; ++j) {
                int nx = x[i] + dx[j], ny = y[i] + dy[j];
                if(!ft.count(make_pair(nx, ny))) continue;

                int she = ft[{nx, ny}];
                if(find(i) == find(she)) continue;

                g[i].push_back(she);
                g[she].push_back(i);
                unite(i, she);
                u.push_back(i);
                v.push_back(she);

                if(!ben.count(make_pair(x[i] + nx >> 1, ny - 1))) {
                    ben[{x[i] + nx >> 1, ny - 1}] = 1;
                    a.push_back(x[i] + nx >> 1);
                    b.push_back(ny - 1);
                } else if(!ben.count(make_pair(x[i] + nx >> 1, ny + 1))) {
                    ben[{x[i] + nx >> 1, ny + 1}] = 1;
                    a.push_back(x[i] + nx >> 1);
                    b.push_back(ny + 1);

                } else return 0;
            }
        }
    }
    trav(0);
    for(int i=0; i<n; ++i) if(!vis[i]) {
        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:53:38: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |                     b.push_back(y[i] + ny >> 1);
parks.cpp:56:38: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |                     b.push_back(y[i] + ny >> 1);
parks.cpp:60:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |                         b.push_back(y[i] + ny >> 1);
parks.cpp:61:43: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |                         ben[{x[i]-1, y[i] + ny >> 1}] = 1;
parks.cpp:64:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |                         b.push_back(y[i] + ny >> 1);
parks.cpp:65:43: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |                         ben[{x[i]+1, y[i] + ny >> 1}] = 1;
parks.cpp:93:46: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   93 |                 if(!ben.count(make_pair(x[i] + nx >> 1, ny - 1))) {
parks.cpp:94:31: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   94 |                     ben[{x[i] + nx >> 1, ny - 1}] = 1;
parks.cpp:95:38: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   95 |                     a.push_back(x[i] + nx >> 1);
parks.cpp:97:53: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   97 |                 } else if(!ben.count(make_pair(x[i] + nx >> 1, ny + 1))) {
parks.cpp:98:31: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   98 |                     ben[{x[i] + nx >> 1, ny + 1}] = 1;
parks.cpp:99:38: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   99 |                     a.push_back(x[i] + nx >> 1);
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 187 ms 23144 KB Output is correct
10 Correct 14 ms 6996 KB Output is correct
11 Correct 85 ms 14764 KB Output is correct
12 Correct 20 ms 7976 KB Output is correct
13 Correct 55 ms 11368 KB Output is correct
14 Correct 3 ms 5092 KB Output is correct
15 Correct 4 ms 5276 KB Output is correct
16 Correct 199 ms 22448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 187 ms 23144 KB Output is correct
10 Correct 14 ms 6996 KB Output is correct
11 Correct 85 ms 14764 KB Output is correct
12 Correct 20 ms 7976 KB Output is correct
13 Correct 55 ms 11368 KB Output is correct
14 Correct 3 ms 5092 KB Output is correct
15 Correct 4 ms 5276 KB Output is correct
16 Correct 199 ms 22448 KB Output is correct
17 Correct 3 ms 4924 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 755 ms 45860 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 5 ms 5204 KB Output is correct
26 Correct 7 ms 5500 KB Output is correct
27 Correct 8 ms 5588 KB Output is correct
28 Correct 204 ms 21392 KB Output is correct
29 Correct 393 ms 29448 KB Output is correct
30 Correct 510 ms 37804 KB Output is correct
31 Correct 749 ms 45672 KB Output is correct
32 Correct 2 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 2 ms 4948 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 2 ms 4948 KB Output is correct
38 Correct 2 ms 4948 KB Output is correct
39 Correct 2 ms 4948 KB Output is correct
40 Correct 2 ms 4948 KB Output is correct
41 Correct 3 ms 4976 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 5 ms 5332 KB Output is correct
44 Correct 7 ms 5460 KB Output is correct
45 Correct 291 ms 26744 KB Output is correct
46 Correct 532 ms 36676 KB Output is correct
47 Correct 450 ms 36440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 187 ms 23144 KB Output is correct
10 Correct 14 ms 6996 KB Output is correct
11 Correct 85 ms 14764 KB Output is correct
12 Correct 20 ms 7976 KB Output is correct
13 Correct 55 ms 11368 KB Output is correct
14 Correct 3 ms 5092 KB Output is correct
15 Correct 4 ms 5276 KB Output is correct
16 Correct 199 ms 22448 KB Output is correct
17 Correct 3 ms 4924 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 755 ms 45860 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 5 ms 5204 KB Output is correct
26 Correct 7 ms 5500 KB Output is correct
27 Correct 8 ms 5588 KB Output is correct
28 Correct 204 ms 21392 KB Output is correct
29 Correct 393 ms 29448 KB Output is correct
30 Correct 510 ms 37804 KB Output is correct
31 Correct 749 ms 45672 KB Output is correct
32 Correct 2 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 2 ms 4948 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 2 ms 4948 KB Output is correct
38 Correct 2 ms 4948 KB Output is correct
39 Correct 2 ms 4948 KB Output is correct
40 Correct 2 ms 4948 KB Output is correct
41 Correct 3 ms 4976 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 5 ms 5332 KB Output is correct
44 Correct 7 ms 5460 KB Output is correct
45 Correct 291 ms 26744 KB Output is correct
46 Correct 532 ms 36676 KB Output is correct
47 Correct 450 ms 36440 KB Output is correct
48 Correct 2 ms 4948 KB Output is correct
49 Correct 2 ms 4948 KB Output is correct
50 Correct 2 ms 4948 KB Output is correct
51 Correct 2 ms 4948 KB Output is correct
52 Correct 2 ms 4948 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Correct 2 ms 4948 KB Output is correct
55 Correct 648 ms 45188 KB Output is correct
56 Correct 2 ms 5004 KB Output is correct
57 Correct 5 ms 5332 KB Output is correct
58 Correct 12 ms 6300 KB Output is correct
59 Correct 17 ms 6664 KB Output is correct
60 Correct 270 ms 25540 KB Output is correct
61 Correct 375 ms 32344 KB Output is correct
62 Correct 547 ms 38020 KB Output is correct
63 Correct 694 ms 45160 KB Output is correct
64 Correct 3 ms 5012 KB Output is correct
65 Correct 2 ms 4948 KB Output is correct
66 Correct 2 ms 5012 KB Output is correct
67 Correct 540 ms 42136 KB Output is correct
68 Correct 504 ms 42184 KB Output is correct
69 Correct 488 ms 42420 KB Output is correct
70 Correct 7 ms 5656 KB Output is correct
71 Correct 13 ms 6356 KB Output is correct
72 Correct 256 ms 26324 KB Output is correct
73 Correct 462 ms 37152 KB Output is correct
74 Correct 723 ms 47400 KB Output is correct
75 Correct 583 ms 44812 KB Output is correct
76 Correct 517 ms 42104 KB Output is correct
77 Correct 9 ms 5844 KB Output is correct
78 Correct 15 ms 6556 KB Output is correct
79 Correct 248 ms 25740 KB Output is correct
80 Correct 439 ms 36424 KB Output is correct
81 Correct 777 ms 46828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 187 ms 23144 KB Output is correct
10 Correct 14 ms 6996 KB Output is correct
11 Correct 85 ms 14764 KB Output is correct
12 Correct 20 ms 7976 KB Output is correct
13 Correct 55 ms 11368 KB Output is correct
14 Correct 3 ms 5092 KB Output is correct
15 Correct 4 ms 5276 KB Output is correct
16 Correct 199 ms 22448 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Incorrect 423 ms 36292 KB Solution announced impossible, but it is possible.
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 187 ms 23144 KB Output is correct
10 Correct 14 ms 6996 KB Output is correct
11 Correct 85 ms 14764 KB Output is correct
12 Correct 20 ms 7976 KB Output is correct
13 Correct 55 ms 11368 KB Output is correct
14 Correct 3 ms 5092 KB Output is correct
15 Correct 4 ms 5276 KB Output is correct
16 Correct 199 ms 22448 KB Output is correct
17 Incorrect 390 ms 29976 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 187 ms 23144 KB Output is correct
10 Correct 14 ms 6996 KB Output is correct
11 Correct 85 ms 14764 KB Output is correct
12 Correct 20 ms 7976 KB Output is correct
13 Correct 55 ms 11368 KB Output is correct
14 Correct 3 ms 5092 KB Output is correct
15 Correct 4 ms 5276 KB Output is correct
16 Correct 199 ms 22448 KB Output is correct
17 Correct 3 ms 4924 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 755 ms 45860 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 5 ms 5204 KB Output is correct
26 Correct 7 ms 5500 KB Output is correct
27 Correct 8 ms 5588 KB Output is correct
28 Correct 204 ms 21392 KB Output is correct
29 Correct 393 ms 29448 KB Output is correct
30 Correct 510 ms 37804 KB Output is correct
31 Correct 749 ms 45672 KB Output is correct
32 Correct 2 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 2 ms 4948 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 2 ms 4948 KB Output is correct
38 Correct 2 ms 4948 KB Output is correct
39 Correct 2 ms 4948 KB Output is correct
40 Correct 2 ms 4948 KB Output is correct
41 Correct 3 ms 4976 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 5 ms 5332 KB Output is correct
44 Correct 7 ms 5460 KB Output is correct
45 Correct 291 ms 26744 KB Output is correct
46 Correct 532 ms 36676 KB Output is correct
47 Correct 450 ms 36440 KB Output is correct
48 Correct 2 ms 4948 KB Output is correct
49 Correct 2 ms 4948 KB Output is correct
50 Correct 2 ms 4948 KB Output is correct
51 Correct 2 ms 4948 KB Output is correct
52 Correct 2 ms 4948 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Correct 2 ms 4948 KB Output is correct
55 Correct 648 ms 45188 KB Output is correct
56 Correct 2 ms 5004 KB Output is correct
57 Correct 5 ms 5332 KB Output is correct
58 Correct 12 ms 6300 KB Output is correct
59 Correct 17 ms 6664 KB Output is correct
60 Correct 270 ms 25540 KB Output is correct
61 Correct 375 ms 32344 KB Output is correct
62 Correct 547 ms 38020 KB Output is correct
63 Correct 694 ms 45160 KB Output is correct
64 Correct 3 ms 5012 KB Output is correct
65 Correct 2 ms 4948 KB Output is correct
66 Correct 2 ms 5012 KB Output is correct
67 Correct 540 ms 42136 KB Output is correct
68 Correct 504 ms 42184 KB Output is correct
69 Correct 488 ms 42420 KB Output is correct
70 Correct 7 ms 5656 KB Output is correct
71 Correct 13 ms 6356 KB Output is correct
72 Correct 256 ms 26324 KB Output is correct
73 Correct 462 ms 37152 KB Output is correct
74 Correct 723 ms 47400 KB Output is correct
75 Correct 583 ms 44812 KB Output is correct
76 Correct 517 ms 42104 KB Output is correct
77 Correct 9 ms 5844 KB Output is correct
78 Correct 15 ms 6556 KB Output is correct
79 Correct 248 ms 25740 KB Output is correct
80 Correct 439 ms 36424 KB Output is correct
81 Correct 777 ms 46828 KB Output is correct
82 Correct 2 ms 4948 KB Output is correct
83 Correct 2 ms 4948 KB Output is correct
84 Correct 2 ms 4948 KB Output is correct
85 Incorrect 423 ms 36292 KB Solution announced impossible, but it is possible.
86 Halted 0 ms 0 KB -