Submission #760846

# Submission time Handle Problem Language Result Execution time Memory
760846 2023-06-18T17:04:35 Z caganyanmaz Fountain Parks (IOI21_parks) C++17
30 / 100
293 ms 59296 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];

vector<int> uu, vv, aa, bb;
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;
                                array<int, 2> pos = {x+2, -1};
                                if (fountains.find({fx, fy}) != fountains.end() || (fountains.find({fx+2, fy}) == fountains.end() && (*lower_bound(rows[y+2].begin(), rows[y+2].end(), pos))[0] != x+2))
                                        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:32: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]
   32 |                 for (int i = 1; i < rows[y].size(); i++)
      |                                 ~~^~~~~~~~~~~~~~~~
parks.cpp: In function 'void configure_horizontal_connections()':
parks.cpp:61: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]
   61 |                 while (i < intervals[y].size() && j < intervals[y-2].size())
      |                        ~~^~~~~~~~~~~~~~~~~~~~~
parks.cpp:61: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]
   61 |                 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:138:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |         if (node_sum < x.size())
      |             ~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14292 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 7 ms 14292 KB Output is correct
4 Correct 7 ms 14292 KB Output is correct
5 Correct 7 ms 14292 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14304 KB Output is correct
8 Correct 7 ms 14364 KB Output is correct
9 Correct 118 ms 39080 KB Output is correct
10 Correct 16 ms 16980 KB Output is correct
11 Correct 56 ms 27800 KB Output is correct
12 Correct 20 ms 18388 KB Output is correct
13 Correct 21 ms 20636 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 8 ms 14548 KB Output is correct
16 Correct 117 ms 37128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14292 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 7 ms 14292 KB Output is correct
4 Correct 7 ms 14292 KB Output is correct
5 Correct 7 ms 14292 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14304 KB Output is correct
8 Correct 7 ms 14364 KB Output is correct
9 Correct 118 ms 39080 KB Output is correct
10 Correct 16 ms 16980 KB Output is correct
11 Correct 56 ms 27800 KB Output is correct
12 Correct 20 ms 18388 KB Output is correct
13 Correct 21 ms 20636 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 8 ms 14548 KB Output is correct
16 Correct 117 ms 37128 KB Output is correct
17 Correct 9 ms 14292 KB Output is correct
18 Correct 7 ms 14292 KB Output is correct
19 Correct 7 ms 14292 KB Output is correct
20 Correct 7 ms 14292 KB Output is correct
21 Correct 7 ms 14320 KB Output is correct
22 Correct 7 ms 14292 KB Output is correct
23 Correct 244 ms 53028 KB Output is correct
24 Correct 7 ms 14292 KB Output is correct
25 Correct 8 ms 14548 KB Output is correct
26 Correct 8 ms 14548 KB Output is correct
27 Correct 8 ms 14696 KB Output is correct
28 Correct 88 ms 29960 KB Output is correct
29 Correct 144 ms 37168 KB Output is correct
30 Correct 195 ms 45472 KB Output is correct
31 Correct 243 ms 52512 KB Output is correct
32 Correct 7 ms 14292 KB Output is correct
33 Correct 7 ms 14292 KB Output is correct
34 Correct 7 ms 14292 KB Output is correct
35 Correct 7 ms 14348 KB Output is correct
36 Correct 7 ms 14292 KB Output is correct
37 Correct 7 ms 14280 KB Output is correct
38 Correct 7 ms 14340 KB Output is correct
39 Correct 7 ms 14292 KB Output is correct
40 Correct 7 ms 14292 KB Output is correct
41 Correct 7 ms 14292 KB Output is correct
42 Correct 7 ms 14292 KB Output is correct
43 Correct 7 ms 14548 KB Output is correct
44 Correct 8 ms 14628 KB Output is correct
45 Correct 123 ms 35676 KB Output is correct
46 Correct 179 ms 45572 KB Output is correct
47 Correct 175 ms 45216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14292 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 7 ms 14292 KB Output is correct
4 Correct 7 ms 14292 KB Output is correct
5 Correct 7 ms 14292 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14304 KB Output is correct
8 Correct 7 ms 14364 KB Output is correct
9 Correct 118 ms 39080 KB Output is correct
10 Correct 16 ms 16980 KB Output is correct
11 Correct 56 ms 27800 KB Output is correct
12 Correct 20 ms 18388 KB Output is correct
13 Correct 21 ms 20636 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 8 ms 14548 KB Output is correct
16 Correct 117 ms 37128 KB Output is correct
17 Correct 9 ms 14292 KB Output is correct
18 Correct 7 ms 14292 KB Output is correct
19 Correct 7 ms 14292 KB Output is correct
20 Correct 7 ms 14292 KB Output is correct
21 Correct 7 ms 14320 KB Output is correct
22 Correct 7 ms 14292 KB Output is correct
23 Correct 244 ms 53028 KB Output is correct
24 Correct 7 ms 14292 KB Output is correct
25 Correct 8 ms 14548 KB Output is correct
26 Correct 8 ms 14548 KB Output is correct
27 Correct 8 ms 14696 KB Output is correct
28 Correct 88 ms 29960 KB Output is correct
29 Correct 144 ms 37168 KB Output is correct
30 Correct 195 ms 45472 KB Output is correct
31 Correct 243 ms 52512 KB Output is correct
32 Correct 7 ms 14292 KB Output is correct
33 Correct 7 ms 14292 KB Output is correct
34 Correct 7 ms 14292 KB Output is correct
35 Correct 7 ms 14348 KB Output is correct
36 Correct 7 ms 14292 KB Output is correct
37 Correct 7 ms 14280 KB Output is correct
38 Correct 7 ms 14340 KB Output is correct
39 Correct 7 ms 14292 KB Output is correct
40 Correct 7 ms 14292 KB Output is correct
41 Correct 7 ms 14292 KB Output is correct
42 Correct 7 ms 14292 KB Output is correct
43 Correct 7 ms 14548 KB Output is correct
44 Correct 8 ms 14628 KB Output is correct
45 Correct 123 ms 35676 KB Output is correct
46 Correct 179 ms 45572 KB Output is correct
47 Correct 175 ms 45216 KB Output is correct
48 Correct 7 ms 14292 KB Output is correct
49 Correct 8 ms 14292 KB Output is correct
50 Correct 7 ms 14348 KB Output is correct
51 Correct 7 ms 14292 KB Output is correct
52 Correct 7 ms 14292 KB Output is correct
53 Correct 7 ms 14292 KB Output is correct
54 Correct 7 ms 14292 KB Output is correct
55 Correct 234 ms 50248 KB Output is correct
56 Correct 7 ms 14352 KB Output is correct
57 Correct 9 ms 14672 KB Output is correct
58 Correct 12 ms 15588 KB Output is correct
59 Correct 9 ms 15060 KB Output is correct
60 Correct 105 ms 32652 KB Output is correct
61 Correct 145 ms 38992 KB Output is correct
62 Correct 199 ms 44060 KB Output is correct
63 Correct 234 ms 50208 KB Output is correct
64 Correct 7 ms 14292 KB Output is correct
65 Correct 7 ms 14292 KB Output is correct
66 Correct 7 ms 14292 KB Output is correct
67 Correct 248 ms 55456 KB Output is correct
68 Correct 245 ms 55600 KB Output is correct
69 Correct 244 ms 56480 KB Output is correct
70 Correct 8 ms 14732 KB Output is correct
71 Correct 10 ms 14992 KB Output is correct
72 Correct 112 ms 33252 KB Output is correct
73 Correct 179 ms 43888 KB Output is correct
74 Correct 248 ms 52240 KB Output is correct
75 Correct 293 ms 59296 KB Output is correct
76 Correct 242 ms 58168 KB Output is correct
77 Correct 9 ms 14804 KB Output is correct
78 Correct 10 ms 15188 KB Output is correct
79 Correct 119 ms 35004 KB Output is correct
80 Correct 186 ms 45624 KB Output is correct
81 Correct 278 ms 56248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14292 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 7 ms 14292 KB Output is correct
4 Correct 7 ms 14292 KB Output is correct
5 Correct 7 ms 14292 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14304 KB Output is correct
8 Correct 7 ms 14364 KB Output is correct
9 Correct 118 ms 39080 KB Output is correct
10 Correct 16 ms 16980 KB Output is correct
11 Correct 56 ms 27800 KB Output is correct
12 Correct 20 ms 18388 KB Output is correct
13 Correct 21 ms 20636 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 8 ms 14548 KB Output is correct
16 Correct 117 ms 37128 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 14292 KB Output is correct
20 Correct 258 ms 58060 KB Output is correct
21 Correct 235 ms 54016 KB Output is correct
22 Correct 254 ms 52952 KB Output is correct
23 Correct 183 ms 45848 KB Output is correct
24 Correct 46 ms 21724 KB Output is correct
25 Correct 63 ms 25824 KB Output is correct
26 Correct 80 ms 27772 KB Output is correct
27 Correct 241 ms 46724 KB Output is correct
28 Correct 242 ms 46608 KB Output is correct
29 Correct 193 ms 44256 KB Output is correct
30 Correct 191 ms 44236 KB Output is correct
31 Correct 7 ms 14292 KB Output is correct
32 Runtime error 26 ms 32084 KB Execution killed with signal 6
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14292 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 7 ms 14292 KB Output is correct
4 Correct 7 ms 14292 KB Output is correct
5 Correct 7 ms 14292 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14304 KB Output is correct
8 Correct 7 ms 14364 KB Output is correct
9 Correct 118 ms 39080 KB Output is correct
10 Correct 16 ms 16980 KB Output is correct
11 Correct 56 ms 27800 KB Output is correct
12 Correct 20 ms 18388 KB Output is correct
13 Correct 21 ms 20636 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 8 ms 14548 KB Output is correct
16 Correct 117 ms 37128 KB Output is correct
17 Correct 230 ms 55932 KB Output is correct
18 Correct 219 ms 54972 KB Output is correct
19 Correct 235 ms 56064 KB Output is correct
20 Correct 263 ms 56992 KB Output is correct
21 Correct 241 ms 49284 KB Output is correct
22 Correct 7 ms 14292 KB Output is correct
23 Runtime error 35 ms 34312 KB Execution killed with signal 6
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14292 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 7 ms 14292 KB Output is correct
4 Correct 7 ms 14292 KB Output is correct
5 Correct 7 ms 14292 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14304 KB Output is correct
8 Correct 7 ms 14364 KB Output is correct
9 Correct 118 ms 39080 KB Output is correct
10 Correct 16 ms 16980 KB Output is correct
11 Correct 56 ms 27800 KB Output is correct
12 Correct 20 ms 18388 KB Output is correct
13 Correct 21 ms 20636 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 8 ms 14548 KB Output is correct
16 Correct 117 ms 37128 KB Output is correct
17 Correct 9 ms 14292 KB Output is correct
18 Correct 7 ms 14292 KB Output is correct
19 Correct 7 ms 14292 KB Output is correct
20 Correct 7 ms 14292 KB Output is correct
21 Correct 7 ms 14320 KB Output is correct
22 Correct 7 ms 14292 KB Output is correct
23 Correct 244 ms 53028 KB Output is correct
24 Correct 7 ms 14292 KB Output is correct
25 Correct 8 ms 14548 KB Output is correct
26 Correct 8 ms 14548 KB Output is correct
27 Correct 8 ms 14696 KB Output is correct
28 Correct 88 ms 29960 KB Output is correct
29 Correct 144 ms 37168 KB Output is correct
30 Correct 195 ms 45472 KB Output is correct
31 Correct 243 ms 52512 KB Output is correct
32 Correct 7 ms 14292 KB Output is correct
33 Correct 7 ms 14292 KB Output is correct
34 Correct 7 ms 14292 KB Output is correct
35 Correct 7 ms 14348 KB Output is correct
36 Correct 7 ms 14292 KB Output is correct
37 Correct 7 ms 14280 KB Output is correct
38 Correct 7 ms 14340 KB Output is correct
39 Correct 7 ms 14292 KB Output is correct
40 Correct 7 ms 14292 KB Output is correct
41 Correct 7 ms 14292 KB Output is correct
42 Correct 7 ms 14292 KB Output is correct
43 Correct 7 ms 14548 KB Output is correct
44 Correct 8 ms 14628 KB Output is correct
45 Correct 123 ms 35676 KB Output is correct
46 Correct 179 ms 45572 KB Output is correct
47 Correct 175 ms 45216 KB Output is correct
48 Correct 7 ms 14292 KB Output is correct
49 Correct 8 ms 14292 KB Output is correct
50 Correct 7 ms 14348 KB Output is correct
51 Correct 7 ms 14292 KB Output is correct
52 Correct 7 ms 14292 KB Output is correct
53 Correct 7 ms 14292 KB Output is correct
54 Correct 7 ms 14292 KB Output is correct
55 Correct 234 ms 50248 KB Output is correct
56 Correct 7 ms 14352 KB Output is correct
57 Correct 9 ms 14672 KB Output is correct
58 Correct 12 ms 15588 KB Output is correct
59 Correct 9 ms 15060 KB Output is correct
60 Correct 105 ms 32652 KB Output is correct
61 Correct 145 ms 38992 KB Output is correct
62 Correct 199 ms 44060 KB Output is correct
63 Correct 234 ms 50208 KB Output is correct
64 Correct 7 ms 14292 KB Output is correct
65 Correct 7 ms 14292 KB Output is correct
66 Correct 7 ms 14292 KB Output is correct
67 Correct 248 ms 55456 KB Output is correct
68 Correct 245 ms 55600 KB Output is correct
69 Correct 244 ms 56480 KB Output is correct
70 Correct 8 ms 14732 KB Output is correct
71 Correct 10 ms 14992 KB Output is correct
72 Correct 112 ms 33252 KB Output is correct
73 Correct 179 ms 43888 KB Output is correct
74 Correct 248 ms 52240 KB Output is correct
75 Correct 293 ms 59296 KB Output is correct
76 Correct 242 ms 58168 KB Output is correct
77 Correct 9 ms 14804 KB Output is correct
78 Correct 10 ms 15188 KB Output is correct
79 Correct 119 ms 35004 KB Output is correct
80 Correct 186 ms 45624 KB Output is correct
81 Correct 278 ms 56248 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 14292 KB Output is correct
85 Correct 258 ms 58060 KB Output is correct
86 Correct 235 ms 54016 KB Output is correct
87 Correct 254 ms 52952 KB Output is correct
88 Correct 183 ms 45848 KB Output is correct
89 Correct 46 ms 21724 KB Output is correct
90 Correct 63 ms 25824 KB Output is correct
91 Correct 80 ms 27772 KB Output is correct
92 Correct 241 ms 46724 KB Output is correct
93 Correct 242 ms 46608 KB Output is correct
94 Correct 193 ms 44256 KB Output is correct
95 Correct 191 ms 44236 KB Output is correct
96 Correct 7 ms 14292 KB Output is correct
97 Runtime error 26 ms 32084 KB Execution killed with signal 6
98 Halted 0 ms 0 KB -