Submission #841578

# Submission time Handle Problem Language Result Execution time Memory
841578 2023-09-01T17:29:50 Z I_love_Hoang_Yen Soccer Stadium (IOI23_soccer) C++17
0 / 100
1 ms 348 KB
#include "soccer.h"
#include <bits/stdc++.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, -1};

    // From biggest row, each row should contains the row next to (& further away from) it
    int largest_row = max_element(rows.begin(), rows.end()) - rows.begin();
    for (int i = largest_row; i > 0; --i) {
        if (!rows[i].contains(rows[i-1])) return {false, -1};
    }
    for (int i = largest_row; i + 1 < (int) rows.size(); ++i) {
        if (!rows[i].contains(rows[i+1])) return {false, -1};
    }

    // 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, -1};
    }

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