답안 #532496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532496 2022-03-03T03:19:11 Z pavement 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
69 / 100
5000 ms 51216 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, OG; i < Q; i++) {
		G[i]--;
		if (chc.find(G[i]) != chc.end()) {
			answer(chc[G[i]]);
			continue;
		}
		ans = 0;
		OG = G[i];
		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[OG] = ans;
		answer(ans);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7756 KB Output is correct
2 Correct 4 ms 7756 KB Output is correct
3 Correct 4 ms 7772 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 8012 KB Output is correct
7 Correct 4 ms 7500 KB Output is correct
8 Correct 4 ms 7760 KB Output is correct
9 Correct 7 ms 9804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7756 KB Output is correct
2 Correct 4 ms 7756 KB Output is correct
3 Correct 4 ms 7772 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 8012 KB Output is correct
7 Correct 4 ms 7500 KB Output is correct
8 Correct 4 ms 7760 KB Output is correct
9 Correct 7 ms 9804 KB Output is correct
10 Correct 4 ms 7500 KB Output is correct
11 Correct 15 ms 14156 KB Output is correct
12 Correct 30 ms 22736 KB Output is correct
13 Correct 44 ms 31940 KB Output is correct
14 Correct 80 ms 49088 KB Output is correct
15 Correct 81 ms 50748 KB Output is correct
16 Correct 79 ms 46816 KB Output is correct
17 Correct 73 ms 46628 KB Output is correct
18 Correct 31 ms 22720 KB Output is correct
19 Correct 87 ms 49116 KB Output is correct
20 Correct 103 ms 50744 KB Output is correct
21 Correct 79 ms 46660 KB Output is correct
22 Correct 75 ms 46408 KB Output is correct
23 Correct 89 ms 51216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7756 KB Output is correct
2 Correct 4 ms 7756 KB Output is correct
3 Correct 4 ms 7772 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 8012 KB Output is correct
7 Correct 4 ms 7500 KB Output is correct
8 Correct 4 ms 7760 KB Output is correct
9 Correct 7 ms 9804 KB Output is correct
10 Correct 4 ms 7500 KB Output is correct
11 Correct 15 ms 14156 KB Output is correct
12 Correct 30 ms 22736 KB Output is correct
13 Correct 44 ms 31940 KB Output is correct
14 Correct 80 ms 49088 KB Output is correct
15 Correct 81 ms 50748 KB Output is correct
16 Correct 79 ms 46816 KB Output is correct
17 Correct 73 ms 46628 KB Output is correct
18 Correct 31 ms 22720 KB Output is correct
19 Correct 87 ms 49116 KB Output is correct
20 Correct 103 ms 50744 KB Output is correct
21 Correct 79 ms 46660 KB Output is correct
22 Correct 75 ms 46408 KB Output is correct
23 Correct 89 ms 51216 KB Output is correct
24 Correct 6 ms 7628 KB Output is correct
25 Correct 1281 ms 14204 KB Output is correct
26 Correct 2528 ms 22792 KB Output is correct
27 Correct 3868 ms 31916 KB Output is correct
28 Execution timed out 5025 ms 49136 KB Time limit exceeded
29 Halted 0 ms 0 KB -