// In the name of Allah
#include <bits/stdc++.h>
#include "soccer.h"
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2000 + 4;
int n; int A[maxn][maxn];
vector<pair<int, pii>> lsx;
int ind1[maxn][maxn], ind2[maxn][maxn];
pii valx[maxn][maxn]; int dp[maxn][maxn];
int solver() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (A[i][j] == 1) {
return (n * n) - (min(i + 1, n - i) * min(j + 1, n - j));
}
}
}
return n * n;
}
int solvex() {
int sm = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (A[i][j] == 0) sm++;
}
}
int lx = n, rx = -1;
for (int i = 0; i < n; i++) {
int jx = 0, tx = 0;
for (int j = 0; j < n; j++) {
if (A[i][j] != A[i][jx]) {
if (A[i][jx] == 0) {
lsx.pb(Mp(i, Mp(jx, j))); tx++;
lx = min(lx, i); rx = max(rx, i);
}
jx = j;
}
}
if (A[i][jx] == 0) {
lsx.pb(Mp(i, Mp(jx, n))); tx++;
lx = min(lx, i); rx = max(rx, i);
}
if (tx >= 2) return 0;
}
if (rx - lx + 1 != len(lsx)) return 0;
for (int i = 0; i < len(lsx); i++) {
int i1 = i - 1, i2 = i + 1;
int lx = lsx[i].S.F, rx = lsx[i].S.S;
bool flag = 1;
for (int j = 0; j < len(lsx) - 1; j++) {
if (i1 < 0) {
int l2 = lsx[i2].S.F, r2 = lsx[i2].S.S;
if (l2 < lx || r2 > rx) {
flag = 0;
break;
}
lx = l2; rx = r2; i2++;
}
else if (i2 >= len(lsx)) {
int l1 = lsx[i1].S.F, r1 = lsx[i1].S.S;
if (l1 < lx || r1 > rx) {
flag = 0;
break;
}
lx = l1; rx = r1; i1--;
}
else {
int l1 = lsx[i1].S.F, r1 = lsx[i1].S.S;
int l2 = lsx[i2].S.F, r2 = lsx[i2].S.S;
if (r1 - l1 + 1 >= r2 - l2 + 1) {
if (l1 < lx || r1 > rx) {
flag = 0;
break;
}
lx = l1; rx = r1; i1--;
}
else {
if (l2 < lx || r2 > rx) {
flag = 0;
break;
}
lx = l2; rx = r2; i2++;
}
}
}
if (flag) return sm;
}
return 0;
}
int biggest_stadium(int N, vector<vector<int>> F) {
n = N; int sm = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
A[i][j] = F[i][j];
if (A[i][j] == 0) sm++;
}
}
if (sm == n * n) return sm;
else if (sm == n * n - 1) return solver();
int x = solvex(); lsx.clear();
if (x != 0 || n > 500) return x;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (A[i][j] == 1) ind1[i][j] = j + 1;
else if (j - 1 >= 0) ind1[i][j] = ind1[i][j - 1];
else ind1[i][j] = j;
}
for (int j = n - 1; j >= 0; j--) {
if (A[i][j] == 1) ind2[i][j] = j - 1;
else if (j + 1 < n) ind2[i][j] = ind2[i][j + 1];
else ind2[i][j] = j;
}
}
int ans = 0;
for (int j = 0; j < n; j++) {
for (int ln = 1; ln <= n; ln++) {
for (int l = 0, r = ln; r <= n; l++, r++) {
if (ln == 1) {
valx[l][r] = Mp(ind1[l][j], ind2[l][j]);
if (valx[l][r].F <= valx[l][r].S) dp[l][r] = (valx[l][r].S - valx[l][r].F + 1);
else dp[l][r] = 0;
}
else {
valx[l][r] = Mp(max(ind1[l][j], valx[l + 1][r].F), min(ind2[l][j], valx[l + 1][r].S));
if (valx[l][r].F <= valx[l][r].S) dp[l][r] = max(dp[l + 1][r], dp[l][r - 1]) + (valx[l][r].S - valx[l][r].F + 1);
else dp[l][r] = 0;
}
ans = max(ans, dp[l][r]);
}
}
}
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... |