Submission #532495

# Submission time Handle Problem Language Result Execution time Memory
532495 2022-03-03T03:17:52 Z pavement Tropical Garden (IOI11_garden) C++17
69 / 100
89 ms 51240 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
using ii = pair<int, int>;

int to[300005], anc[35][300005];
bool out[300005];
vector<int> bits, in_nodes;
vector<ii> _adj[300005];
map<int, int> chc;

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
	for (int i = 0; i < M; i++) {
		_adj[R[i][0]].eb(i, i << 1);
		_adj[R[i][1]].eb(i, i << 1 | 1);
	}
	for (int i = 0; i < N; i++) sort(_adj[i].begin(), _adj[i].end());
	for (int i = 0; i < M; i++) {
		if (_adj[R[i][1]].size() == 1) to[i << 1] = (i << 1) ^ 1;
		else to[i << 1] = ((_adj[R[i][1]][0].second >> 1) == i ? _adj[R[i][1]][1].second : _adj[R[i][1]][0].second);
		if (_adj[R[i][0]].size() == 1) to[i << 1 | 1] = (i << 1 | 1) ^ 1;
		else to[i << 1 | 1] = ((_adj[R[i][0]][0].second >> 1) == i ? _adj[R[i][0]][1].second : _adj[R[i][0]][0].second);
	}
	for (int i = 0; i < N; i++)
		if (!_adj[i].empty()) in_nodes.pb(_adj[i][0].second);
	for (int i = 0; i < M; i++) {
		if (R[i][0] == P) out[i << 1 | 1] = 1;
		if (R[i][1] == P) out[i << 1] = 1;
	}
	for (int k = 0; k < 30; k++) {
		for (int i = 0; i < (M << 1); i++)
			if (k == 0) anc[k][i] = to[i];
			else anc[k][i] = anc[k - 1][anc[k - 1][i]];
	}
	for (int i = 0, ans, curr; i < Q; i++) {
		G[i]--;
		if (chc.find(G[i]) != chc.end()) {
			answer(chc[G[i]]);
			continue;
		}
		ans = 0;
		bits.clear();
		for (int j = 0; G[i]; j++, G[i] >>= 1)
			if (G[i] & 1) bits.pb(j);
		for (int j : in_nodes) {
			curr = j;
			for (int k : bits)
				curr = anc[k][curr];
			if (out[curr]) ans++;
		}
		chc[G[i]] = ans;
		answer(ans);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7756 KB Output is correct
2 Correct 4 ms 7756 KB Output is correct
3 Correct 4 ms 7888 KB Output is correct
4 Correct 4 ms 7500 KB Output is correct
5 Correct 5 ms 7500 KB Output is correct
6 Correct 5 ms 8012 KB Output is correct
7 Correct 4 ms 7500 KB Output is correct
8 Correct 4 ms 7756 KB Output is correct
9 Correct 7 ms 9804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7756 KB Output is correct
2 Correct 4 ms 7756 KB Output is correct
3 Correct 4 ms 7888 KB Output is correct
4 Correct 4 ms 7500 KB Output is correct
5 Correct 5 ms 7500 KB Output is correct
6 Correct 5 ms 8012 KB Output is correct
7 Correct 4 ms 7500 KB Output is correct
8 Correct 4 ms 7756 KB Output is correct
9 Correct 7 ms 9804 KB Output is correct
10 Correct 4 ms 7500 KB Output is correct
11 Correct 18 ms 14144 KB Output is correct
12 Correct 30 ms 22768 KB Output is correct
13 Correct 41 ms 31932 KB Output is correct
14 Correct 82 ms 48996 KB Output is correct
15 Correct 85 ms 50808 KB Output is correct
16 Correct 83 ms 46756 KB Output is correct
17 Correct 74 ms 46652 KB Output is correct
18 Correct 30 ms 22728 KB Output is correct
19 Correct 78 ms 49100 KB Output is correct
20 Correct 81 ms 50788 KB Output is correct
21 Correct 78 ms 46640 KB Output is correct
22 Correct 75 ms 46400 KB Output is correct
23 Correct 89 ms 51240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7756 KB Output is correct
2 Correct 4 ms 7756 KB Output is correct
3 Correct 4 ms 7888 KB Output is correct
4 Correct 4 ms 7500 KB Output is correct
5 Correct 5 ms 7500 KB Output is correct
6 Correct 5 ms 8012 KB Output is correct
7 Correct 4 ms 7500 KB Output is correct
8 Correct 4 ms 7756 KB Output is correct
9 Correct 7 ms 9804 KB Output is correct
10 Correct 4 ms 7500 KB Output is correct
11 Correct 18 ms 14144 KB Output is correct
12 Correct 30 ms 22768 KB Output is correct
13 Correct 41 ms 31932 KB Output is correct
14 Correct 82 ms 48996 KB Output is correct
15 Correct 85 ms 50808 KB Output is correct
16 Correct 83 ms 46756 KB Output is correct
17 Correct 74 ms 46652 KB Output is correct
18 Correct 30 ms 22728 KB Output is correct
19 Correct 78 ms 49100 KB Output is correct
20 Correct 81 ms 50788 KB Output is correct
21 Correct 78 ms 46640 KB Output is correct
22 Correct 75 ms 46400 KB Output is correct
23 Correct 89 ms 51240 KB Output is correct
24 Incorrect 6 ms 7500 KB Output isn't correct
25 Halted 0 ms 0 KB -