Submission #404883

# Submission time Handle Problem Language Result Execution time Memory
404883 2021-05-15T08:37:15 Z Joshc Tropical Garden (IOI11_garden) C++11
100 / 100
192 ms 61980 KB
#include "garden.h"
#include "gardenlib.h"
#include <algorithm>
#include <vector>
using namespace std;

const int INF = 2000000000;

vector<int> edges[150001], edges2[300001], num[300001], num2[300001]; 
int dist[300001], dist2[300001], m[300001], m2[300001], x = 0, y = 0;

void dfs(int v, int p, int cur, int dist[], int& len) {
    dist[v] = cur;
    for (int i : edges2[v]) {
        if (i == p) continue;
        if (dist[i] != INF) len = cur+1;
        else dfs(i, v, cur+1, dist, len);
    }
}

void count_routes(int n, int z, int p, int r[][2], int q, int g[]) {
    for (int i=0; i<z; i++) {
        edges[r[i][0]].push_back(r[i][1]);
        edges[r[i][1]].push_back(r[i][0]);
    }
    for (int i=0; i<n; i++) {
        edges2[edges[i][0]*2 + (i == edges[edges[i][0]][0])].push_back(i*2);
        if (edges[i].size() == 1) edges2[edges[i][0]*2 + (i == edges[edges[i][0]][0])].push_back(i*2+1);
        else edges2[edges[i][1]*2 + (i == edges[edges[i][1]][0])].push_back(i*2+1);
    }
    fill(&dist[0], &dist[300001], INF);
    fill(&dist2[0], &dist2[300001], INF);
    dfs(p*2, p*2, 0, dist, x);
    dfs(p*2+1, p*2+1, 0, dist2, y);
    for (int i=0; i<2*n; i+=2) {
        if (dist[i] != INF) {
            m[dist[i]]++;
            if (x) num[dist[i]%x].push_back(dist[i]);
        }
        if (dist2[i] != INF) {
            m2[dist2[i]]++;
            if (y) num2[dist2[i]%y].push_back(dist2[i]); 
        }
    }
    for (int i=0; i<2*n; i++) {
        sort(num[i].begin(), num[i].end());
        sort(num2[i].begin(), num2[i].end());
    }
    for (int i=0; i<q; i++) {
        int a = g[i];
        int cur = x ? upper_bound(num[a%x].begin(), num[a%x].end(), a)-num[a%x].begin() : (a < 2*n ? m[a] : 0);
        int cur2 = y ? upper_bound(num2[a%y].begin(), num2[a%y].end(), a)-num2[a%y].begin() : (a < 2*n ? m2[a] : 0);
        answer(cur+cur2);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27468 KB Output is correct
2 Correct 18 ms 27344 KB Output is correct
3 Correct 16 ms 27376 KB Output is correct
4 Correct 15 ms 27300 KB Output is correct
5 Correct 15 ms 27212 KB Output is correct
6 Correct 18 ms 27612 KB Output is correct
7 Correct 16 ms 27264 KB Output is correct
8 Correct 18 ms 27384 KB Output is correct
9 Correct 19 ms 27596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27468 KB Output is correct
2 Correct 18 ms 27344 KB Output is correct
3 Correct 16 ms 27376 KB Output is correct
4 Correct 15 ms 27300 KB Output is correct
5 Correct 15 ms 27212 KB Output is correct
6 Correct 18 ms 27612 KB Output is correct
7 Correct 16 ms 27264 KB Output is correct
8 Correct 18 ms 27384 KB Output is correct
9 Correct 19 ms 27596 KB Output is correct
10 Correct 15 ms 27260 KB Output is correct
11 Correct 27 ms 29440 KB Output is correct
12 Correct 45 ms 30916 KB Output is correct
13 Correct 77 ms 56168 KB Output is correct
14 Correct 145 ms 39192 KB Output is correct
15 Correct 183 ms 39992 KB Output is correct
16 Correct 134 ms 37240 KB Output is correct
17 Correct 116 ms 35940 KB Output is correct
18 Correct 43 ms 30916 KB Output is correct
19 Correct 190 ms 39108 KB Output is correct
20 Correct 171 ms 40076 KB Output is correct
21 Correct 127 ms 37044 KB Output is correct
22 Correct 130 ms 35952 KB Output is correct
23 Correct 173 ms 40260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27468 KB Output is correct
2 Correct 18 ms 27344 KB Output is correct
3 Correct 16 ms 27376 KB Output is correct
4 Correct 15 ms 27300 KB Output is correct
5 Correct 15 ms 27212 KB Output is correct
6 Correct 18 ms 27612 KB Output is correct
7 Correct 16 ms 27264 KB Output is correct
8 Correct 18 ms 27384 KB Output is correct
9 Correct 19 ms 27596 KB Output is correct
10 Correct 15 ms 27260 KB Output is correct
11 Correct 27 ms 29440 KB Output is correct
12 Correct 45 ms 30916 KB Output is correct
13 Correct 77 ms 56168 KB Output is correct
14 Correct 145 ms 39192 KB Output is correct
15 Correct 183 ms 39992 KB Output is correct
16 Correct 134 ms 37240 KB Output is correct
17 Correct 116 ms 35940 KB Output is correct
18 Correct 43 ms 30916 KB Output is correct
19 Correct 190 ms 39108 KB Output is correct
20 Correct 171 ms 40076 KB Output is correct
21 Correct 127 ms 37044 KB Output is correct
22 Correct 130 ms 35952 KB Output is correct
23 Correct 173 ms 40260 KB Output is correct
24 Correct 16 ms 27276 KB Output is correct
25 Correct 27 ms 29448 KB Output is correct
26 Correct 47 ms 30900 KB Output is correct
27 Correct 81 ms 56304 KB Output is correct
28 Correct 177 ms 39164 KB Output is correct
29 Correct 171 ms 40004 KB Output is correct
30 Correct 142 ms 37312 KB Output is correct
31 Correct 129 ms 35940 KB Output is correct
32 Correct 48 ms 30892 KB Output is correct
33 Correct 152 ms 39152 KB Output is correct
34 Correct 189 ms 40132 KB Output is correct
35 Correct 141 ms 37164 KB Output is correct
36 Correct 121 ms 36028 KB Output is correct
37 Correct 192 ms 40436 KB Output is correct
38 Correct 148 ms 61980 KB Output is correct