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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int biggest_stadium(int n, vector<vector<int>> grid) {
vector<vector<int>> dist_up(n, vector<int>(n, 0)), dist_down(n, vector<int>(n, 0));
for (int i = 0; i < n; i++) {
dist_up[0][i] = 1 - grid[0][i];
dist_down[n - 1][i] = 1 - grid[n - 1][i];
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < n; j++) {
dist_up[i][j] = grid[i][j] ? 0 : 1 + dist_up[i - 1][j];
dist_down[n - i - 1][j] = grid[n - i - 1][j] ? 0 : 1 + dist_down[n - i][j];
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (grid[i][j]) { continue; }
int dist = dist_up[i][j];
int sub_ans = dist;
for (int x = j - 1; dist && x >= 0; x--) {
dist = min(dist_up[i][x], dist);
sub_ans += dist;
}
for (int x = j + 1; dist && x < n; x++) {
dist = min(dist_up[i][x], dist);
sub_ans += dist;
}
dist = dist_down[i][j] - 1;
sub_ans += dist;
for (int x = j - 1; dist && x >= 0; x--) {
dist = min(dist_down[i][x] - 1, dist);
if (dist < 0) { break; }
sub_ans += dist;
}
for (int x = j + 1; dist && x < n; x++) {
dist = min(dist_down[i][x] - 1, dist);
if (dist < 0) { break; }
sub_ans += dist;
}
ans = max(ans, sub_ans);
}
}
return ans;
}
// int main() {
// cout << biggest_stadium(5, { {0, 0, 0, 0, 0},
// {1, 0, 0, 0, 0},
// {0, 0, 0, 0, 0},
// {0, 0, 0, 0, 0},
// {0, 0, 1, 0, 0} }) << '\n';
// }
# | 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... |