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;
static const int MAX_N = 30+5;
static int n;
static int arr[MAX_N][MAX_N];
static int pref_sum[MAX_N][MAX_N];
bool is_tree(int col, int i, int j) {
return pref_sum[col][j] - pref_sum[col][i - 1];
}
static int dp[MAX_N][MAX_N][MAX_N][MAX_N];
static int seen[MAX_N][MAX_N][MAX_N][MAX_N];
int find_dp(int top, int bot, int l, int r) {
if (r < l) return 0;
if (top == 0 && bot == n + 1) return 0;
if (seen[top][bot][l][r]) return dp[top][bot][l][r];
dp[top][bot][l][r] = max(find_dp(top, bot, l + 1, r), find_dp(top, bot, l, r - 1));
if (!is_tree(top, l, r) && top != 0) {
int new_bot = (top == bot) ? bot + 1 : bot;
dp[top][bot][l][r] = max(dp[top][bot][l][r], find_dp(top - 1, new_bot, l, r) + r - l + 1);
}
if (!is_tree(bot, l, r) && bot != n + 1) {
int new_top = (top == bot) ? top - 1 : top;
dp[top][bot][l][r] = max(dp[top][bot][l][r], find_dp(new_top, bot + 1, l, r) + r - l + 1);
}
seen[top][bot][l][r] = true;
//cout << top << " " << bot << " " << l << " " << r << " " << dp[top][bot][l][r] << '\n';
return dp[top][bot][l][r];
}
int biggest_stadium(int xn, vector<vector<int>> xarr) {
n = xn;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
arr[i + 1][j + 1] = xarr[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
pref_sum[i][j] = pref_sum[i][j - 1] + arr[i][j];
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans = max(ans, find_dp(i, i, 1, n));
}
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... |