답안 #760842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760842 2023-06-18T16:37:05 Z caganyanmaz 분수 공원 (IOI21_parks) C++17
30 / 100
279 ms 103056 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

constexpr static int SIZE = 200001;

vector<int> g[SIZE];
bitset<SIZE> visited;
vector<array<int, 2>> rows[SIZE];
vector<array<int, 2>> intervals[SIZE];

void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b);

void configure_rows(const vector<int>& x, const vector<int>& y)
{
        int n = x.size();
        for (int i = 0; i < n; i++)
                rows[y[i]].pb({x[i], i});
        for (int i = 0; i < SIZE; i+=2)
                sort(rows[i].begin(), rows[i].end());

}

void configure_intervals()
{
        for (int y = 0; y < SIZE; y+=2)
        {
                if (rows[y].empty())
                        continue;
                intervals[y].pb({rows[y][0][0], rows[y][0][0]});
                for (int i = 1; i < rows[y].size(); i++)
                {
                        if (intervals[y].back()[1] + 2 == rows[y][i][0])
                        {
                                intervals[y].back()[1] = rows[y][i][0];
                                g[rows[y][i-1][1]].pb(rows[y][i][1]);
                                g[rows[y][i][1]].pb(rows[y][i-1][1]);
                        }
                        else
                        {
                                intervals[y].pb({rows[y][i][0], rows[y][i][0]});
                        }

                }
        }
}

// Line from a1 to a2 and line from b1 to b2
// Checking intersection (touching also counts)
bool is_intersecting(int a1, int a2, int b1, int b2)
{
        return (b2 >= a1 && a1 >= b1) || (b2 >= a2 && a2 >= b1) || (a2 >= b1 && b1 >= a1) || (a2 >= b2 && b2 >= a1);
}

void configure_horizontal_connections()
{
        for (int y = 2; y < SIZE; y+=2)
        {
                int i = 0, j = 0;
                while (i < intervals[y].size() && j < intervals[y-2].size())
                {
                        if (is_intersecting(intervals[y][i][0], intervals[y][i][1], intervals[y-2][j][0], intervals[y-2][j][1]))
                        {
                                int x = max(intervals[y][i][0], intervals[y-2][j][0]);
                                array<int, 2> pos = {x, 0};
                                int a = (*lower_bound(rows[y].begin(), rows[y].end(), pos))[1];
                                int b = (*lower_bound(rows[y-2].begin(), rows[y-2].end(), pos))[1];
                                g[a].pb(b);
                                g[b].pb(a);

                        }
                        if (intervals[y][i][1] > intervals[y-2][j][1])
                                j++;
                        else
                                i++;
                }
        }
}


int node_sum = 0;
void dfs(int node)
{
        visited[node] = true;
        node_sum++;
        for (int c : g[node])
                if (!visited[c])
                        dfs(c);
}

void build_grid(const vector<int>& xv, const vector<int>& yv)
{
        vector<int> u, v, a, b;
        set<array<int, 2>> fountains;
        for (int y = 0; y < SIZE; y+=2)
        {
                for (auto [x, node] : rows[y])
                {
                        for (int c : g[node])
                        {
                                if (yv[c] != y || xv[c] > x)
                                        continue;
                                int fx = x-1, fy = y-1;
                                if (fountains.find({fx, fy}) != fountains.end())
                                        fy += 2;
                                assert(fountains.find({fx, fy}) == fountains.end());
                                u.pb(node), v.pb(c), a.pb(fx), b.pb(fy);
                                fountains.insert({fx, fy});
                        }
                }
                for (auto [x, node] : rows[y])
                {
                        for (int c : g[node])
                        {
                                if (yv[c] <= y)
                                        continue;
                                int fx = x-1, fy = y+1;
                                if (fountains.find({fx, fy}) != fountains.end())
                                        fx += 2;
                                assert(fountains.find({fx, fy}) == fountains.end());
                                u.pb(node), v.pb(c), a.pb(fx), b.pb(fy);
                                fountains.insert({fx, fy});
                        }
                }
        }
        build(u, v, a, b);

}

