답안 #840448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
840448 2023-08-31T11:38:00 Z catalystgma 축구 경기장 (IOI23_soccer) C++17
22 / 100
4500 ms 142612 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::queue<Pos> qu;

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

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

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

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

			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]) {
							qu.emplace(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 'int continua(int, std::vector<std::vector<int> >&)':
soccer.cpp:121:12: warning: unused variable 'z' [-Wunused-variable]
  121 |  int i, j, z;
      |            ^
soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:162:12: warning: unused variable 'z' [-Wunused-variable]
  162 |  int i, j, z;
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 340 KB partial
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB ok
2 Correct 0 ms 256 KB ok
3 Correct 0 ms 212 KB ok
4 Correct 0 ms 212 KB ok
5 Correct 0 ms 260 KB ok
6 Correct 1 ms 212 KB ok
7 Correct 2 ms 384 KB ok
8 Correct 15 ms 2204 KB ok
9 Correct 249 ms 31648 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB ok
2 Correct 0 ms 256 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 1 ms 340 KB ok
9 Correct 1 ms 212 KB ok
10 Partially correct 0 ms 212 KB partial
11 Partially correct 0 ms 212 KB partial
12 Partially correct 1 ms 212 KB partial
13 Correct 1 ms 212 KB ok
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 340 KB partial
2 Correct 1 ms 212 KB ok
3 Correct 0 ms 256 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 1 ms 340 KB ok
10 Correct 1 ms 212 KB ok
11 Partially correct 0 ms 212 KB partial
12 Partially correct 0 ms 212 KB partial
13 Partially correct 1 ms 212 KB partial
14 Correct 1 ms 212 KB ok
15 Partially correct 0 ms 340 KB partial
16 Partially correct 0 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 1 ms 340 KB ok
21 Correct 0 ms 340 KB ok
22 Partially correct 1 ms 340 KB partial
23 Partially correct 1 ms 340 KB partial
24 Partially correct 1 ms 340 KB partial
25 Partially correct 1 ms 340 KB partial
26 Partially correct 1 ms 212 KB partial
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 340 KB partial
2 Correct 1 ms 212 KB ok
3 Correct 0 ms 256 KB ok
4 Correct 0 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 1 ms 340 KB ok
12 Correct 1 ms 212 KB ok
13 Partially correct 0 ms 212 KB partial
14 Partially correct 0 ms 212 KB partial
15 Partially correct 1 ms 212 KB partial
16 Correct 1 ms 212 KB ok
17 Partially correct 0 ms 340 KB partial
18 Partially correct 0 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 1 ms 340 KB ok
23 Correct 0 ms 340 KB ok
24 Partially correct 1 ms 340 KB partial
25 Partially correct 1 ms 340 KB partial
26 Partially correct 1 ms 340 KB partial
27 Partially correct 1 ms 340 KB partial
28 Partially correct 1 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 2 ms 468 KB ok
35 Correct 4 ms 468 KB ok
36 Partially correct 1 ms 468 KB partial
37 Partially correct 1 ms 468 KB partial
38 Partially correct 1 ms 468 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
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 340 KB partial
2 Correct 1 ms 212 KB ok
3 Correct 0 ms 256 KB ok
4 Correct 0 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 1 ms 340 KB ok
12 Correct 1 ms 212 KB ok
13 Partially correct 0 ms 212 KB partial
14 Partially correct 0 ms 212 KB partial
15 Partially correct 1 ms 212 KB partial
16 Correct 1 ms 212 KB ok
17 Partially correct 0 ms 340 KB partial
18 Partially correct 0 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 1 ms 340 KB ok
23 Correct 0 ms 340 KB ok
24 Partially correct 1 ms 340 KB partial
25 Partially correct 1 ms 340 KB partial
26 Partially correct 1 ms 340 KB partial
27 Partially correct 1 ms 340 KB partial
28 Partially correct 1 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 2 ms 468 KB ok
35 Correct 4 ms 468 KB ok
36 Partially correct 1 ms 468 KB partial
37 Partially correct 1 ms 468 KB partial
38 Partially correct 1 ms 468 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 39 ms 4444 KB partial
43 Partially correct 34 ms 4440 KB partial
44 Partially correct 78 ms 14160 KB partial
45 Partially correct 100 ms 14184 KB partial
46 Partially correct 72 ms 13988 KB partial
47 Partially correct 87 ms 14204 KB partial
48 Correct 4046 ms 11188 KB ok
49 Partially correct 75 ms 12904 KB partial
50 Partially correct 51 ms 13464 KB partial
51 Partially correct 17 ms 2260 KB partial
52 Partially correct 128 ms 9304 KB partial
53 Partially correct 107 ms 8488 KB partial
54 Partially correct 36 ms 8904 KB partial
55 Partially correct 41 ms 9632 KB partial
56 Partially correct 57 ms 10892 KB partial
57 Partially correct 23 ms 4424 KB partial
58 Partially correct 25 ms 4500 KB partial
59 Partially correct 35 ms 4416 KB partial
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 340 KB partial
2 Correct 1 ms 212 KB ok
3 Correct 0 ms 256 KB ok
4 Correct 0 ms 212 KB ok
5 Correct 0 ms 212 KB ok
6 Correct 0 ms 260 KB ok
7 Correct 1 ms 212 KB ok
8 Correct 2 ms 384 KB ok
9 Correct 15 ms 2204 KB ok
10 Correct 249 ms 31648 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 1 ms 340 KB ok
17 Correct 1 ms 212 KB ok
18 Partially correct 0 ms 212 KB partial
19 Partially correct 0 ms 212 KB partial
20 Partially correct 1 ms 212 KB partial
21 Correct 1 ms 212 KB ok
22 Partially correct 0 ms 340 KB partial
23 Partially correct 0 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 1 ms 340 KB ok
28 Correct 0 ms 340 KB ok
29 Partially correct 1 ms 340 KB partial
30 Partially correct 1 ms 340 KB partial
31 Partially correct 1 ms 340 KB partial
32 Partially correct 1 ms 340 KB partial
33 Partially correct 1 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 2 ms 468 KB ok
40 Correct 4 ms 468 KB ok
41 Partially correct 1 ms 468 KB partial
42 Partially correct 1 ms 468 KB partial
43 Partially correct 1 ms 468 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 39 ms 4444 KB partial
48 Partially correct 34 ms 4440 KB partial
49 Partially correct 78 ms 14160 KB partial
50 Partially correct 100 ms 14184 KB partial
51 Partially correct 72 ms 13988 KB partial
52 Partially correct 87 ms 14204 KB partial
53 Correct 4046 ms 11188 KB ok
54 Partially correct 75 ms 12904 KB partial
55 Partially correct 51 ms 13464 KB partial
56 Partially correct 17 ms 2260 KB partial
57 Partially correct 128 ms 9304 KB partial
58 Partially correct 107 ms 8488 KB partial
59 Partially correct 36 ms 8904 KB partial
60 Partially correct 41 ms 9632 KB partial
61 Partially correct 57 ms 10892 KB partial
62 Partially correct 23 ms 4424 KB partial
63 Partially correct 25 ms 4500 KB partial
64 Partially correct 35 ms 4416 KB partial
65 Partially correct 458 ms 64648 KB partial
66 Partially correct 276 ms 31760 KB partial
67 Partially correct 257 ms 31648 KB partial
68 Partially correct 1416 ms 142500 KB partial
69 Partially correct 1279 ms 142016 KB partial
70 Partially correct 1214 ms 141436 KB partial
71 Partially correct 1361 ms 142612 KB partial
72 Partially correct 1585 ms 142544 KB partial
73 Execution timed out 4527 ms 119056 KB Time limit exceeded
74 Halted 0 ms 0 KB -