Submission #840458

# Submission time Handle Problem Language Result Execution time Memory
840458 2023-08-31T11:42:58 Z catalystgma Soccer Stadium (IOI23_soccer) C++17
22 / 100
4500 ms 142564 KB
#include <bits/stdc++.h>
#define maxn 2000

bool inside(int n, int i, int j) {
	return i  >= 0 && i < n && j >= 0 && j < n;
}

std::vector<std::pair<int, int>> neighs(int n, int i, int j, std::vector<std::vector<int>> &v) {
	std::vector<std::pair<int, int>> sol;
	for (int dy: {-1, 0, 1}) {
		for (int dx: {-1, 0, 1}) {
			if (abs(dy) != abs(dx) && inside(n, i+dy, j+dx) && v[i+dy][j+dx] == 0) {
				sol.emplace_back(i + dy, j + dx);
			}
		}
	}

	return sol;
}

struct Pos {
	int y, x;
	bool isDirOrizontal, haveRemChange;

	Pos(int y_, int x_, bool isdo) {
		y = y_;
		x = x_;
		isDirOrizontal = isdo;
	}
};

int viz[maxn+5][maxn+5][2]; ///punct, directie = max schimbari ramase.
bool bagat[maxn+5][maxn+5][2];

bool isFullMapOk(int n, std::vector<std::vector<int>> &v) {
	std::vector<std::pair<int, std::pair<int, int>>> parti;
	int i, j, z;
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (v[i][j] == 0) {
				parti.emplace_back(neighs(n, i, j, v).size(), std::make_pair(i, j));
			}
		}
	}

	std::sort(parti.begin(), parti.end());

	clock_t te = clock() + 4 * CLOCKS_PER_SEC;
	for (auto p: parti) {
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				viz[i][j][0] = viz[i][j][1] = -1;
				bagat[i][j][0] = bagat[i][j][1] = false;
			}
		}

		std::deque<Pos> qu;

		viz[p.second.first][p.second.second][0] = 1;
		qu.emplace_front(p.second.first, p.second.second, false);

		viz[p.second.first][p.second.second][1] = 1;
		qu.emplace_front(p.second.first, p.second.second, true);

		while (!qu.empty()) { ///daca nu merge campul, ma astept sa crape din cauza unui patrat cu nr mic de vecini.
			if (clock() > te) {
				return true;
			}

			auto now = qu.front();
			qu.pop_front();

			now.haveRemChange = viz[now.y][now.x][now.isDirOrizontal];
			bagat[now.y][now.x][now.isDirOrizontal] = false;

			for (int _ = 0; _ < 2; _++) {
				if (_) { ///incerc sa schimb directia.
					if (!now.haveRemChange) break;
					now.haveRemChange = false;
					now.isDirOrizontal ^= 1;
				}

				for (int sh: {-1, 1}) {
					if (now.isDirOrizontal) now.x += sh;
					else now.y += sh;

					if (inside(n, now.y, now.x) && v[now.y][now.x] == 0 && viz[now.y][now.x][now.isDirOrizontal] < now.haveRemChange) {
						viz[now.y][now.x][now.isDirOrizontal] = now.haveRemChange;
						if (!bagat[now.y][now.x][now.isDirOrizontal]) {
							if (now.haveRemChange == 1) qu.emplace_front(now.y, now.x, now.isDirOrizontal);
							else qu.emplace_back(now.y, now.x, now.isDirOrizontal);
							bagat[now.y][now.x][now.isDirOrizontal] = true;
						}
					}

					if (now.isDirOrizontal) now.x -= sh;
					else now.y -= sh;
				}
			}
		}

		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				if (v[i][j] == 0 && std::max(viz[i][j][0], viz[i][j][1]) < 0) {
					return false;
				}
			}
		}

		if (clock() > te) {
			break;
		}
	}

	return true;
}

