# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
169059 | 2019-12-18T07:04:58 Z | AlexLuchianov | Tropical Garden (IOI11_garden) | C++14 | 2496 ms | 33268 KB |
#include "garden.h" #include "gardenlib.h" #include <vector> #include <queue> #include <iostream> using namespace std; using ll = long long; #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) < (b)) ? (b) : (a)) int const nmax = 300000; int const inf = 1000000000; int f[1 + nmax], scount[1 + nmax]; int dist[1 + nmax], dist2[1 + nmax]; vector<int> graph[1 + nmax]; vector<int> invg[1 + nmax]; void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) { for(int i = 0; i < 2 * N; i++) f[i] = -1; for(int i = 0; i < M; i++){ int x = R[i][0], y = R[i][1]; graph[x].push_back(i); graph[y].push_back(i); } for(int i = 0;i < N; i++){ int e = graph[i][0]; int to = R[e][0] + R[e][1] - i; if(graph[to][0] == e) f[2 * i] = 2 * to + 1; else f[2 * i] = 2 * to; if(2 <= graph[i].size()){ int e = graph[i][1]; int to = R[e][0] + R[e][1] - i; if(graph[to][0] == e) f[2 * i + 1] = 2 * to + 1; else f[2 * i + 1] = 2 * to; } else f[2 * i + 1] = f[2 * i]; } for(int i = 0; i < 2 * N; i++) invg[f[i]].push_back(i); for(int i = 0; i < 2 * N; i++) dist[i] = dist2[i] = inf; queue<int> q; q.push(2 * P); dist[2 * P] = 0; while(0 < q.size()){ int node = q.front(); q.pop(); for(int h = 0; h < invg[node].size(); h++){ int to = invg[node][h]; if(dist[to] == inf){ dist[to] = dist[node] + 1; q.push(to); } } } dist[2 * P] = dist[f[2 * P]] + 1; q.push(2 * P + 1); dist2[2 * P + 1] = 0; while(0 < q.size()){ int node = q.front(); q.pop(); for(int h = 0; h < invg[node].size(); h++){ int to = invg[node][h]; if(dist2[to] == inf){ dist2[to] = dist2[node] + 1; q.push(to); } } } dist2[2 * P + 1] = dist2[f[2 * P + 1]] + 1; for(int i = 0; i < Q; i++){ int k = G[i]; int result = 0; for(int j = 0; j < N; j++){ if(dist[j * 2] <= k && (k - dist[j * 2]) % dist[2 * P] == 0) result++; if(dist2[j * 2] <= k && (k - dist2[j * 2]) % dist2[2 * P + 1] == 0) result++; } answer(result); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 14500 KB | Output is correct |
2 | Correct | 14 ms | 14584 KB | Output is correct |
3 | Correct | 15 ms | 14556 KB | Output is correct |
4 | Correct | 15 ms | 14444 KB | Output is correct |
5 | Correct | 14 ms | 14456 KB | Output is correct |
6 | Correct | 15 ms | 14584 KB | Output is correct |
7 | Correct | 14 ms | 14436 KB | Output is correct |
8 | Correct | 15 ms | 14560 KB | Output is correct |
9 | Correct | 17 ms | 14684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 14500 KB | Output is correct |
2 | Correct | 14 ms | 14584 KB | Output is correct |
3 | Correct | 15 ms | 14556 KB | Output is correct |
4 | Correct | 15 ms | 14444 KB | Output is correct |
5 | Correct | 14 ms | 14456 KB | Output is correct |
6 | Correct | 15 ms | 14584 KB | Output is correct |
7 | Correct | 14 ms | 14436 KB | Output is correct |
8 | Correct | 15 ms | 14560 KB | Output is correct |
9 | Correct | 17 ms | 14684 KB | Output is correct |
10 | Correct | 14 ms | 14456 KB | Output is correct |
11 | Correct | 29 ms | 16748 KB | Output is correct |
12 | Correct | 46 ms | 18388 KB | Output is correct |
13 | Correct | 61 ms | 25088 KB | Output is correct |
14 | Correct | 150 ms | 27736 KB | Output is correct |
15 | Correct | 176 ms | 28020 KB | Output is correct |
16 | Correct | 136 ms | 24172 KB | Output is correct |
17 | Correct | 196 ms | 23076 KB | Output is correct |
18 | Correct | 61 ms | 18396 KB | Output is correct |
19 | Correct | 247 ms | 27604 KB | Output is correct |
20 | Correct | 210 ms | 28028 KB | Output is correct |
21 | Correct | 137 ms | 24192 KB | Output is correct |
22 | Correct | 134 ms | 23048 KB | Output is correct |
23 | Correct | 150 ms | 28992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 14500 KB | Output is correct |
2 | Correct | 14 ms | 14584 KB | Output is correct |
3 | Correct | 15 ms | 14556 KB | Output is correct |
4 | Correct | 15 ms | 14444 KB | Output is correct |
5 | Correct | 14 ms | 14456 KB | Output is correct |
6 | Correct | 15 ms | 14584 KB | Output is correct |
7 | Correct | 14 ms | 14436 KB | Output is correct |
8 | Correct | 15 ms | 14560 KB | Output is correct |
9 | Correct | 17 ms | 14684 KB | Output is correct |
10 | Correct | 14 ms | 14456 KB | Output is correct |
11 | Correct | 29 ms | 16748 KB | Output is correct |
12 | Correct | 46 ms | 18388 KB | Output is correct |
13 | Correct | 61 ms | 25088 KB | Output is correct |
14 | Correct | 150 ms | 27736 KB | Output is correct |
15 | Correct | 176 ms | 28020 KB | Output is correct |
16 | Correct | 136 ms | 24172 KB | Output is correct |
17 | Correct | 196 ms | 23076 KB | Output is correct |
18 | Correct | 61 ms | 18396 KB | Output is correct |
19 | Correct | 247 ms | 27604 KB | Output is correct |
20 | Correct | 210 ms | 28028 KB | Output is correct |
21 | Correct | 137 ms | 24192 KB | Output is correct |
22 | Correct | 134 ms | 23048 KB | Output is correct |
23 | Correct | 150 ms | 28992 KB | Output is correct |
24 | Correct | 15 ms | 14508 KB | Output is correct |
25 | Correct | 129 ms | 16868 KB | Output is correct |
26 | Correct | 183 ms | 18428 KB | Output is correct |
27 | Correct | 1343 ms | 25168 KB | Output is correct |
28 | Correct | 1274 ms | 27744 KB | Output is correct |
29 | Correct | 1528 ms | 28036 KB | Output is correct |
30 | Correct | 1010 ms | 24224 KB | Output is correct |
31 | Correct | 939 ms | 23096 KB | Output is correct |
32 | Correct | 203 ms | 18428 KB | Output is correct |
33 | Correct | 1265 ms | 27736 KB | Output is correct |
34 | Correct | 1457 ms | 28012 KB | Output is correct |
35 | Correct | 1016 ms | 24200 KB | Output is correct |
36 | Correct | 1559 ms | 23084 KB | Output is correct |
37 | Correct | 1018 ms | 29012 KB | Output is correct |
38 | Correct | 2496 ms | 33268 KB | Output is correct |