#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, bool hrc) {
y = y_;
x = x_;
isDirOrizontal = isdo;
haveRemChange = hrc;
}
};
int viz[maxn+5][maxn+5][2]; ///punct, directie = max schimbari ramase.
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++) {
viz[i][j][0] = viz[i][j][1] = -1;
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;
}
}
std::queue<Pos> qu;
viz[p.second.first][p.second.second][0] = 1;
qu.emplace(p.second.first, p.second.second, false, true);
viz[p.second.first][p.second.second][1] = 1;
qu.emplace(p.second.first, p.second.second, true, true);
while (!qu.empty()) { ///daca nu merge campul, ma astept sa crape din cauza unui patrat cu nr mic de vecini.
auto now = qu.front();
qu.pop();
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;
qu.emplace(now.y, now.x, now.isDirOrizontal, now.haveRemChange);
}
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:109:12: warning: unused variable 'z' [-Wunused-variable]
109 | int i, j, z;
| ^
soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:150:12: warning: unused variable 'z' [-Wunused-variable]
150 | int i, j, z;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
partial |
# |
Verdict |
Execution time |
Memory |
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 |
0 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 |
15 ms |
2204 KB |
ok |
9 |
Correct |
232 ms |
31644 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 |
0 ms |
212 KB |
partial |
4 |
Partially correct |
0 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 |
Correct |
1 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 |
0 ms |
212 KB |
partial |
2 |
Correct |
0 ms |
212 KB |
ok |
3 |
Correct |
0 ms |
212 KB |
ok |
4 |
Partially correct |
0 ms |
212 KB |
partial |
5 |
Partially correct |
0 ms |
212 KB |
partial |
6 |
Partially correct |
0 ms |
212 KB |
partial |
7 |
Partially correct |
1 ms |
212 KB |
partial |
8 |
Partially correct |
0 ms |
212 KB |
partial |
9 |
Correct |
1 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 |
212 KB |
partial |
16 |
Partially correct |
0 ms |
212 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 |
212 KB |
ok |
21 |
Correct |
0 ms |
212 KB |
ok |
22 |
Partially correct |
0 ms |
212 KB |
partial |
23 |
Partially correct |
0 ms |
340 KB |
partial |
24 |
Partially correct |
1 ms |
212 KB |
partial |
25 |
Partially correct |
0 ms |
212 KB |
partial |
26 |
Partially correct |
0 ms |
212 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
212 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 |
0 ms |
212 KB |
ok |
6 |
Partially correct |
0 ms |
212 KB |
partial |
7 |
Partially correct |
0 ms |
212 KB |
partial |
8 |
Partially correct |
0 ms |
212 KB |
partial |
9 |
Partially correct |
1 ms |
212 KB |
partial |
10 |
Partially correct |
0 ms |
212 KB |
partial |
11 |
Correct |
1 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 |
212 KB |
partial |
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 |
Partially correct |
0 ms |
212 KB |
partial |
22 |
Correct |
0 ms |
212 KB |
ok |
23 |
Correct |
0 ms |
212 KB |
ok |
24 |
Partially correct |
0 ms |
212 KB |
partial |
25 |
Partially correct |
0 ms |
340 KB |
partial |
26 |
Partially correct |
1 ms |
212 KB |
partial |
27 |
Partially correct |
0 ms |
212 KB |
partial |
28 |
Partially correct |
0 ms |
212 KB |
partial |
29 |
Partially correct |
0 ms |
212 KB |
partial |
30 |
Partially correct |
1 ms |
340 KB |
partial |
31 |
Partially correct |
1 ms |
340 KB |
partial |
32 |
Partially correct |
0 ms |
212 KB |
partial |
33 |
Partially correct |
0 ms |
212 KB |
partial |
34 |
Correct |
1 ms |
340 KB |
ok |
35 |
Correct |
3 ms |
340 KB |
ok |
36 |
Partially correct |
0 ms |
340 KB |
partial |
37 |
Partially correct |
1 ms |
340 KB |
partial |
38 |
Partially correct |
0 ms |
340 KB |
partial |
39 |
Partially correct |
1 ms |
340 KB |
partial |
40 |
Partially correct |
1 ms |
448 KB |
partial |
41 |
Partially correct |
0 ms |
212 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
212 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 |
0 ms |
212 KB |
ok |
6 |
Partially correct |
0 ms |
212 KB |
partial |
7 |
Partially correct |
0 ms |
212 KB |
partial |
8 |
Partially correct |
0 ms |
212 KB |
partial |
9 |
Partially correct |
1 ms |
212 KB |
partial |
10 |
Partially correct |
0 ms |
212 KB |
partial |
11 |
Correct |
1 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 |
212 KB |
partial |
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 |
Partially correct |
0 ms |
212 KB |
partial |
22 |
Correct |
0 ms |
212 KB |
ok |
23 |
Correct |
0 ms |
212 KB |
ok |
24 |
Partially correct |
0 ms |
212 KB |
partial |
25 |
Partially correct |
0 ms |
340 KB |
partial |
26 |
Partially correct |
1 ms |
212 KB |
partial |
27 |
Partially correct |
0 ms |
212 KB |
partial |
28 |
Partially correct |
0 ms |
212 KB |
partial |
29 |
Partially correct |
0 ms |
212 KB |
partial |
30 |
Partially correct |
1 ms |
340 KB |
partial |
31 |
Partially correct |
1 ms |
340 KB |
partial |
32 |
Partially correct |
0 ms |
212 KB |
partial |
33 |
Partially correct |
0 ms |
212 KB |
partial |
34 |
Correct |
1 ms |
340 KB |
ok |
35 |
Correct |
3 ms |
340 KB |
ok |
36 |
Partially correct |
0 ms |
340 KB |
partial |
37 |
Partially correct |
1 ms |
340 KB |
partial |
38 |
Partially correct |
0 ms |
340 KB |
partial |
39 |
Partially correct |
1 ms |
340 KB |
partial |
40 |
Partially correct |
1 ms |
448 KB |
partial |
41 |
Partially correct |
0 ms |
212 KB |
partial |
42 |
Partially correct |
26 ms |
4416 KB |
partial |
43 |
Partially correct |
29 ms |
4456 KB |
partial |
44 |
Partially correct |
71 ms |
12164 KB |
partial |
45 |
Partially correct |
75 ms |
12176 KB |
partial |
46 |
Partially correct |
67 ms |
12144 KB |
partial |
47 |
Partially correct |
88 ms |
12268 KB |
partial |
48 |
Correct |
4046 ms |
9200 KB |
ok |
49 |
Partially correct |
55 ms |
10904 KB |
partial |
50 |
Partially correct |
49 ms |
11548 KB |
partial |
51 |
Partially correct |
16 ms |
2208 KB |
partial |
52 |
Partially correct |
83 ms |
7436 KB |
partial |
53 |
Partially correct |
80 ms |
6520 KB |
partial |
54 |
Partially correct |
27 ms |
6992 KB |
partial |
55 |
Partially correct |
37 ms |
7656 KB |
partial |
56 |
Partially correct |
41 ms |
9008 KB |
partial |
57 |
Partially correct |
24 ms |
4424 KB |
partial |
58 |
Partially correct |
29 ms |
4496 KB |
partial |
59 |
Partially correct |
31 ms |
4492 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
212 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 |
0 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 |
15 ms |
2204 KB |
ok |
10 |
Correct |
232 ms |
31644 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 |
Partially correct |
1 ms |
212 KB |
partial |
15 |
Partially correct |
0 ms |
212 KB |
partial |
16 |
Correct |
1 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 |
212 KB |
partial |
23 |
Partially correct |
0 ms |
212 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 |
212 KB |
ok |
28 |
Correct |
0 ms |
212 KB |
ok |
29 |
Partially correct |
0 ms |
212 KB |
partial |
30 |
Partially correct |
0 ms |
340 KB |
partial |
31 |
Partially correct |
1 ms |
212 KB |
partial |
32 |
Partially correct |
0 ms |
212 KB |
partial |
33 |
Partially correct |
0 ms |
212 KB |
partial |
34 |
Partially correct |
0 ms |
212 KB |
partial |
35 |
Partially correct |
1 ms |
340 KB |
partial |
36 |
Partially correct |
1 ms |
340 KB |
partial |
37 |
Partially correct |
0 ms |
212 KB |
partial |
38 |
Partially correct |
0 ms |
212 KB |
partial |
39 |
Correct |
1 ms |
340 KB |
ok |
40 |
Correct |
3 ms |
340 KB |
ok |
41 |
Partially correct |
0 ms |
340 KB |
partial |
42 |
Partially correct |
1 ms |
340 KB |
partial |
43 |
Partially correct |
0 ms |
340 KB |
partial |
44 |
Partially correct |
1 ms |
340 KB |
partial |
45 |
Partially correct |
1 ms |
448 KB |
partial |
46 |
Partially correct |
0 ms |
212 KB |
partial |
47 |
Partially correct |
26 ms |
4416 KB |
partial |
48 |
Partially correct |
29 ms |
4456 KB |
partial |
49 |
Partially correct |
71 ms |
12164 KB |
partial |
50 |
Partially correct |
75 ms |
12176 KB |
partial |
51 |
Partially correct |
67 ms |
12144 KB |
partial |
52 |
Partially correct |
88 ms |
12268 KB |
partial |
53 |
Correct |
4046 ms |
9200 KB |
ok |
54 |
Partially correct |
55 ms |
10904 KB |
partial |
55 |
Partially correct |
49 ms |
11548 KB |
partial |
56 |
Partially correct |
16 ms |
2208 KB |
partial |
57 |
Partially correct |
83 ms |
7436 KB |
partial |
58 |
Partially correct |
80 ms |
6520 KB |
partial |
59 |
Partially correct |
27 ms |
6992 KB |
partial |
60 |
Partially correct |
37 ms |
7656 KB |
partial |
61 |
Partially correct |
41 ms |
9008 KB |
partial |
62 |
Partially correct |
24 ms |
4424 KB |
partial |
63 |
Partially correct |
29 ms |
4496 KB |
partial |
64 |
Partially correct |
31 ms |
4492 KB |
partial |
65 |
Partially correct |
444 ms |
64692 KB |
partial |
66 |
Partially correct |
267 ms |
31752 KB |
partial |
67 |
Partially correct |
243 ms |
31760 KB |
partial |
68 |
Partially correct |
1348 ms |
134656 KB |
partial |
69 |
Partially correct |
1209 ms |
134280 KB |
partial |
70 |
Partially correct |
1119 ms |
133692 KB |
partial |
71 |
Partially correct |
1366 ms |
134884 KB |
partial |
72 |
Partially correct |
1528 ms |
134744 KB |
partial |
73 |
Execution timed out |
4550 ms |
111248 KB |
Time limit exceeded |
74 |
Halted |
0 ms |
0 KB |
- |