이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "soccer.h"
using namespace std;
struct Row {
int first, last;
int cnt() const {
return last - first + 1;
}
bool contains(const Row& b) const {
return first <= b.first && b.last <= last;
}
bool operator < (const Row& b) const {
return cnt() > b.cnt();
}
};
pair<bool, int> subtask_25p(int n, const vector<vector<int>>& forest) {
int cnt_row = 0; // number of non-empty rows
int first_row = n, last_row = -1;
int total = 0;
vector<Row> rows;
for (int r = 0; r < n; ++r) {
int cnt = 0; // number of empty cells
int first = n, last = -1; // all empty cells should be in [first, last]
for (int c = 0; c < n; ++c) {
if (forest[r][c] == 0) {
++total;
++cnt;
if (first == n) first = c;
last = c;
}
}
// ignore empty rows
if (cnt == 0) continue;
if (first_row == n) first_row = r;
last_row = r;
++cnt_row;
// Condition: in each row, there should be only 1 sequence of 0
if (cnt != last - first + 1) return {false, -1};
rows.push_back(Row{first, last});
}
// Condition: all rows with empty cells must be consecutive
if (cnt_row != last_row - first_row + 1) return {false, -2};
// From biggest row, each row should contains the row next to (& further away from) it
int largest_row = min_element(rows.begin(), rows.end()) - rows.begin();
for (int i = largest_row; i > 0; --i) {
if (!rows[i].contains(rows[i-1])) return {false, -3};
}
for (int i = largest_row; i + 1 < (int) rows.size(); ++i) {
if (!rows[i].contains(rows[i+1])) return {false, -4};
}
// In decreasing order of size, row should contains next row
sort(rows.begin(), rows.end());
for (int i = 0; i + 1 < (int) rows.size(); ++i) {
if (!rows[i].contains(rows[i+1])) return {false, -5};
}
return {true, total};
}
int biggest_stadium(int n, vector<vector<int>> forest) {
auto [is_good, cnt] = subtask_25p(n, forest);
if (is_good) return cnt;
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... |