답안 #1068752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1068752 2024-08-21T11:49:52 Z Boas 분수 공원 (IOI21_parks) C++17
5 / 100
314 ms 120856 KB
#include "parks.h"

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef vector<signed> vi32;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef unordered_set<ll> si;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
// typedef unordered_set<iii> siii;
// typedef unordered_set<ii> sii;
typedef vector<vii> vvii;
#define pb push_back
#define loop(x, i) for (int i = 0; i < x; i++)
#define ALL(x) begin(x), end(x)
#define sz(x) (int)x.size()

vii adj = {{-2, 0}, {2, 0}, {0, 2}, {0, -2}};

si benchPoints; // neighbour count

ll MX = 200'002;

ll toInt(iii p)
{
    auto [a, b, c] = p;
    return MX * MX * 4 * a + MX * b + c;
}
ll toInt(ii p)
{
    auto [b, c] = p;
    return MX * b + c;
}

void addNeighbour(ll x, ll y, int dif = 1)
{
    if (benchPoints.count(toInt({1, x, y})))
    {
        benchPoints.erase(toInt({1, x, y}));
        if (dif == 1)
        {
            benchPoints.insert(toInt({2, x, y}));
        }
    }
    else if (benchPoints.count(toInt({2, x, y})))
    {
        benchPoints.erase(toInt({2, x, y}));
        benchPoints.insert(toInt({2 + dif, x, y}));
    }
    else if (benchPoints.count(toInt({3, x, y})))
    {
        benchPoints.erase(toInt({3, x, y}));
        if (dif == 1)
            throw;
        benchPoints.insert(toInt({2, x, y}));
    }
    else if (dif == 1)
    {
        benchPoints.insert(toInt({1, x, y}));
    }
}

int construct_roads(vi xs, vi ys)
{
    unordered_map<ll, int> fountains;
    unordered_map<ll, int> roads;
    // unordered_set<ii> gotBench;
    int n = sz(xs);
    loop(n, i)
    {
        fountains[toInt({xs[i], ys[i]})] = i;
    }
    vb vis(n);
    vi u, v, a, b;
    a = b = vi(n - 1);
    int visCnt = 1;
    auto dfs = [&](auto &&self, int i) -> void
    {
        int x = xs[i], y = ys[i];
        for (const auto &[dx, dy] : adj)
        {
            ii pos = {x + dx, y + dy};
            if (fountains.count(toInt(pos)))
            {
                int j = fountains[toInt(pos)];
                if (vis[j])
                    continue;
                if (dx != 0)
                {
                    roads[toInt({x + dx / 2, y})] = sz(u);
                    addNeighbour(x + dx / 2, y + 1);
                    addNeighbour(x + dx / 2, y - 1);
                }
                else
                {
                    roads[toInt({x, y + dy / 2})] = sz(u);
                    addNeighbour(x + 1, y + dy / 2);
                    addNeighbour(x - 1, y + dy / 2);
                }
                u.pb(i);
                v.pb(j);
                vis[j] = 1;
                visCnt++;
                self(self, j);
            }
        }
    };
    vis[0] = 1;
    dfs(dfs, 0);
    if (visCnt != n)
        return 0;
    for (int benchesBuilt = 0; benchesBuilt < n - 1; benchesBuilt++)
    {
        auto tupl = *benchPoints.begin();
        ll x = (tupl % (MX * MX * 4LL)) / MX, y = tupl % MX;
        benchPoints.erase(benchPoints.begin());
        ii loc;
        if (roads.count(toInt({x + 1, y})))
        {
            loc = {x + 1, y};
            addNeighbour(x + 2, y, -1);
        }
        else if (roads.count(toInt({x - 1, y})))
        {
            loc = {x - 1, y};
            addNeighbour(x - 2, y, -1);
        }
        else if (roads.count(toInt({x, y + 1})))
        {
            loc = {x, y + 1};
            addNeighbour(x, y + 2, -1);
        }
        else
        {
            loc = {x, y - 1};
            addNeighbour(x, y - 2, -1);
        }
        int ix = roads[toInt(loc)];
        roads.erase(toInt(loc));
        a[ix] = x;
        b[ix] = y;
    }
    build(u, v, a, b);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 93 ms 32880 KB Output is correct
10 Correct 8 ms 3672 KB Output is correct
11 Correct 40 ms 18128 KB Output is correct
12 Correct 10 ms 5304 KB Output is correct
13 Correct 18 ms 11364 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 87 ms 28100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 93 ms 32880 KB Output is correct
10 Correct 8 ms 3672 KB Output is correct
11 Correct 40 ms 18128 KB Output is correct
12 Correct 10 ms 5304 KB Output is correct
13 Correct 18 ms 11364 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 87 ms 28100 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Runtime error 0 ms 348 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 93 ms 32880 KB Output is correct
10 Correct 8 ms 3672 KB Output is correct
11 Correct 40 ms 18128 KB Output is correct
12 Correct 10 ms 5304 KB Output is correct
13 Correct 18 ms 11364 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 87 ms 28100 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Runtime error 0 ms 348 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 93 ms 32880 KB Output is correct
10 Correct 8 ms 3672 KB Output is correct
11 Correct 40 ms 18128 KB Output is correct
12 Correct 10 ms 5304 KB Output is correct
13 Correct 18 ms 11364 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 87 ms 28100 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Runtime error 240 ms 119640 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 93 ms 32880 KB Output is correct
10 Correct 8 ms 3672 KB Output is correct
11 Correct 40 ms 18128 KB Output is correct
12 Correct 10 ms 5304 KB Output is correct
13 Correct 18 ms 11364 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 87 ms 28100 KB Output is correct
17 Correct 288 ms 67784 KB Output is correct
18 Correct 314 ms 65352 KB Output is correct
19 Runtime error 257 ms 120856 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 93 ms 32880 KB Output is correct
10 Correct 8 ms 3672 KB Output is correct
11 Correct 40 ms 18128 KB Output is correct
12 Correct 10 ms 5304 KB Output is correct
13 Correct 18 ms 11364 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 87 ms 28100 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Runtime error 0 ms 348 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -