Submission #1078309

# Submission time Handle Problem Language Result Execution time Memory
1078309 2024-08-27T15:08:21 Z PanosPask Soccer Stadium (IOI23_soccer) C++17
0 / 100
0 ms 348 KB
#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 = i;
            }
        }
    }

    return true;
}

bool included(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++) {
        pi propagate_range = {-1, -1};
        for (int i = 0; i <= column_range[j].second; i++) {
            if (!included(row_range[i], propagate_range)) {
                return 0;
            }

            if (row_range[i].first != -1 && column_range[j].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 (!included(row_range[i], propagate_range)) {
                return 0;
            }

            if (row_range[i].first != -1 && column_range[j].first != -1) {
                if (F[i][j]) {
                    propagate_range = row_range[i];
                }
            }
        }
    }

    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++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 344 KB partial
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB wrong
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB wrong
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 344 KB partial
2 Incorrect 0 ms 348 KB wrong
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 344 KB partial
2 Incorrect 0 ms 348 KB wrong
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 344 KB partial
2 Incorrect 0 ms 348 KB wrong
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 344 KB partial
2 Incorrect 0 ms 348 KB wrong
3 Halted 0 ms 0 KB -