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;
bool inside(pair<int, int> a, pair<int, int> b) {
return b.first <= a.first && a.second <= b.second;
}
int biggest_stadium(int N, std::vector<std::vector<int>> F)
{
pair<int, int> inv = make_pair(-1, -1);
vector<pair<int, int>> border(N, inv);
int ans = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (F[i][j] == 0) {
++ans;
if (j == 0 || F[i][j - 1] == 1) {
if (border[i] != inv) {
return 0;
}
border[i].first = j;
}
border[i].second = j;
}
}
}
int mx = 0;
for (int i = 0; i < N; ++i) {
if (border[i] != inv && border[i].second - border[i].first
>= border[mx].second - border[mx].first) {
mx = i;
}
}
int l = mx - 1;
int r = mx + 1;
pair<int, int> now = border[mx];
while ((l >= 0 && border[l] != inv) || (r < N && border[r] != inv)) {
if (l < 0 || border[l] == inv) {
if (!inside(border[r], now)) {
return 0;
}
now = border[r];
++r;
} else if (r >= N || border[r] == inv) {
if (!inside(border[l], now)) {
return 0;
}
now = border[l];
--l;
} else {
if (border[r].second - border[r].first >= border[l].second - border[l].first) {
if (!inside(border[r], now)) {
return 0;
}
now = border[r];
++r;
} else {
if (!inside(border[l], now)) {
return 0;
}
now = border[l];
--l;
}
}
}
for (int i = 0; i < N; ++i) {
if (i < l || i > r) {
if (border[i] != inv) {
return 0;
}
}
}
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... |