int continua(int n, std::vector<std::vector<int>> &v) {
	int y = -1, x = -1, cnt0s = 0;
	int i, j, z;
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (v[i][j] == 0) {
				y = i;
				x = j;
				cnt0s++;
			}
		}
	}

	std::queue<std::pair<int, int>> qu;
	std::vector<std::pair<int, int>> got;

	qu.emplace(y, x);
	got.emplace_back(y, x);
	v[y][x] = -1;

	while (!qu.empty()) {
		std::tie(y, x) = qu.front();
		qu.pop();

		for (auto p: neighs(n, y, x, v)) {
			if (v[p.first][p.second] != -1) {
				qu.push(p);
				got.push_back(p);
				v[p.first][p.second] = -1;
			}
		}
	}

	for (auto &p: got) {
		v[p.first][p.second] = 0;
	}

	return ((int)got.size() == cnt0s? cnt0s: -1);
}

int biggest_stadium(int n, std::vector<std::vector<int>> v) {
	int cnt1s = 0, y = -1, x = -1;

	int i, j, z;
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (v[i][j] == 1) {
				cnt1s++;
				y = i;
				x = j;
			}
		}
	}

	if (cnt1s <= 1) {
		if (cnt1s == 0) {
			return n * n;
		}

		return n * n - std::min(n - x, x + 1) * std::min(n - y, y + 1);
	}

	///incerc sa vad daca toata harta e ok.

	///zona continua?
	int cnt0s = continua(n, v);
	if (cnt0s == -1) {
		return -1;
	}

	if (isFullMapOk(n, v)) {
		return cnt0s;
	}

	return -1;
}

Compilation message

soccer.cpp: In function 'bool isFullMapOk(int, std::vector<std::vector<int> >&)':
soccer.cpp:37:12: warning: unused variable 'z' [-Wunused-variable]
   37 |  int i, j, z;
      |            ^
soccer.cpp: In function 'int continua(int, std::vector<std::vector<int> >&)':
soccer.cpp:120:12: warning: unused variable 'z' [-Wunused-variable]
  120 |  int i, j, z;
      |            ^
soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:161:12: warning: unused variable 'z' [-Wunused-variable]
  161 |  int i, j, z;
      |            ^
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 340 KB partial
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ok
2 Correct 0 ms 212 KB ok
3 Correct 1 ms 212 KB ok
4 Correct 0 ms 212 KB ok
5 Correct 0 ms 212 KB ok
6 Correct 1 ms 212 KB ok
7 Correct 1 ms 340 KB ok
8 Correct 22 ms 2208 KB ok
9 Correct 227 ms 31640 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ok
2 Correct 0 ms 212 KB ok
3 Partially correct 1 ms 212 KB partial
4 Partially correct 0 ms 212 KB partial
5 Partially correct 1 ms 212 KB partial
6 Partially correct 0 ms 212 KB partial
7 Partially correct 0 ms 212 KB partial
8 Correct 0 ms 212 KB ok
9 Correct 0 ms 212 KB ok
10 Partially correct 0 ms 212 KB partial
11 Partially correct 0 ms 212 KB partial
12 Partially correct 0 ms 212 KB partial
13 Correct 0 ms 212 KB ok
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 340 KB partial
2 Correct 0 ms 212 KB ok
3 Correct 0 ms 212 KB ok
4 Partially correct 1 ms 212 KB partial
5 Partially correct 0 ms 212 KB partial
6 Partially correct 1 ms 212 KB partial
7 Partially correct 0 ms 212 KB partial
8 Partially correct 0 ms 212 KB partial
9 Correct 0 ms 212 KB ok
10 Correct 0 ms 212 KB ok
11 Partially correct 0 ms 212 KB partial
12 Partially correct 0 ms 212 KB partial
13 Partially correct 0 ms 212 KB partial
14 Correct 0 ms 212 KB ok
15 Partially correct 0 ms 340 KB partial
16 Partially correct 1 ms 340 KB partial
17 Partially correct 0 ms 212 KB partial
18 Partially correct 1 ms 212 KB partial
19 Partially correct 0 ms 212 KB partial
20 Correct 0 ms 340 KB ok
21 Correct 0 ms 340 KB ok
22 Partially correct 0 ms 340 KB partial
23 Partially correct 0 ms 340 KB partial
24 Partially correct 0 ms 340 KB partial
25 Partially correct 1 ms 360 KB partial
26 Partially correct 0 ms 212 KB partial
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 340 KB partial
2 Correct 0 ms 212 KB ok
3 Correct 0 ms 212 KB ok
4 Correct 1 ms 212 KB ok
5 Correct 0 ms 212 KB ok
6 Partially correct 1 ms 212 KB partial
7 Partially correct 0 ms 212 KB partial
8 Partially correct 1 ms 212 KB partial
9 Partially correct 0 ms 212 KB partial
10 Partially correct 0 ms 212 KB partial
11 Correct 0 ms 212 KB ok
12 Correct 0 ms 212 KB ok
13 Partially correct 0 ms 212 KB partial
14 Partially correct 0 ms 212 KB partial
15 Partially correct 0 ms 212 KB partial
16 Correct 0 ms 212 KB ok
17 Partially correct 0 ms 340 KB partial
18 Partially correct 1 ms 340 KB partial
19 Partially correct 0 ms 212 KB partial
20 Partially correct 1 ms 212 KB partial
21 Partially correct 0 ms 212 KB partial
22 Correct 0 ms 340 KB ok
23 Correct 0 ms 340 KB ok
24 Partially correct 0 ms 340 KB partial
25 Partially correct 0 ms 340 KB partial
26 Partially correct 0 ms 340 KB partial
27 Partially correct 1 ms 360 KB partial
28 Partially correct 0 ms 212 KB partial
29 Partially correct 1 ms 340 KB partial
30 Partially correct 1 ms 468 KB partial
31 Partially correct 1 ms 468 KB partial
32 Partially correct 1 ms 212 KB partial
33 Partially correct 1 ms 212 KB partial
34 Correct 11 ms 564 KB ok
35 Correct 28 ms 468 KB ok
36 Partially correct 1 ms 468 KB partial
37 Partially correct 1 ms 512 KB partial
38 Partially correct 1 ms 512 KB partial
39 Partially correct 1 ms 468 KB partial
40 Partially correct 1 ms 468 KB partial
41 Partially correct 1 ms 212 KB partial
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 340 KB partial
2 Correct 0 ms 212 KB ok
3 Correct 0 ms 212 KB ok
4 Correct 1 ms 212 KB ok
5 Correct 0 ms 212 KB ok
6 Partially correct 1 ms 212 KB partial
7 Partially correct 0 ms 212 KB partial
8 Partially correct 1 ms 212 KB partial
9 Partially correct 0 ms 212 KB partial
10 Partially correct 0 ms 212 KB partial
11 Correct 0 ms 212 KB ok
12 Correct 0 ms 212 KB ok
13 Partially correct 0 ms 212 KB partial
14 Partially correct 0 ms 212 KB partial
15 Partially correct 0 ms 212 KB partial
16 Correct 0 ms 212 KB ok
17 Partially correct 0 ms 340 KB partial
18 Partially correct 1 ms 340 KB partial
19 Partially correct 0 ms 212 KB partial
20 Partially correct 1 ms 212 KB partial
21 Partially correct 0 ms 212 KB partial
22 Correct 0 ms 340 KB ok
23 Correct 0 ms 340 KB ok
24 Partially correct 0 ms 340 KB partial
25 Partially correct 0 ms 340 KB partial
26 Partially correct 0 ms 340 KB partial
27 Partially correct 1 ms 360 KB partial
28 Partially correct 0 ms 212 KB partial
29 Partially correct 1 ms 340 KB partial
30 Partially correct 1 ms 468 KB partial
31 Partially correct 1 ms 468 KB partial
32 Partially correct 1 ms 212 KB partial
33 Partially correct 1 ms 212 KB partial
34 Correct 11 ms 564 KB ok
35 Correct 28 ms 468 KB ok
36 Partially correct 1 ms 468 KB partial
37 Partially correct 1 ms 512 KB partial
38 Partially correct 1 ms 512 KB partial
39 Partially correct 1 ms 468 KB partial
40 Partially correct 1 ms 468 KB partial
41 Partially correct 1 ms 212 KB partial
42 Partially correct 29 ms 4360 KB partial
43 Partially correct 26 ms 4468 KB partial
44 Partially correct 90 ms 14176 KB partial
45 Partially correct 95 ms 14172 KB partial
46 Partially correct 68 ms 14036 KB partial
47 Partially correct 264 ms 14172 KB partial
48 Correct 4045 ms 11212 KB ok
49 Partially correct 83 ms 12884 KB partial
50 Partially correct 82 ms 13456 KB partial
51 Partially correct 15 ms 2208 KB partial
52 Partially correct 864 ms 9344 KB partial
53 Partially correct 573 ms 8488 KB partial
54 Partially correct 59 ms 8904 KB partial
55 Partially correct 145 ms 9584 KB partial
56 Partially correct 42 ms 10932 KB partial
57 Partially correct 22 ms 4500 KB partial
58 Partially correct 22 ms 4496 KB partial
59 Partially correct 23 ms 4456 KB partial
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 340 KB partial
2 Correct 0 ms 212 KB ok
3 Correct 0 ms 212 KB ok
4 Correct 1 ms 212 KB ok
5 Correct 0 ms 212 KB ok
6 Correct 0 ms 212 KB ok
7 Correct 1 ms 212 KB ok
8 Correct 1 ms 340 KB ok
9 Correct 22 ms 2208 KB ok
10 Correct 227 ms 31640 KB ok
11 Partially correct 1 ms 212 KB partial
12 Partially correct 0 ms 212 KB partial
13 Partially correct 1 ms 212 KB partial
14 Partially correct 0 ms 212 KB partial
15 Partially correct 0 ms 212 KB partial
16 Correct 0 ms 212 KB ok
17 Correct 0 ms 212 KB ok
18 Partially correct 0 ms 212 KB partial
19 Partially correct 0 ms 212 KB partial
20 Partially correct 0 ms 212 KB partial
21 Correct 0 ms 212 KB ok
22 Partially correct 0 ms 340 KB partial
23 Partially correct 1 ms 340 KB partial
24 Partially correct 0 ms 212 KB partial
25 Partially correct 1 ms 212 KB partial
26 Partially correct 0 ms 212 KB partial
27 Correct 0 ms 340 KB ok
28 Correct 0 ms 340 KB ok
29 Partially correct 0 ms 340 KB partial
30 Partially correct 0 ms 340 KB partial
31 Partially correct 0 ms 340 KB partial
32 Partially correct 1 ms 360 KB partial
33 Partially correct 0 ms 212 KB partial
34 Partially correct 1 ms 340 KB partial
35 Partially correct 1 ms 468 KB partial
36 Partially correct 1 ms 468 KB partial
37 Partially correct 1 ms 212 KB partial
38 Partially correct 1 ms 212 KB partial
39 Correct 11 ms 564 KB ok
40 Correct 28 ms 468 KB ok
41 Partially correct 1 ms 468 KB partial
42 Partially correct 1 ms 512 KB partial
43 Partially correct 1 ms 512 KB partial
44 Partially correct 1 ms 468 KB partial
45 Partially correct 1 ms 468 KB partial
46 Partially correct 1 ms 212 KB partial
47 Partially correct 29 ms 4360 KB partial
48 Partially correct 26 ms 4468 KB partial
49 Partially correct 90 ms 14176 KB partial
50 Partially correct 95 ms 14172 KB partial
51 Partially correct 68 ms 14036 KB partial
52 Partially correct 264 ms 14172 KB partial
53 Correct 4045 ms 11212 KB ok
54 Partially correct 83 ms 12884 KB partial
55 Partially correct 82 ms 13456 KB partial
56 Partially correct 15 ms 2208 KB partial
57 Partially correct 864 ms 9344 KB partial
58 Partially correct 573 ms 8488 KB partial
59 Partially correct 59 ms 8904 KB partial
60 Partially correct 145 ms 9584 KB partial
61 Partially correct 42 ms 10932 KB partial
62 Partially correct 22 ms 4500 KB partial
63 Partially correct 22 ms 4496 KB partial
64 Partially correct 23 ms 4456 KB partial
65 Partially correct 447 ms 64720 KB partial
66 Partially correct 305 ms 31644 KB partial
67 Partially correct 236 ms 31644 KB partial
68 Partially correct 1567 ms 142488 KB partial
69 Partially correct 1251 ms 142072 KB partial
70 Partially correct 1156 ms 141504 KB partial
71 Partially correct 1663 ms 142564 KB partial
72 Partially correct 3436 ms 142540 KB partial
73 Execution timed out 4507 ms 119096 KB Time limit exceeded
74 Halted 0 ms 0 KB -