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 "soccer.h"
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define LL node * 2
#define RR node * 2 + 1
#define ll long long
#define MAXN 505
const int modulo = 1e9 + 7;
const ll INF = 2e18 + 7;
int dp[2][MAXN][MAXN], prv[2][MAXN][MAXN];
int biggest_stadium(int N, vector<std::vector<int>> F)
{
int n = N;
vector<pii> v;
vector<vector<int>> pre = F;
for (int i = 0; i < n; i++)
for (int j = 1; j < n; j++) pre[i][j] += pre[i][j - 1];
for (int i = 0; i < n; i++){
for (int j = i; j < n; j++)
v.pb({i, j});
}
sort(v.begin(), v.end(), [&](pii a, pii b){
return (a.nd - a.st) < (b.nd - b.st);
});
int ans = 0;
for (int i = n - 1; i >= 0; i--){
for (auto j : v){
int l = j.st, r = j.nd;
dp[0][l][r] = 0;
int sum = pre[i][r];
if (l > 0) sum -= pre[i][l - 1];
if (sum == 0) dp[0][l][r] = (r - l + 1) + prv[0][l][r];
if (r > l) dp[0][l][r] = max(dp[0][l][r], max(dp[0][l][r - 1], dp[0][l + 1][r]));
ans = max(ans, dp[0][l][r]);
}
reverse(v.begin(), v.end());
for (auto j : v){
int l = j.st, r = j.nd;
dp[1][l][r] = 0;
int sum = pre[i][r];
if (l > 0) sum -= pre[i][l - 1];
if (sum == 0) dp[1][l][r] = (r - l + 1) + max(prv[0][l][r], prv[1][l][1]);
if (l > 0) dp[1][l][r] = max(dp[1][l][r], dp[1][l - 1][r]);
if (r < n - 1) dp[1][l][r] = max(dp[1][l][r], dp[1][l][r + 1]);
ans = max(ans, dp[1][l][r]);
}
reverse(v.begin(), v.end());
swap(dp, prv);
}
return ans;
}
/*
int main()
{
fileio();
int N;
assert(1 == scanf("%d", &N));
std::vector<std::vector<int>> F(N, std::vector<int>(N));
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
assert(1 == scanf("%d", &F[i][j]));
}
}
fclose(stdin);
int res = biggest_stadium(N, F);
printf("%d\n", res);
fclose(stdout);
return 0;
}*/
# | 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... |