#include "soccer.h"
using namespace std;
typedef pair<int, int> pi;
vector<vector<int>> grid;
vector<pi> row_range;
vector<vector<int>> rotated;
vector<pi> column_range;
bool check_row(vector<int>& r, vector<pi>& range, int pos)
{
range[pos] = {-1, -1};
for (int i = 0; i < r.size(); i++) {
if (r[i] == 0) {
if (range[pos].second != -1) {
return false;
}
if (range[pos].first == -1) {
range[pos].first = i;
}
}
else {
if (range[pos].first != -1 && range[pos].second == -1) {
range[pos].second = i;
}
}
}
if (range[pos].second == -1) {
range[pos].second = r.size();
}
return true;
}
bool includes(pi a, pi b)
{
if (b.first == -1) {
return true;
}
return a.first <= b.first && a.second >= b.second;
}
int biggest_stadium(int N, std::vector<std::vector<int>> F)
{
grid.resize(N, vector<int>(N));
rotated.resize(N, vector<int>(N));
column_range.resize(N);
row_range.resize(N);
int tot = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
grid[i][j] = F[i][j];
rotated[j][i] = F[i][j];
tot += !F[i][j];
}
}
bool good = true;
for (int i = 0; i < N; i++) {
good = good && check_row(grid[i], row_range, i) && check_row(rotated[i], column_range, i);
}
if (!good) {
return 0;
}
// for (int j = 0; j < N; j++) {
// if (column_range[j].first == -1) {
// continue;
// }
// pi propagate_range = {-1, -1};
// for (int i = 0; i < column_range[j].second; i++) {
// if (!includes(row_range[i], propagate_range)) {
// return 0;
// }
// if (row_range[i].first != -1) {
// if (F[i][j]) {
// propagate_range = row_range[i];
// }
// }
// }
// propagate_range = {-1, -1};
// for (int i = N - 1; i >= column_range[j].first; i--) {
// if (!includes(row_range[i], propagate_range)) {
// return 0;
// }
// if (row_range[i].first != -1) {
// if (F[i][j]) {
// propagate_range = row_range[i];
// }
// }
// }
// }
pi cur = {-1, -1};
for (int r = 0; r < N; r++) {
if (row_range[r].first != -1) {
if (includes(row_range[r], cur)) {
cur = row_range[r];
}
else if (!includes(cur, row_range[r])) {
return 0;
}
}
}
return tot;
}
Compilation message
soccer.cpp: In function 'bool check_row(std::vector<int>&, std::vector<std::pair<int, int> >&, int)':
soccer.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < r.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
partial |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Partially correct |
0 ms |
348 KB |
partial |
7 |
Partially correct |
1 ms |
348 KB |
partial |
8 |
Partially correct |
14 ms |
4236 KB |
partial |
9 |
Partially correct |
243 ms |
63248 KB |
partial |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Partially correct |
1 ms |
348 KB |
partial |
4 |
Partially correct |
0 ms |
348 KB |
partial |
5 |
Incorrect |
0 ms |
348 KB |
wrong |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
partial |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Partially correct |
1 ms |
348 KB |
partial |
5 |
Partially correct |
0 ms |
348 KB |
partial |
6 |
Incorrect |
0 ms |
348 KB |
wrong |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
partial |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Partially correct |
1 ms |
348 KB |
partial |
7 |
Partially correct |
0 ms |
348 KB |
partial |
8 |
Incorrect |
0 ms |
348 KB |
wrong |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
partial |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Partially correct |
1 ms |
348 KB |
partial |
7 |
Partially correct |
0 ms |
348 KB |
partial |
8 |
Incorrect |
0 ms |
348 KB |
wrong |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
partial |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Partially correct |
0 ms |
348 KB |
partial |
8 |
Partially correct |
1 ms |
348 KB |
partial |
9 |
Partially correct |
14 ms |
4236 KB |
partial |
10 |
Partially correct |
243 ms |
63248 KB |
partial |
11 |
Partially correct |
1 ms |
348 KB |
partial |
12 |
Partially correct |
0 ms |
348 KB |
partial |
13 |
Incorrect |
0 ms |
348 KB |
wrong |
14 |
Halted |
0 ms |
0 KB |
- |