Submission #800768

# Submission time Handle Problem Language Result Execution time Memory
800768 2023-08-01T20:10:48 Z finn__ Fountain Parks (IOI21_parks) C++17
45 / 100
110 ms 28024 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;

template <size_t N>
struct dsu
{
    int64_t p[N];

    dsu() { fill(p, p + N, -1); }

    int64_t repr(int64_t u) { return p[u] < 0 ? u : p[u] = repr(p[u]); }

    bool merge(int64_t i, int64_t j)
    {
        i = repr(i);
        j = repr(j);
        if (i == j)
            return 0;

        if (p[i] > p[j])
            swap(i, j);
        p[i] += p[j];
        p[j] = i;
        return 1;
    }

    bool same_set(int64_t i, int64_t j) { return repr(i) == repr(j); }

    int64_t set_size(int64_t i) { return -p[repr(i)]; }

    void reset() { fill(p.begin(), p.end(), -1); }
};

struct fountain
{
    int x, y;
    size_t i;
};

constexpr size_t N = 200000;

fountain f[N];
vector<pair<size_t, size_t>> edges;
dsu<N> d;

int construct_roads(vector<int> x, vector<int> y)
{
    size_t n = x.size();

    for (size_t i = 0; i < x.size(); ++i)
        f[i].i = i, f[i].x = x[i], f[i].y = y[i];
    sort(f, f + n, [](auto const &a, auto const &b)
         { return a.y == b.y ? a.x < b.x : a.y < b.y; });

    for (size_t i = 0; i < n;)
    {
        size_t j = i;
        while (j < n && f[j].y == f[i].y)
            ++j;

        for (size_t k = i + 1; k < j; ++k)
            if (f[k - 1].x + 2 == f[k].x)
                if (d.merge(f[k - 1].i, f[k].i))
                    edges.emplace_back(f[k - 1].i, f[k].i);

        if (f[j].y == f[i].y + 2)
        {
            size_t k = j;
            while (i < j && k < n && f[k].y == f[j].y)
            {
                if (f[i].x < f[k].x)
                    ++i;
                else if (f[k].x < f[i].x)
                    ++k;
                else
                {
                    if (d.merge(f[i].i, f[k].i))
                        edges.emplace_back(f[k].i, f[i].i);
                    ++i;
                    ++k;
                }
            }
        }

        i = j;
    }

    if (d.set_size(0) != n)
        return 0;
    vector<int> u, v, a, b;
    for (auto const &[i, j] : edges)
    {
        u.push_back(i);
        v.push_back(j);
        if (x[i] == x[j])
        {
            b.push_back((y[i] + y[j]) >> 1);
            if (((x[i] & 3) == 2) ^ ((min(y[i], y[j]) & 3) == 2))
                a.push_back(x[i] - 1);
            else
                a.push_back(x[i] + 1);
        }
        else
        {
            a.push_back((x[i] + x[j]) >> 1);
            if (((y[i] & 3) == 2) ^ ((min(x[i], x[j]) & 3) == 2))
                b.push_back(y[i] + 1);
            else
                b.push_back(y[i] - 1);
        }
    }

    build(u, v, a, b);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:89:23: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     if (d.set_size(0) != n)
      |         ~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1872 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 49 ms 13616 KB Output is correct
10 Correct 5 ms 3152 KB Output is correct
11 Correct 25 ms 8088 KB Output is correct
12 Correct 9 ms 3664 KB Output is correct
13 Correct 8 ms 4684 KB Output is correct
14 Correct 2 ms 1880 KB Output is correct
15 Correct 2 ms 2004 KB Output is correct
16 Correct 51 ms 13636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1872 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 49 ms 13616 KB Output is correct
10 Correct 5 ms 3152 KB Output is correct
11 Correct 25 ms 8088 KB Output is correct
12 Correct 9 ms 3664 KB Output is correct
13 Correct 8 ms 4684 KB Output is correct
14 Correct 2 ms 1880 KB Output is correct
15 Correct 2 ms 2004 KB Output is correct
16 Correct 51 ms 13636 KB Output is correct
17 Incorrect 1 ms 1748 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1872 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 49 ms 13616 KB Output is correct
10 Correct 5 ms 3152 KB Output is correct
11 Correct 25 ms 8088 KB Output is correct
12 Correct 9 ms 3664 KB Output is correct
13 Correct 8 ms 4684 KB Output is correct
14 Correct 2 ms 1880 KB Output is correct
15 Correct 2 ms 2004 KB Output is correct
16 Correct 51 ms 13636 KB Output is correct
17 Incorrect 1 ms 1748 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1872 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 49 ms 13616 KB Output is correct
10 Correct 5 ms 3152 KB Output is correct
11 Correct 25 ms 8088 KB Output is correct
12 Correct 9 ms 3664 KB Output is correct
13 Correct 8 ms 4684 KB Output is correct
14 Correct 2 ms 1880 KB Output is correct
15 Correct 2 ms 2004 KB Output is correct
16 Correct 51 ms 13636 KB Output is correct
17 Correct 1 ms 1872 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 107 ms 27432 KB Output is correct
21 Correct 104 ms 27044 KB Output is correct
22 Correct 104 ms 27036 KB Output is correct
23 Correct 89 ms 23256 KB Output is correct
24 Correct 46 ms 9816 KB Output is correct
25 Correct 48 ms 13904 KB Output is correct
26 Correct 47 ms 13908 KB Output is correct
27 Correct 102 ms 26040 KB Output is correct
28 Correct 100 ms 25648 KB Output is correct
29 Correct 99 ms 25620 KB Output is correct
30 Correct 100 ms 25640 KB Output is correct
31 Correct 1 ms 1876 KB Output is correct
32 Correct 8 ms 3644 KB Output is correct
33 Correct 23 ms 6236 KB Output is correct
34 Correct 104 ms 27536 KB Output is correct
35 Correct 4 ms 2644 KB Output is correct
36 Correct 13 ms 5196 KB Output is correct
37 Correct 28 ms 8396 KB Output is correct
38 Correct 44 ms 12392 KB Output is correct
39 Correct 61 ms 15680 KB Output is correct
40 Correct 76 ms 20740 KB Output is correct
41 Correct 94 ms 23932 KB Output is correct
42 Correct 110 ms 28024 KB Output is correct
43 Correct 1 ms 1748 KB Output is correct
44 Correct 2 ms 1868 KB Output is correct
45 Correct 1 ms 1876 KB Output is correct
46 Correct 1 ms 1876 KB Output is correct
47 Correct 1 ms 1876 KB Output is correct
48 Correct 1 ms 1876 KB Output is correct
49 Correct 1 ms 1876 KB Output is correct
50 Correct 1 ms 1868 KB Output is correct
51 Correct 1 ms 1876 KB Output is correct
52 Correct 1 ms 1864 KB Output is correct
53 Correct 1 ms 1876 KB Output is correct
54 Correct 1 ms 2016 KB Output is correct
55 Correct 2 ms 2004 KB Output is correct
56 Correct 49 ms 13736 KB Output is correct
57 Correct 81 ms 19940 KB Output is correct
58 Correct 73 ms 19912 KB Output is correct
59 Correct 1 ms 1876 KB Output is correct
60 Correct 1 ms 1872 KB Output is correct
61 Correct 1 ms 1868 KB Output is correct
62 Correct 100 ms 25788 KB Output is correct
63 Correct 100 ms 25776 KB Output is correct
64 Correct 98 ms 25636 KB Output is correct
65 Correct 2 ms 2140 KB Output is correct
66 Correct 3 ms 2384 KB Output is correct
67 Correct 49 ms 13560 KB Output is correct
68 Correct 76 ms 20412 KB Output is correct
69 Correct 100 ms 25768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1872 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 49 ms 13616 KB Output is correct
10 Correct 5 ms 3152 KB Output is correct
11 Correct 25 ms 8088 KB Output is correct
12 Correct 9 ms 3664 KB Output is correct
13 Correct 8 ms 4684 KB Output is correct
14 Correct 2 ms 1880 KB Output is correct
15 Correct 2 ms 2004 KB Output is correct
16 Correct 51 ms 13636 KB Output is correct
17 Correct 103 ms 26552 KB Output is correct
18 Correct 107 ms 26792 KB Output is correct
19 Correct 104 ms 27056 KB Output is correct
20 Correct 102 ms 25112 KB Output is correct
21 Correct 88 ms 22820 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 17 ms 6044 KB Output is correct
24 Correct 6 ms 3280 KB Output is correct
25 Correct 19 ms 7140 KB Output is correct
26 Correct 31 ms 9284 KB Output is correct
27 Correct 53 ms 14588 KB Output is correct
28 Correct 67 ms 17640 KB Output is correct
29 Correct 82 ms 22056 KB Output is correct
30 Correct 95 ms 24304 KB Output is correct
31 Correct 109 ms 27580 KB Output is correct
32 Correct 100 ms 25656 KB Output is correct
33 Correct 99 ms 25764 KB Output is correct
34 Correct 2 ms 2260 KB Output is correct
35 Correct 3 ms 2516 KB Output is correct
36 Correct 49 ms 13740 KB Output is correct
37 Correct 75 ms 20520 KB Output is correct
38 Correct 100 ms 25728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1872 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 49 ms 13616 KB Output is correct
10 Correct 5 ms 3152 KB Output is correct
11 Correct 25 ms 8088 KB Output is correct
12 Correct 9 ms 3664 KB Output is correct
13 Correct 8 ms 4684 KB Output is correct
14 Correct 2 ms 1880 KB Output is correct
15 Correct 2 ms 2004 KB Output is correct
16 Correct 51 ms 13636 KB Output is correct
17 Incorrect 1 ms 1748 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -