#include "soccer.h"
#include "bits/stdc++.h"
using namespace std;
const int inf = 1e9;
using ll = long long;
void maxs(short &a, short b) { a = max(a, b); }
int biggest_stadium(int n, std::vector<std::vector<int>> f) {
vector<ll> out(n * n);
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) f[i][j] = !f[i][j];
const vector<int> dx = {1, -1, 0, 0};
const vector<int> dy = {0, 0, 1, -1};
auto get_dist = [&](int ri, int rj) -> vector<int> {
vector<int> dist(n * n, inf);
dist[ri * n + rj] = 0;
queue<pair<int, int>> q;
q.emplace(ri, rj);
auto add = [&](int i, int j, int d) -> void {
if (dist[i * n + j] > d) {
dist[i * n + j] = d;
q.emplace(i, j);
}
};
while (!q.empty()) {
auto [i, j] = q.front(); q.pop();
for (int k = i; k >= 0 and f[k][j]; k--) add(k, j, dist[i * n + j] + 1);
for (int k = i; k < n and f[k][j]; k++) add(k, j, dist[i * n + j] + 1);
for (int k = j; k >= 0 and f[i][k]; k--) add(i, k, dist[i * n + j] + 1);
for (int k = j; k < n and f[i][k]; k++) add(i, k, dist[i * n + j] + 1);
}
return dist;
};
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int id = i * n + j;
if (f[i][j] == 0) continue;
auto dist = get_dist(i, j);
for (int k = 0; k < n * n; k++) if (dist[k] <= 2) out[id] |= 1ll << k;
}
}
const int sz1 = n * n / 2, sz2 = n * n - n * n / 2;
vector<short> mx(1 << sz1);
for (ll bt = 0; bt < (1 << sz1); bt++) {
ll act = (1ll << 49) - 1;
for (int i = 0; i < sz1; i++) if (bt >> i & 1) act &= out[i];
if ((act & bt) == bt) mx[bt] = __builtin_popcountll(bt);
for (int i = 0; i < sz1; i++) {
if (!(bt >> i & 1)) maxs(mx[bt | (1 << i)], mx[bt]);
}
}
int ans = 0;
for (ll bt = 0; bt < (1 << sz2); bt++) {
ll act = (1ll << 49) - 1;
for (int i = 0; i < sz2; i++) {
if (bt >> i & 1) act &= out[i + sz1];
}
if (((act >> sz1) & bt) != bt) continue;
int bt2 = 0;
for (int i = 0; i < sz1; i++) {
if (!(act >> i & 1)) continue;
if (((out[i] >> sz1) & bt) == bt) bt2 |= 1 << i;
}
ans = max(ans, __builtin_popcountll(bt) + mx[bt2]);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |