Submission #553353

# Submission time Handle Problem Language Result Execution time Memory
553353 2022-04-25T14:39:35 Z timreizin Tropical Garden (IOI11_garden) C++17
100 / 100
2523 ms 13300 KB
#include "garden.h"
#include "gardenlib.h"
#include <vector>

using namespace std;

void count_routes(int n, int m, int p, int R[][2], int q, int G[])
{
    vector<int> adj(2 * n, -1), best(n, -1);
    for (int i = 0; i < m; ++i)
    {
        auto [u, v] = R[i];
        if (best[u] == -1) best[u] = v;
        if (adj[2 * u] == -1) adj[2 * u] = v;
        else if (adj[2 * u + 1] == -1) adj[2 * u + 1] = v;
        swap(u, v);
        if (best[u] == -1) best[u] = v;
        if (adj[2 * u] == -1) adj[2 * u] = v;
        else if (adj[2 * u + 1] == -1) adj[2 * u + 1] = v;
    }
    for (int i = 0; i < n; ++i)
    {
        if (adj[2 * i + 1] == -1) adj[2 * i + 1] = adj[2 * i];
        adj[2 * i] *= 2;
        adj[2 * i + 1] *= 2;
        if (best[adj[2 * i] / 2] == i) ++adj[2 * i];
        if (best[adj[2 * i + 1] / 2] == i) ++adj[2 * i + 1];
    }
    vector<int> d(2 * n, -1);
    auto dfs = [&d, &adj](auto self, int v) -> int
    {
        if (d[v] == -2) return -3;
        if (d[v] != -1) return d[v];
        d[v] = -2;
        d[v] = self(self, adj[v]) + 1;
        if (d[v] == -2) return -3;
        return d[v];
    };
    vector<int> result(q);
    //2 * p
    d[2 * p] = 0;
    for (int i = 0; i < 2 * n; ++i) if (d[i] == -1) dfs(dfs, i);
    int len = 0;
    if (d[adj[2 * p]] > 0) len = d[adj[2 * p]] + 1;
    for (int i = 0; i < q; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (d[2 * j] >= 0 && G[i] >= d[2 * j])
            {
                if (len) result[i] += (G[i] - d[2 * j]) % len == 0;
                else result[i] += G[i] == d[2 * j];
            }
        }
    }
    //2 * p + 1
    d = vector<int>(2 * n, -1);
    d[2 * p + 1] = 0;
    for (int i = 0; i < 2 * n; ++i) if (d[i] == -1) dfs(dfs, i);
    len = 0;
    if (d[adj[2 * p + 1]] > 0) len = d[adj[2 * p + 1]] + 1;
    for (int i = 0; i < q; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (d[2 * j] >= 0 && G[i] >= d[2 * j])
            {
                if (len) result[i] += (G[i] - d[2 * j]) % len == 0;
                else result[i] += G[i] == d[2 * j];
            }
        }
    }
    for (int i : result) answer(i);
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 444 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 8 ms 1508 KB Output is correct
12 Correct 14 ms 2480 KB Output is correct
13 Correct 27 ms 10856 KB Output is correct
14 Correct 37 ms 6664 KB Output is correct
15 Correct 42 ms 6892 KB Output is correct
16 Correct 34 ms 5536 KB Output is correct
17 Correct 33 ms 4916 KB Output is correct
18 Correct 13 ms 2280 KB Output is correct
19 Correct 38 ms 6732 KB Output is correct
20 Correct 39 ms 6892 KB Output is correct
21 Correct 34 ms 5448 KB Output is correct
22 Correct 35 ms 4940 KB Output is correct
23 Correct 40 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 444 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 8 ms 1508 KB Output is correct
12 Correct 14 ms 2480 KB Output is correct
13 Correct 27 ms 10856 KB Output is correct
14 Correct 37 ms 6664 KB Output is correct
15 Correct 42 ms 6892 KB Output is correct
16 Correct 34 ms 5536 KB Output is correct
17 Correct 33 ms 4916 KB Output is correct
18 Correct 13 ms 2280 KB Output is correct
19 Correct 38 ms 6732 KB Output is correct
20 Correct 39 ms 6892 KB Output is correct
21 Correct 34 ms 5448 KB Output is correct
22 Correct 35 ms 4940 KB Output is correct
23 Correct 40 ms 7516 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 74 ms 1504 KB Output is correct
26 Correct 90 ms 2532 KB Output is correct
27 Correct 2207 ms 11020 KB Output is correct
28 Correct 700 ms 6784 KB Output is correct
29 Correct 2523 ms 6988 KB Output is correct
30 Correct 1419 ms 5504 KB Output is correct
31 Correct 1452 ms 4960 KB Output is correct
32 Correct 146 ms 2332 KB Output is correct
33 Correct 699 ms 6784 KB Output is correct
34 Correct 2462 ms 6988 KB Output is correct
35 Correct 1512 ms 5424 KB Output is correct
36 Correct 1911 ms 4960 KB Output is correct
37 Correct 526 ms 7560 KB Output is correct
38 Correct 2331 ms 13300 KB Output is correct