답안 #840463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
840463 2023-08-31T11:47:49 Z catalystgma 축구 경기장 (IOI23_soccer) C++17
22 / 100
4500 ms 142616 KB
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")

#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:40:12: warning: unused variable 'z' [-Wunused-variable]
   40 |  int i, j, z;
      |            ^
soccer.cpp: In function 'int continua(int, std::vector<std::vector<int> >&)':
soccer.cpp:123:12: warning: unused variable 'z' [-Wunused-variable]
  123 |  int i, j, z;
      |            ^
soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:164:12: warning: unused variable 'z' [-Wunused-variable]
  164 |  int i, j, z;
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 340 KB partial
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB ok
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 340 KB ok
8 Correct 16 ms 2200 KB ok
9 Correct 233 ms 31656 KB ok
# 결과 실행 시간 메모리 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 0 ms 212 KB partial
6 Partially correct 0 ms 296 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
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 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 0 ms 212 KB partial
7 Partially correct 0 ms 296 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 0 ms 340 KB partial
17 Partially correct 0 ms 212 KB partial
18 Partially correct 0 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 1 ms 340 KB partial
24 Partially correct 0 ms 340 KB partial
25 Partially correct 0 ms 340 KB partial
26 Partially correct 0 ms 212 KB partial
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 340 KB partial
2 Correct 0 ms 212 KB ok
3 Correct 0 ms 212 KB ok
4 Correct 0 ms 212 KB ok
5 Correct 1 ms 212 KB ok
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 Partially correct 0 ms 296 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 0 ms 340 KB partial
19 Partially correct 0 ms 212 KB partial
20 Partially correct 0 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 1 ms 340 KB partial
26 Partially correct 0 ms 340 KB partial
27 Partially correct 0 ms 340 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 0 ms 212 KB partial
33 Partially correct 0 ms 212 KB partial
34 Correct 7 ms 468 KB ok
35 Correct 28 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 0 ms 212 KB partial
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 340 KB partial
2 Correct 0 ms 212 KB ok
3 Correct 0 ms 212 KB ok
4 Correct 0 ms 212 KB ok
5 Correct 1 ms 212 KB ok
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 Partially correct 0 ms 296 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 0 ms 340 KB partial
19 Partially correct 0 ms 212 KB partial
20 Partially correct 0 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 1 ms 340 KB partial
26 Partially correct 0 ms 340 KB partial
27 Partially correct 0 ms 340 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 0 ms 212 KB partial
33 Partially correct 0 ms 212 KB partial
34 Correct 7 ms 468 KB ok
35 Correct 28 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 0 ms 212 KB partial
42 Partially correct 26 ms 4500 KB partial
43 Partially correct 28 ms 4452 KB partial
44 Partially correct 81 ms 14196 KB partial
45 Partially correct 97 ms 14188 KB partial
46 Partially correct 72 ms 14152 KB partial
47 Partially correct 204 ms 14208 KB partial
48 Correct 4045 ms 11216 KB ok
49 Partially correct 76 ms 12840 KB partial
50 Partially correct 84 ms 13472 KB partial
51 Partially correct 15 ms 2204 KB partial
52 Partially correct 732 ms 9348 KB partial
53 Partially correct 514 ms 8488 KB partial
54 Partially correct 58 ms 8980 KB partial
55 Partially correct 144 ms 9636 KB partial
56 Partially correct 41 ms 10944 KB partial
57 Partially correct 22 ms 4416 KB partial
58 Partially correct 23 ms 4552 KB partial
59 Partially correct 21 ms 4496 KB partial
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 340 KB partial
2 Correct 0 ms 212 KB ok
3 Correct 0 ms 212 KB ok
4 Correct 0 ms 212 KB ok
5 Correct 1 ms 212 KB ok
6 Correct 0 ms 212 KB ok
7 Correct 0 ms 212 KB ok
8 Correct 1 ms 340 KB ok
9 Correct 16 ms 2200 KB ok
10 Correct 233 ms 31656 KB ok
11 Partially correct 1 ms 212 KB partial
12 Partially correct 0 ms 212 KB partial
13 Partially correct 0 ms 212 KB partial
14 Partially correct 0 ms 296 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 0 ms 340 KB partial
24 Partially correct 0 ms 212 KB partial
25 Partially correct 0 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 1 ms 340 KB partial
31 Partially correct 0 ms 340 KB partial
32 Partially correct 0 ms 340 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 0 ms 212 KB partial
38 Partially correct 0 ms 212 KB partial
39 Correct 7 ms 468 KB ok
40 Correct 28 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 0 ms 212 KB partial
47 Partially correct 26 ms 4500 KB partial
48 Partially correct 28 ms 4452 KB partial
49 Partially correct 81 ms 14196 KB partial
50 Partially correct 97 ms 14188 KB partial
51 Partially correct 72 ms 14152 KB partial
52 Partially correct 204 ms 14208 KB partial
53 Correct 4045 ms 11216 KB ok
54 Partially correct 76 ms 12840 KB partial
55 Partially correct 84 ms 13472 KB partial
56 Partially correct 15 ms 2204 KB partial
57 Partially correct 732 ms 9348 KB partial
58 Partially correct 514 ms 8488 KB partial
59 Partially correct 58 ms 8980 KB partial
60 Partially correct 144 ms 9636 KB partial
61 Partially correct 41 ms 10944 KB partial
62 Partially correct 22 ms 4416 KB partial
63 Partially correct 23 ms 4552 KB partial
64 Partially correct 21 ms 4496 KB partial
65 Partially correct 421 ms 64632 KB partial
66 Partially correct 263 ms 31648 KB partial
67 Partially correct 237 ms 31648 KB partial
68 Partially correct 1551 ms 142616 KB partial
69 Partially correct 1349 ms 142068 KB partial
70 Partially correct 1292 ms 141532 KB partial
71 Partially correct 1608 ms 142516 KB partial
72 Partially correct 3441 ms 142516 KB partial
73 Execution timed out 4552 ms 119096 KB Time limit exceeded
74 Halted 0 ms 0 KB -