답안 #532493

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532493 2022-03-03T03:14:28 Z pavement 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
69 / 100
5000 ms 53104 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];

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; i < Q; i++) {
		G[i]--;
		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) {
			int curr = j;
			for (int k : bits)
				curr = anc[k][curr];
			if (out[curr]) ans++;
		}
		answer(ans);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7728 KB Output is correct
2 Correct 5 ms 7756 KB Output is correct
3 Correct 4 ms 7868 KB Output is correct
4 Correct 4 ms 7500 KB Output is correct
5 Correct 4 ms 7500 KB Output is correct
6 Correct 5 ms 8140 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
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7728 KB Output is correct
2 Correct 5 ms 7756 KB Output is correct
3 Correct 4 ms 7868 KB Output is correct
4 Correct 4 ms 7500 KB Output is correct
5 Correct 4 ms 7500 KB Output is correct
6 Correct 5 ms 8140 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 7600 KB Output is correct
11 Correct 15 ms 14360 KB Output is correct
12 Correct 31 ms 23284 KB Output is correct
13 Correct 41 ms 32944 KB Output is correct
14 Correct 80 ms 50740 KB Output is correct
15 Correct 84 ms 52524 KB Output is correct
16 Correct 79 ms 48452 KB Output is correct
17 Correct 73 ms 48176 KB Output is correct
18 Correct 31 ms 23296 KB Output is correct
19 Correct 80 ms 50648 KB Output is correct
20 Correct 81 ms 52536 KB Output is correct
21 Correct 80 ms 48244 KB Output is correct
22 Correct 76 ms 47848 KB Output is correct
23 Correct 84 ms 53104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7728 KB Output is correct
2 Correct 5 ms 7756 KB Output is correct
3 Correct 4 ms 7868 KB Output is correct
4 Correct 4 ms 7500 KB Output is correct
5 Correct 4 ms 7500 KB Output is correct
6 Correct 5 ms 8140 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 7600 KB Output is correct
11 Correct 15 ms 14360 KB Output is correct
12 Correct 31 ms 23284 KB Output is correct
13 Correct 41 ms 32944 KB Output is correct
14 Correct 80 ms 50740 KB Output is correct
15 Correct 84 ms 52524 KB Output is correct
16 Correct 79 ms 48452 KB Output is correct
17 Correct 73 ms 48176 KB Output is correct
18 Correct 31 ms 23296 KB Output is correct
19 Correct 80 ms 50648 KB Output is correct
20 Correct 81 ms 52536 KB Output is correct
21 Correct 80 ms 48244 KB Output is correct
22 Correct 76 ms 47848 KB Output is correct
23 Correct 84 ms 53104 KB Output is correct
24 Correct 6 ms 7616 KB Output is correct
25 Correct 1330 ms 14528 KB Output is correct
26 Correct 2605 ms 23484 KB Output is correct
27 Correct 3844 ms 33000 KB Output is correct
28 Execution timed out 5038 ms 50736 KB Time limit exceeded
29 Halted 0 ms 0 KB -