#include "soccer.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2000, inf = INT_MAX;
int n, e, sum, ans; // 0 nunca usado, 1 en uso, 2 no se puede usar
vector<vector<int>> f, f2;
vector<pair<int, int>> s[2];
bool check() {
//cerr << "a" << endl;
bool ok = 1;
for (int i = 0; i < n; i++) {
int l = inf;
int r = -inf;
for (int j = 0; j < n; j++) {
if (f2[i][j] != 2) continue;
l = min(l, j);
r = max(r, j);
}
s[0][i] = make_pair(l, r);
l = inf;
r = -inf;
for (int j = 0; j < n; j++) {
if (f2[j][i] != 1) continue;
l = min(l, j);
r = max(r, j);
}
s[1][i] = make_pair(l, r);
}
//cerr << "a" << endl;
for (int x = 0; x < n; x++) {
for (int y = x+1; y < n; y++) {
pair<int, int> a = s[0][x];
pair<int, int> b = s[0][y];
if (!(a.first <= b.first && b.second <= a.second) && !(b.first <= a.first && a.second <= b.second)) {
ok = 0;
}
a = s[1][x];
b = s[1][y];
if (!(a.first <= b.first && b.second <= a.second) && !(b.first <= a.first && a.second <= b.second)) {
ok = 0;
}
}
}//cerr << "a" << endl;
return ok;
}
void gen(int idx) {
//cerr << idx << endl;
if (idx == n) {
if (!check()) return;
ans = max(ans, sum);
return;
}
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (f[idx][j] == 1) break;
f2[idx][j] = 2;
sum += j-i+1;
gen(idx+1);
sum -= j-i+1;
}
for (int j = i; j < n; j++) {
if (f[idx][j] == 1) break;
f2[idx][j] = f[idx][j];
}
}
}
int biggest_stadium(int N, vector<vector<int>> F) {
n = N;
f = f2 = F;
// se pueden coger todas las empty cells?
bool ok = 1;
e = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
e += !f[i][j];
}
}
s[0].resize(n);
s[1].resize(n);
for (int i = 0; i < n; i++) {
int l = inf;
int r = -inf;
for (int j = 0; j < n; j++) {
if (f[i][j] == 1) continue;
l = min(l, j);
r = max(r, j);
}
s[0][i] = make_pair(l, r);
for (int j = l; j <= r; j++) {
if (f[i][j] == 1) ok = 0;
}
l = inf;
r = -inf;
for (int j = 0; j < n; j++) {
if (f[j][i] == 1) continue;
l = min(l, j);
r = max(r, j);
}
s[1][i] = make_pair(l, r);
for (int j = l; j <= r; j++) {
if (f[j][i] == 1) ok = 0;
}
}
for (int x = 0; x < n; x++) {
for (int y = x+1; y < n; y++) {
pair<int, int> a = s[0][x];
pair<int, int> b = s[0][y];
if (!(a.first <= b.first && b.second <= a.second) && !(b.first <= a.first && a.second <= b.second)) {
ok = 0;
}
a = s[1][x];
b = s[1][y];
if (!(a.first <= b.first && b.second <= a.second) && !(b.first <= a.first && a.second <= b.second)) {
ok = 0;
}
}
}
if (ok) return e;
// hay solo un tree?
if (e == n*n-1) {
ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (f[i][j] == 1) {
ans = max(ans, n*n - (i+1)*(j+1));
ans = max(ans, n*n - (n-i)*(j+1));
ans = max(ans, n*n - (i+1)*(n-j));
ans = max(ans, n*n - (n-i)*(n-j));
break;
}
}
}
return ans;
}
// else
sum = ans = 0;
gen(0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
27 ms |
348 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
1 ms |
344 KB |
ok |
3 |
Correct |
1 ms |
344 KB |
ok |
4 |
Correct |
0 ms |
344 KB |
ok |
5 |
Correct |
1 ms |
344 KB |
ok |
6 |
Correct |
0 ms |
344 KB |
ok |
7 |
Correct |
1 ms |
344 KB |
ok |
8 |
Correct |
16 ms |
4184 KB |
ok |
9 |
Correct |
263 ms |
63252 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
1 ms |
344 KB |
ok |
3 |
Correct |
1 ms |
344 KB |
ok |
4 |
Incorrect |
0 ms |
348 KB |
wrong |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
27 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
1 ms |
344 KB |
ok |
4 |
Correct |
1 ms |
344 KB |
ok |
5 |
Incorrect |
0 ms |
348 KB |
wrong |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
27 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
1 ms |
344 KB |
ok |
4 |
Correct |
1 ms |
344 KB |
ok |
5 |
Correct |
0 ms |
344 KB |
ok |
6 |
Correct |
1 ms |
344 KB |
ok |
7 |
Incorrect |
0 ms |
348 KB |
wrong |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
27 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
1 ms |
344 KB |
ok |
4 |
Correct |
1 ms |
344 KB |
ok |
5 |
Correct |
0 ms |
344 KB |
ok |
6 |
Correct |
1 ms |
344 KB |
ok |
7 |
Incorrect |
0 ms |
348 KB |
wrong |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
27 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
1 ms |
344 KB |
ok |
4 |
Correct |
1 ms |
344 KB |
ok |
5 |
Correct |
0 ms |
344 KB |
ok |
6 |
Correct |
1 ms |
344 KB |
ok |
7 |
Correct |
0 ms |
344 KB |
ok |
8 |
Correct |
1 ms |
344 KB |
ok |
9 |
Correct |
16 ms |
4184 KB |
ok |
10 |
Correct |
263 ms |
63252 KB |
ok |
11 |
Correct |
1 ms |
344 KB |
ok |
12 |
Incorrect |
0 ms |
348 KB |
wrong |
13 |
Halted |
0 ms |
0 KB |
- |