Submission #39255

# Submission time Handle Problem Language Result Execution time Memory
39255 2018-01-10T12:37:03 Z 14kg Tropical Garden (IOI11_garden) C++11
69 / 100
5000 ms 153860 KB
#include "garden.h"
#include "gardenlib.h"
#include <algorithm>
#include <vector>
#define N 150001

using namespace std;
int n, m, start, p[15], R, Rw, tot;
bool check[N][2][15];
pair<int, int> r[N];
vector<int> r1[N], r2[N];
vector<pair<int, int> > d[N][2][15];

void Push_r(int x, int y) {
	if (!r[x].first) r[x].first = y;
	else if (!r[x].second) r[x].second = y;
}
void f(int x, int y, int s) {
	if (s == 0 || check[x][y][s]) return;

	f(x, y, s - 1), check[x][y][s] = true;
	for (auto i : d[x][y][s - 1]) {
		f(i.first, i.second, s - 1);
		for (auto j : d[i.first][i.second][s - 1]) {
			f(j.first, j.second, s - 1);
			for (auto p : d[j.first][j.second][s - 1]) {
				f(p.first, p.second, s - 1);
				for (auto q : d[p.first][p.second][s - 1]) {
					d[x][y][s].push_back(q);
				}
			}
		}
	}
}
void g(int x, int y, int R, int Rw) {
	if (R == 0) {
		if (y == 0 || r[x].first == 0) tot++;
		return;
	}
	while (p[Rw] > R) Rw--;

	f(x, y, Rw);
	for (auto i : d[x][y][Rw]) g(i.first, i.second, R - p[Rw], Rw);
}
void count_routes(int _n, int _m, int _s, int _r[][2], int Q_len, int Q[]) {
	n = _n, start = _s + 1, p[0] = 1;
	for (int i = 1; i < 15; i++) p[i] = p[i - 1] * 4;

	for (int i = 0; i < _m; i++) {
		int x = _r[i][0] + 1, y = _r[i][1] + 1;
		Push_r(x, y), Push_r(y, x);
	}
	for (int i = 1; i <= n; i++) {
		if (!r[i].second) r[i].second = r[i].first, r[i].first = 0;

		if (r[i].first) r1[r[i].first].push_back(i);
		r2[r[i].second].push_back(i);

		if (r[r[i].first].first == i || (r[r[i].first].first == 0 && r[r[i].first].second == i)) d[r[i].first][1][0].push_back({ i,0 });
		if (r[r[i].second].first == i || (r[r[i].second].first == 0 && r[r[i].second].second == i)) d[r[i].second][1][0].push_back({ i,1 });
	}

	for (int i = 1; i <= n; i++) {
		for (auto j : r1[i])
			if (j != r[i].first && (r[i].first || r[i].second != j)) d[i][0][0].push_back({ j,0 });
		for (auto j : r2[i])
			if (j != r[i].first && (r[i].first || r[i].second != j)) d[i][0][0].push_back({ j,1 });
	}

	for (int i = 0; i < Q_len; i++) {
		tot = 0, g(start, 0, Q[i], 14), g(start, 1, Q[i], 14);
		answer(tot);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 107 ms 113096 KB Output is correct
2 Correct 107 ms 113248 KB Output is correct
3 Correct 108 ms 113212 KB Output is correct
4 Correct 109 ms 113120 KB Output is correct
5 Correct 106 ms 113084 KB Output is correct
6 Correct 106 ms 113280 KB Output is correct
7 Correct 107 ms 113124 KB Output is correct
8 Correct 109 ms 113236 KB Output is correct
9 Correct 110 ms 113308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 113096 KB Output is correct
2 Correct 107 ms 113248 KB Output is correct
3 Correct 108 ms 113212 KB Output is correct
4 Correct 109 ms 113120 KB Output is correct
5 Correct 106 ms 113084 KB Output is correct
6 Correct 106 ms 113280 KB Output is correct
7 Correct 107 ms 113124 KB Output is correct
8 Correct 109 ms 113236 KB Output is correct
9 Correct 110 ms 113308 KB Output is correct
10 Correct 110 ms 113124 KB Output is correct
11 Correct 126 ms 115884 KB Output is correct
12 Correct 146 ms 117664 KB Output is correct
13 Correct 635 ms 147924 KB Output is correct
14 Correct 364 ms 133620 KB Output is correct
15 Correct 939 ms 153036 KB Output is correct
16 Correct 648 ms 143576 KB Output is correct
17 Correct 634 ms 140340 KB Output is correct
18 Correct 143 ms 117752 KB Output is correct
19 Correct 321 ms 132832 KB Output is correct
20 Correct 1088 ms 153860 KB Output is correct
21 Correct 662 ms 144752 KB Output is correct
22 Correct 469 ms 136556 KB Output is correct
23 Correct 272 ms 131176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 113096 KB Output is correct
2 Correct 107 ms 113248 KB Output is correct
3 Correct 108 ms 113212 KB Output is correct
4 Correct 109 ms 113120 KB Output is correct
5 Correct 106 ms 113084 KB Output is correct
6 Correct 106 ms 113280 KB Output is correct
7 Correct 107 ms 113124 KB Output is correct
8 Correct 109 ms 113236 KB Output is correct
9 Correct 110 ms 113308 KB Output is correct
10 Correct 110 ms 113124 KB Output is correct
11 Correct 126 ms 115884 KB Output is correct
12 Correct 146 ms 117664 KB Output is correct
13 Correct 635 ms 147924 KB Output is correct
14 Correct 364 ms 133620 KB Output is correct
15 Correct 939 ms 153036 KB Output is correct
16 Correct 648 ms 143576 KB Output is correct
17 Correct 634 ms 140340 KB Output is correct
18 Correct 143 ms 117752 KB Output is correct
19 Correct 321 ms 132832 KB Output is correct
20 Correct 1088 ms 153860 KB Output is correct
21 Correct 662 ms 144752 KB Output is correct
22 Correct 469 ms 136556 KB Output is correct
23 Correct 272 ms 131176 KB Output is correct
24 Correct 108 ms 113132 KB Output is correct
25 Correct 130 ms 116060 KB Output is correct
26 Correct 154 ms 118236 KB Output is correct
27 Correct 651 ms 148204 KB Output is correct
28 Execution timed out 5068 ms 134280 KB Time limit exceeded
29 Halted 0 ms 0 KB -