#include "soccer.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ii = pair<int, int>;
vector<ii> Sol;
int sum(int lin, int l, int r, vector<vi> &SL) {
if(!l) return SL[lin][r];
return SL[lin][r] - SL[lin][l - 1];
}
bool ok(int l1, int r1, int l2, int r2) {
if(l1 > l2) {
swap(l1, l2);
swap(r1, r2);
}
if(r2 <= r1) return 1;
return l2 == l1;
}
int reg, nrsol;
bool ok2(int a, int b, int c, int d, int i, int j) {
if(a < c && i < c) return 0;
if(d < b && d < j) return 0;
return 1;
}
void gen(int n, int lin, vector<vi> &SL, int rec) {
reg = max(reg, rec);
// if(rec == 19) {
// for(auto [a, b] : Sol)
// cout << a << " " << b << "\n";
// cout << "\n\n";
// }
++nrsol;
if(lin == n)
return;
for(int i = 0; i < n; ++i) {
for(int j = i; j < n; ++j) {
if(!sum(lin, i, j, SL)) {
bool cont = 1;
if(!Sol.empty()) {
auto [st, dr] = Sol.back();
for(int it = Sol.size() - 1; it >= 0; --it) {
cont &= ok2(Sol[it].first, Sol[it].second, st, dr, i, j);
st = max(st, Sol[it].first);
dr = min(dr, Sol[it].second);
}
if(!cont) continue;
}
for(auto it : Sol)
cont &= ok(it.first, it.second, i, j);
if(cont) {
Sol.push_back({i, j});
gen(n, lin + 1, SL, rec + j - i + 1);
Sol.pop_back();
}
}
}
}
}
int biggest_stadium(int n, std::vector<std::vector<int>> F) {
vector<vi> S(n, vi(n, 0)), St(n, vi(n, 0)), Dr(n, vi(n, 0)), Up(n, vi(n, 0)), Down(n, vi(n, 0));
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
S[i][j] = !F[i][j];
if(i) S[i][j] += S[i - 1][j];
if(j) S[i][j] += S[i][ j - 1 ];
if(i && j) S[i][j] -= S[i - 1][j - 1];
}
}
for(int i = 0; i < n; ++i) {
St[i][0] = !F[i][0];
for(int j = 1; j < n; ++j) {
St[i][j] = F[i][j] ? 0 : (1 + St[i][j - 1]);
}
Dr[i][n - 1] = !F[i][n - 1];
for(int j = n - 2; j >= 0; --j)
Dr[i][j] = F[i][j] ? 0 : (1 + Dr[i][j + 1]);
}
for(int j = 0; j < n; ++j) {
Up[0][j] = !F[0][j];
for(int i = 1; i < n; ++i) {
Up[i][j] = F[i][j] ? 0 : (1 + Up[i - 1][j]);
}
Down[n - 1][j] = !F[n - 1][j];
for(int i = n - 2; i >= 0; --i) {
Down[i][j] = F[i][j] ? 0 : (1 + Down[i + 1][j]);
}
}
int xmin = n, xmax = 0, ymin = n, ymax = 0;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j)
if(!F[i][j]) {
xmin = min(xmin, i);
ymin = min(ymin, j);
xmax = max(xmax, i);
ymax = max(ymax, j);
}
}
int ok1 = 1;
auto sum = [&](int x1, int y1, int x2, int y2) {
int re = S[x2][y2];
if(x1) re -= S[x1 - 1][y1];
if(y1) re -= S[x1][y1 - 1];
if(x1 && y1) re += S[x1 - 1][y1 - 1];
return re;
};
vector<vi> SL(n, vi(n, 0));
int nrtree = 0;
for(int i = 0; i < n; ++i) {
SL[i][0] = F[i][0];
for(auto it : F[i])
nrtree += it;
for(int j = 1; j < n; ++j)
SL[i][j] = SL[i][j - 1] + F[i][j];
}
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
if(!F[i][j]) {
int xmi = i - Up[i][j] + 1, xma = i + Down[i][j] - 1;
int ymi = j - St[i][j] + 1, yma = j + Dr[i][j] - 1;
ok1 &= (sum(xmi, ymi, xma, yma) == (n * n - nrtree));
}
}
}
if(ok1) return n * n - nrtree;
if(!nrtree) return n * n;
return n * n - nrtree + 1;
reg = 0;
gen(n, 0, SL, 0);
//cout << nrsol << " - \n";
return reg;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
wrong |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
wrong |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
partial |
2 |
Incorrect |
0 ms |
348 KB |
wrong |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
partial |
2 |
Incorrect |
0 ms |
348 KB |
wrong |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
partial |
2 |
Incorrect |
0 ms |
348 KB |
wrong |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
partial |
2 |
Incorrect |
0 ms |
348 KB |
wrong |
3 |
Halted |
0 ms |
0 KB |
- |