# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1122343 | deera | Soccer Stadium (IOI23_soccer) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
struct Point {
int x, y;
Point(int x, int y): x(x), y(y) {}
};
int biggest_stadium(int N, vector<vector<int>> F) {
int num_trees = 0;
for (auto i: F) for (int j: i) num_trees += j;
if (num_trees == 0) {
return N*N;
}
if (num_trees == 1) {
int x, y;
for (int i = 0; i < N; i++) for (int j = 0; j < N; j++)
if (F[i][j] == 1) {
x = i, y = j;
break;
}
return N*N - min(x + 1, N - x) * min(y + 1, N - y);
}
for (int i = 0; i < N; i++) {
F[i].insert(F[i].begin(), 1);
F[i].push_back(1);
}
F.insert(F.begin(), vector<int>(N + 2, 1));
F.push_back(vector<int>(N + 2, 1));
N += 2;
auto valid = [&](int n) {
return n >= 0 && n < N;
};
int dirs[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
vector<vector<bool>> seen(N, vector<bool>(N, false));
queue<tuple<int, int, bool>> q;
bool f1 = false, f0 = false;
for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
if (!f1 && F[i][j] == 1)
q.push({i, j, true}), f1 = true;
if (!f0 && F[i][j] == 0)
q.push({i, j, false}), f0 = true;
}
while (!q.empty()) {
auto [x, y, t] = q.front();
q.pop();
seen[x][y] = true;
for (auto [dx, dy]: dirs) {
int nx = x + dx, ny = y + dy;
if (valid(nx) && valid(ny) && !seen[nx][ny] && F[nx][ny] == t)
q.push({nx, ny, t});
}
}
for (int i = 0; i < N; i++) for (int j = 0; j < N; j++)
if (!seen[i][j]) return 0; // islands!!!
// most extreme zeros
// Point minx = {N, N}, maxx = {0, 0}, miny = {N, N}, maxy = {0, 0};
// for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
// if (F[i][j] == 0) {
// if (i < minx.x) minx = {i, j};
// if (i > maxx.x) maxx = {i, j};
// if (j < miny.y) miny = {i, j};
// if (j > maxy.y) maxy = {i, j};
// }
// }
// Point points[4] = {minx, maxx, miny, maxy};
vector<Point> points;
for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
// check if it is an empty corner
if (F[i][j] == 0) {
int corners[4][2][2] = {
{{1, 0}, {0, 1}},
{{1, 0}, {0, -1}},
{{-1, 0}, {0, 1}},
{{-1, 0}, {0, -1}}
};
for (auto [a, b]: corners) {
int ax = i + a[0], ay = j + a[1];
int bx = i + b[0], by = j + b[1];
if (valid(ax) && valid(ay) && valid(bx) && valid(by) && F[ax][ay] == 1 && F[bx][by] == 1) {
points.push_back(Point(i, j));
break;
}
}
}
}
for (int i = 0; i < points.size(); i++) for (int j = i + 1; j < points.size(); j++) {
if (i == j) continue;
if (F[points[i].x][points[j].y] + F[points[j].x][points[i].y] == 2) {
return 0; // 3 or more kicks
}
}
int zeros = 0;
for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
if (F[i][j] == 0) zeros++;
}
return zeros;
}
signed main() {
int o = biggest_stadium(3,
{
{1, 0, 0},
{0, 0, 1},
{1, 0, 1}
}
);
cout << o << endl;
}