int construct_roads(vector<int> x, vector<int> y)
{
        configure_rows(x, y);
        configure_intervals();
        configure_horizontal_connections();
        dfs(0);
        if (node_sum < x.size())
                return 0;
        else
                build_grid(x, y);
        return 1;
}

Compilation message

parks.cpp: In function 'void configure_intervals()':
parks.cpp:31:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |                 for (int i = 1; i < rows[y].size(); i++)
      |                                 ~~^~~~~~~~~~~~~~~~
parks.cpp: In function 'void configure_horizontal_connections()':
parks.cpp:60:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                 while (i < intervals[y].size() && j < intervals[y-2].size())
      |                        ~~^~~~~~~~~~~~~~~~~~~~~
parks.cpp:60:53: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                 while (i < intervals[y].size() && j < intervals[y-2].size())
      |                                                   ~~^~~~~~~~~~~~~~~~~~~~~~~
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:136:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |         if (node_sum < x.size())
      |             ~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14292 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 6 ms 14360 KB Output is correct
4 Correct 7 ms 14392 KB Output is correct
5 Correct 7 ms 14296 KB Output is correct
6 Correct 7 ms 14396 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 6 ms 14292 KB Output is correct
9 Correct 114 ms 39836 KB Output is correct
10 Correct 19 ms 17108 KB Output is correct
11 Correct 64 ms 28336 KB Output is correct
12 Correct 20 ms 18444 KB Output is correct
13 Correct 21 ms 21012 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14548 KB Output is correct
16 Correct 117 ms 37984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14292 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 6 ms 14360 KB Output is correct
4 Correct 7 ms 14392 KB Output is correct
5 Correct 7 ms 14296 KB Output is correct
6 Correct 7 ms 14396 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 6 ms 14292 KB Output is correct
9 Correct 114 ms 39836 KB Output is correct
10 Correct 19 ms 17108 KB Output is correct
11 Correct 64 ms 28336 KB Output is correct
12 Correct 20 ms 18444 KB Output is correct
13 Correct 21 ms 21012 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14548 KB Output is correct
16 Correct 117 ms 37984 KB Output is correct
17 Correct 7 ms 14396 KB Output is correct
18 Correct 7 ms 14292 KB Output is correct
19 Correct 8 ms 14388 KB Output is correct
20 Correct 10 ms 14292 KB Output is correct
21 Correct 7 ms 14292 KB Output is correct
22 Correct 8 ms 14292 KB Output is correct
23 Correct 242 ms 54652 KB Output is correct
24 Correct 9 ms 14292 KB Output is correct
25 Correct 8 ms 14548 KB Output is correct
26 Correct 9 ms 14576 KB Output is correct
27 Correct 8 ms 14676 KB Output is correct
28 Correct 86 ms 30596 KB Output is correct
29 Correct 156 ms 38240 KB Output is correct
30 Correct 186 ms 46824 KB Output is correct
31 Correct 238 ms 54176 KB Output is correct
32 Correct 7 ms 14292 KB Output is correct
33 Correct 9 ms 14392 KB Output is correct
34 Correct 8 ms 14392 KB Output is correct
35 Correct 8 ms 14316 KB Output is correct
36 Correct 10 ms 14396 KB Output is correct
37 Correct 8 ms 14292 KB Output is correct
38 Correct 8 ms 14292 KB Output is correct
39 Correct 7 ms 14400 KB Output is correct
40 Correct 7 ms 14292 KB Output is correct
41 Correct 7 ms 14392 KB Output is correct
42 Correct 7 ms 14396 KB Output is correct
43 Correct 8 ms 14536 KB Output is correct
44 Correct 9 ms 14676 KB Output is correct
45 Correct 133 ms 36496 KB Output is correct
46 Correct 179 ms 46716 KB Output is correct
47 Correct 189 ms 46584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14292 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 6 ms 14360 KB Output is correct
4 Correct 7 ms 14392 KB Output is correct
5 Correct 7 ms 14296 KB Output is correct
6 Correct 7 ms 14396 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 6 ms 14292 KB Output is correct
9 Correct 114 ms 39836 KB Output is correct
10 Correct 19 ms 17108 KB Output is correct
11 Correct 64 ms 28336 KB Output is correct
12 Correct 20 ms 18444 KB Output is correct
13 Correct 21 ms 21012 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14548 KB Output is correct
16 Correct 117 ms 37984 KB Output is correct
17 Correct 7 ms 14396 KB Output is correct
18 Correct 7 ms 14292 KB Output is correct
19 Correct 8 ms 14388 KB Output is correct
20 Correct 10 ms 14292 KB Output is correct
21 Correct 7 ms 14292 KB Output is correct
22 Correct 8 ms 14292 KB Output is correct
23 Correct 242 ms 54652 KB Output is correct
24 Correct 9 ms 14292 KB Output is correct
25 Correct 8 ms 14548 KB Output is correct
26 Correct 9 ms 14576 KB Output is correct
27 Correct 8 ms 14676 KB Output is correct
28 Correct 86 ms 30596 KB Output is correct
29 Correct 156 ms 38240 KB Output is correct
30 Correct 186 ms 46824 KB Output is correct
31 Correct 238 ms 54176 KB Output is correct
32 Correct 7 ms 14292 KB Output is correct
33 Correct 9 ms 14392 KB Output is correct
34 Correct 8 ms 14392 KB Output is correct
35 Correct 8 ms 14316 KB Output is correct
36 Correct 10 ms 14396 KB Output is correct
37 Correct 8 ms 14292 KB Output is correct
38 Correct 8 ms 14292 KB Output is correct
39 Correct 7 ms 14400 KB Output is correct
40 Correct 7 ms 14292 KB Output is correct
41 Correct 7 ms 14392 KB Output is correct
42 Correct 7 ms 14396 KB Output is correct
43 Correct 8 ms 14536 KB Output is correct
44 Correct 9 ms 14676 KB Output is correct
45 Correct 133 ms 36496 KB Output is correct
46 Correct 179 ms 46716 KB Output is correct
47 Correct 189 ms 46584 KB Output is correct
48 Correct 9 ms 14292 KB Output is correct
49 Correct 7 ms 14396 KB Output is correct
50 Correct 11 ms 14396 KB Output is correct
51 Correct 8 ms 14376 KB Output is correct
52 Correct 7 ms 14292 KB Output is correct
53 Correct 8 ms 14292 KB Output is correct
54 Correct 8 ms 14292 KB Output is correct
55 Correct 244 ms 52028 KB Output is correct
56 Correct 8 ms 14292 KB Output is correct
57 Correct 12 ms 14676 KB Output is correct
58 Correct 12 ms 15572 KB Output is correct
59 Correct 11 ms 15236 KB Output is correct
60 Correct 106 ms 33368 KB Output is correct
61 Correct 142 ms 39968 KB Output is correct
62 Correct 184 ms 45512 KB Output is correct
63 Correct 227 ms 51820 KB Output is correct
64 Correct 7 ms 14396 KB Output is correct
65 Correct 7 ms 14292 KB Output is correct
66 Correct 7 ms 14328 KB Output is correct
67 Correct 235 ms 57104 KB Output is correct
68 Correct 240 ms 57312 KB Output is correct
69 Correct 232 ms 58140 KB Output is correct
70 Correct 8 ms 14676 KB Output is correct
71 Correct 10 ms 15048 KB Output is correct
72 Correct 114 ms 34068 KB Output is correct
73 Correct 172 ms 45084 KB Output is correct
74 Correct 243 ms 53920 KB Output is correct
75 Correct 279 ms 60960 KB Output is correct
76 Correct 243 ms 59936 KB Output is correct
77 Correct 8 ms 14804 KB Output is correct
78 Correct 10 ms 15172 KB Output is correct
79 Correct 114 ms 35692 KB Output is correct
80 Correct 180 ms 46856 KB Output is correct
81 Correct 275 ms 57828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14292 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 6 ms 14360 KB Output is correct
4 Correct 7 ms 14392 KB Output is correct
5 Correct 7 ms 14296 KB Output is correct
6 Correct 7 ms 14396 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 6 ms 14292 KB Output is correct
9 Correct 114 ms 39836 KB Output is correct
10 Correct 19 ms 17108 KB Output is correct
11 Correct 64 ms 28336 KB Output is correct
12 Correct 20 ms 18444 KB Output is correct
13 Correct 21 ms 21012 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14548 KB Output is correct
16 Correct 117 ms 37984 KB Output is correct
17 Correct 7 ms 14292 KB Output is correct
18 Correct 7 ms 14292 KB Output is correct
19 Correct 7 ms 14332 KB Output is correct
20 Correct 241 ms 60576 KB Output is correct
21 Correct 226 ms 56348 KB Output is correct
22 Correct 240 ms 55292 KB Output is correct
23 Correct 172 ms 47692 KB Output is correct
24 Correct 49 ms 23508 KB Output is correct
25 Correct 63 ms 27380 KB Output is correct
26 Correct 80 ms 29400 KB Output is correct
27 Correct 215 ms 48288 KB Output is correct
28 Correct 209 ms 48316 KB Output is correct
29 Correct 198 ms 45892 KB Output is correct
30 Correct 190 ms 45860 KB Output is correct
31 Correct 7 ms 14292 KB Output is correct
32 Runtime error 23 ms 31672 KB Execution killed with signal 6
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14292 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 6 ms 14360 KB Output is correct
4 Correct 7 ms 14392 KB Output is correct
5 Correct 7 ms 14296 KB Output is correct
6 Correct 7 ms 14396 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 6 ms 14292 KB Output is correct
9 Correct 114 ms 39836 KB Output is correct
10 Correct 19 ms 17108 KB Output is correct
11 Correct 64 ms 28336 KB Output is correct
12 Correct 20 ms 18444 KB Output is correct
13 Correct 21 ms 21012 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14548 KB Output is correct
16 Correct 117 ms 37984 KB Output is correct
17 Correct 214 ms 57876 KB Output is correct
18 Correct 232 ms 57152 KB Output is correct
19 Runtime error 204 ms 103056 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14292 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 6 ms 14360 KB Output is correct
4 Correct 7 ms 14392 KB Output is correct
5 Correct 7 ms 14296 KB Output is correct
6 Correct 7 ms 14396 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 6 ms 14292 KB Output is correct
9 Correct 114 ms 39836 KB Output is correct
10 Correct 19 ms 17108 KB Output is correct
11 Correct 64 ms 28336 KB Output is correct
12 Correct 20 ms 18444 KB Output is correct
13 Correct 21 ms 21012 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14548 KB Output is correct
16 Correct 117 ms 37984 KB Output is correct
17 Correct 7 ms 14396 KB Output is correct
18 Correct 7 ms 14292 KB Output is correct
19 Correct 8 ms 14388 KB Output is correct
20 Correct 10 ms 14292 KB Output is correct
21 Correct 7 ms 14292 KB Output is correct
22 Correct 8 ms 14292 KB Output is correct
23 Correct 242 ms 54652 KB Output is correct
24 Correct 9 ms 14292 KB Output is correct
25 Correct 8 ms 14548 KB Output is correct
26 Correct 9 ms 14576 KB Output is correct
27 Correct 8 ms 14676 KB Output is correct
28 Correct 86 ms 30596 KB Output is correct
29 Correct 156 ms 38240 KB Output is correct
30 Correct 186 ms 46824 KB Output is correct
31 Correct 238 ms 54176 KB Output is correct
32 Correct 7 ms 14292 KB Output is correct
33 Correct 9 ms 14392 KB Output is correct
34 Correct 8 ms 14392 KB Output is correct
35 Correct 8 ms 14316 KB Output is correct
36 Correct 10 ms 14396 KB Output is correct
37 Correct 8 ms 14292 KB Output is correct
38 Correct 8 ms 14292 KB Output is correct
39 Correct 7 ms 14400 KB Output is correct
40 Correct 7 ms 14292 KB Output is correct
41 Correct 7 ms 14392 KB Output is correct
42 Correct 7 ms 14396 KB Output is correct
43 Correct 8 ms 14536 KB Output is correct
44 Correct 9 ms 14676 KB Output is correct
45 Correct 133 ms 36496 KB Output is correct
46 Correct 179 ms 46716 KB Output is correct
47 Correct 189 ms 46584 KB Output is correct
48 Correct 9 ms 14292 KB Output is correct
49 Correct 7 ms 14396 KB Output is correct
50 Correct 11 ms 14396 KB Output is correct
51 Correct 8 ms 14376 KB Output is correct
52 Correct 7 ms 14292 KB Output is correct
53 Correct 8 ms 14292 KB Output is correct
54 Correct 8 ms 14292 KB Output is correct
55 Correct 244 ms 52028 KB Output is correct
56 Correct 8 ms 14292 KB Output is correct
57 Correct 12 ms 14676 KB Output is correct
58 Correct 12 ms 15572 KB Output is correct
59 Correct 11 ms 15236 KB Output is correct
60 Correct 106 ms 33368 KB Output is correct
61 Correct 142 ms 39968 KB Output is correct
62 Correct 184 ms 45512 KB Output is correct
63 Correct 227 ms 51820 KB Output is correct
64 Correct 7 ms 14396 KB Output is correct
65 Correct 7 ms 14292 KB Output is correct
66 Correct 7 ms 14328 KB Output is correct
67 Correct 235 ms 57104 KB Output is correct
68 Correct 240 ms 57312 KB Output is correct
69 Correct 232 ms 58140 KB Output is correct
70 Correct 8 ms 14676 KB Output is correct
71 Correct 10 ms 15048 KB Output is correct
72 Correct 114 ms 34068 KB Output is correct
73 Correct 172 ms 45084 KB Output is correct
74 Correct 243 ms 53920 KB Output is correct
75 Correct 279 ms 60960 KB Output is correct
76 Correct 243 ms 59936 KB Output is correct
77 Correct 8 ms 14804 KB Output is correct
78 Correct 10 ms 15172 KB Output is correct
79 Correct 114 ms 35692 KB Output is correct
80 Correct 180 ms 46856 KB Output is correct
81 Correct 275 ms 57828 KB Output is correct
82 Correct 7 ms 14292 KB Output is correct
83 Correct 7 ms 14292 KB Output is correct
84 Correct 7 ms 14332 KB Output is correct
85 Correct 241 ms 60576 KB Output is correct
86 Correct 226 ms 56348 KB Output is correct
87 Correct 240 ms 55292 KB Output is correct
88 Correct 172 ms 47692 KB Output is correct
89 Correct 49 ms 23508 KB Output is correct
90 Correct 63 ms 27380 KB Output is correct
91 Correct 80 ms 29400 KB Output is correct
92 Correct 215 ms 48288 KB Output is correct
93 Correct 209 ms 48316 KB Output is correct
94 Correct 198 ms 45892 KB Output is correct
95 Correct 190 ms 45860 KB Output is correct
96 Correct 7 ms 14292 KB Output is correct
97 Runtime error 23 ms 31672 KB Execution killed with signal 6
98 Halted 0 ms 0 KB -