Submission #439889

# Submission time Handle Problem Language Result Execution time Memory
439889 2021-07-01T05:52:50 Z dutch Tropical Garden (IOI11_garden) C++17
100 / 100
2834 ms 27408 KB
#include <bits/stdc++.h>
using namespace std;
#include "garden.h"
#include "gardenlib.h"
 
const int LIM = 1.5e5, INF = 2e9;
 
int n, cnt[LIM], c, d[2][LIM*2], p, r[2] = {INF, INF};
vector<int> g[LIM*2];
 
void dfs(int u, int dist){
	if(!d[c][u]) return void(r[c] = dist);
	d[c][u] = dist;
	for(int v : g[u]) dfs(v, dist + 1);
}
 
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
	n = N, p = P;
	for(int i=0; i<M; ++i){
		for(int j=0; j<2; ++j){
			int u = R[i][j], v = R[i][!j];
			if(cnt[u] == 0) g[v + (!cnt[v])*n].push_back(u);
			if(cnt[u] == 1) g[v + (!cnt[v])*n].push_back(u+n);
		}
		for(int j=0; j<2; ++j) ++cnt[R[i][j]];
	}
	for(int u=0; u<n; ++u) if(cnt[u] < 2){
		for(int v : g[u+n]) g[u].push_back(v);
		g[u+n].clear();
	}
	for(c=0; c<2; ++c) fill(d[c], d[c]+2*n, INF);
	for(c=0; c<2; ++c) dfs(p+c*n, 0);
 
	for(int i=0; i<Q; ++i){
		int res = 0;
		for(int u=0; u<n; ++u)
			for(int j=0; j<2; ++j)
				if(d[j][u] <= G[i] && (G[i] - d[j][u]) % r[j] == 0) ++res;
		answer(res);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7372 KB Output is correct
2 Correct 6 ms 7372 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 7 ms 7500 KB Output is correct
7 Correct 6 ms 7372 KB Output is correct
8 Correct 6 ms 7372 KB Output is correct
9 Correct 8 ms 7500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7372 KB Output is correct
2 Correct 6 ms 7372 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 7 ms 7500 KB Output is correct
7 Correct 6 ms 7372 KB Output is correct
8 Correct 6 ms 7372 KB Output is correct
9 Correct 8 ms 7500 KB Output is correct
10 Correct 6 ms 7372 KB Output is correct
11 Correct 14 ms 9156 KB Output is correct
12 Correct 25 ms 10500 KB Output is correct
13 Correct 53 ms 21312 KB Output is correct
14 Correct 109 ms 18116 KB Output is correct
15 Correct 125 ms 18328 KB Output is correct
16 Correct 113 ms 15424 KB Output is correct
17 Correct 89 ms 14452 KB Output is correct
18 Correct 25 ms 10560 KB Output is correct
19 Correct 84 ms 18040 KB Output is correct
20 Correct 135 ms 18300 KB Output is correct
21 Correct 112 ms 15284 KB Output is correct
22 Correct 79 ms 14380 KB Output is correct
23 Correct 80 ms 19136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7372 KB Output is correct
2 Correct 6 ms 7372 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 7 ms 7500 KB Output is correct
7 Correct 6 ms 7372 KB Output is correct
8 Correct 6 ms 7372 KB Output is correct
9 Correct 8 ms 7500 KB Output is correct
10 Correct 6 ms 7372 KB Output is correct
11 Correct 14 ms 9156 KB Output is correct
12 Correct 25 ms 10500 KB Output is correct
13 Correct 53 ms 21312 KB Output is correct
14 Correct 109 ms 18116 KB Output is correct
15 Correct 125 ms 18328 KB Output is correct
16 Correct 113 ms 15424 KB Output is correct
17 Correct 89 ms 14452 KB Output is correct
18 Correct 25 ms 10560 KB Output is correct
19 Correct 84 ms 18040 KB Output is correct
20 Correct 135 ms 18300 KB Output is correct
21 Correct 112 ms 15284 KB Output is correct
22 Correct 79 ms 14380 KB Output is correct
23 Correct 80 ms 19136 KB Output is correct
24 Correct 6 ms 7372 KB Output is correct
25 Correct 109 ms 9264 KB Output is correct
26 Correct 169 ms 10572 KB Output is correct
27 Correct 2555 ms 21352 KB Output is correct
28 Correct 1024 ms 18156 KB Output is correct
29 Correct 2824 ms 18484 KB Output is correct
30 Correct 1658 ms 15460 KB Output is correct
31 Correct 1607 ms 14468 KB Output is correct
32 Correct 165 ms 10548 KB Output is correct
33 Correct 1006 ms 18136 KB Output is correct
34 Correct 2834 ms 18348 KB Output is correct
35 Correct 1727 ms 15324 KB Output is correct
36 Correct 1895 ms 14488 KB Output is correct
37 Correct 858 ms 19236 KB Output is correct
38 Correct 2316 ms 27408 KB Output is correct