Submission #598188

# Submission time Handle Problem Language Result Execution time Memory
598188 2022-07-17T19:03:35 Z snasibov05 Tropical Garden (IOI11_garden) C++14
100 / 100
2519 ms 42108 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>

using namespace std;

void dfs(int cur, int t, vector<int>& d, int& c, vector<vector<int>>& ed){
    for (auto to : ed[cur]){
        if (to == t) {
            c = d[cur] + 1;
            continue;
        }
        d[to] = d[cur] + 1;
        dfs(to, t, d, c, ed);
    }
}

void count_routes(int n, int m, int p, int r[][2], int q, int g[]){

    vector<vector<int>> ed(n, vector<int>(2, -1));
    for (int i = 0; i < m; ++i) {
        if (ed[r[i][0]][0] == -1) ed[r[i][0]][0] = r[i][1];
        else if (ed[r[i][0]][1] == -1) ed[r[i][0]][1] = r[i][1];

        if (ed[r[i][1]][0] == -1) ed[r[i][1]][0] = r[i][0];
        else if (ed[r[i][1]][1] == -1) ed[r[i][1]][1] = r[i][0];
    }

    for (int i = 0; i < n; ++i) {
        if (ed[i][1] == -1) ed[i][1] = ed[i][0];
    }

    vector<vector<int>> gg(2*n);
    for (int i = 0; i < n; ++i){
        int t1 = ed[i][0];
        if (ed[t1][0] == i) gg[t1 + n].push_back(i);
        else gg[t1].push_back(i);

        int t2 = ed[i][1];
        if (ed[t2][0] == i) gg[t2 + n].push_back(i + n);
        else gg[t2].push_back(i + n);
    }

    vector<int> d1(2*n, 2*n + 5); d1[p] = 0;
    vector<int> d2(2*n, 2*n + 5); d2[p + n] = 0;
    int c1 = 2*n + 5, c2 = 2*n + 5;
    dfs(p, p, d1, c1, gg);
    dfs(p + n, p + n, d2, c2, gg);

    for (int i = 0; i < q; ++i){
        int res = 0;
        for (int j = 0; j < n; ++j){
            if (d1[j] == g[i] || (c1 <= 2*n && g[i] - d1[j] > 0 && d1[j] <= 2*n && (g[i] - d1[j]) % c1 == 0)) res++;
            else if (d2[j] == g[i] || (c2 <= 2*n && g[i] - d2[j] > 0 && d2[j] <= 2*n && (g[i] - d2[j]) % c2 == 0)) res++;
        }
        answer(res);
    }
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 9 ms 4168 KB Output is correct
12 Correct 20 ms 6484 KB Output is correct
13 Correct 46 ms 29644 KB Output is correct
14 Correct 92 ms 21732 KB Output is correct
15 Correct 106 ms 22104 KB Output is correct
16 Correct 76 ms 15752 KB Output is correct
17 Correct 80 ms 13136 KB Output is correct
18 Correct 26 ms 6484 KB Output is correct
19 Correct 86 ms 21788 KB Output is correct
20 Correct 110 ms 22044 KB Output is correct
21 Correct 82 ms 15480 KB Output is correct
22 Correct 94 ms 13136 KB Output is correct
23 Correct 93 ms 24104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 9 ms 4168 KB Output is correct
12 Correct 20 ms 6484 KB Output is correct
13 Correct 46 ms 29644 KB Output is correct
14 Correct 92 ms 21732 KB Output is correct
15 Correct 106 ms 22104 KB Output is correct
16 Correct 76 ms 15752 KB Output is correct
17 Correct 80 ms 13136 KB Output is correct
18 Correct 26 ms 6484 KB Output is correct
19 Correct 86 ms 21788 KB Output is correct
20 Correct 110 ms 22044 KB Output is correct
21 Correct 82 ms 15480 KB Output is correct
22 Correct 94 ms 13136 KB Output is correct
23 Correct 93 ms 24104 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 96 ms 4456 KB Output is correct
26 Correct 151 ms 7116 KB Output is correct
27 Correct 2226 ms 30672 KB Output is correct
28 Correct 1029 ms 23540 KB Output is correct
29 Correct 2519 ms 24076 KB Output is correct
30 Correct 1386 ms 17412 KB Output is correct
31 Correct 1400 ms 14928 KB Output is correct
32 Correct 134 ms 7136 KB Output is correct
33 Correct 981 ms 23536 KB Output is correct
34 Correct 2498 ms 23996 KB Output is correct
35 Correct 1503 ms 17228 KB Output is correct
36 Correct 1432 ms 14852 KB Output is correct
37 Correct 745 ms 25912 KB Output is correct
38 Correct 1875 ms 42108 KB Output is correct