Submission #1065085

# Submission time Handle Problem Language Result Execution time Memory
1065085 2024-08-18T22:27:40 Z aaaaaarroz Rectangles (IOI19_rect) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll count_rectangles(vector<vector<int>>a) {
    int n = a.size();
    int m = a[0].size();
    vector<vector<int>> max_row(n, vector<int>(m, 0));
    vector<vector<int>> max_col(n, vector<int>(m, 0));

    // Precomputar los máximos en cada fila
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j < m - 1; ++j) {
            max_row[i][j] = max(a[i][j], max_row[i][j - 1]);
        }
    }

    // Precomputar los máximos en cada columna
    for (int j = 0; j < m; ++j) {
        for (int i = 1; i < n - 1; ++i) {
            max_col[i][j] = max(a[i][j], max_col[i - 1][j]);
        }
    }

    ll rec = 0;
    // Verificar todos los posibles rectángulos
    for (int i = 1; i < n - 1; ++i) {
        for (int j = i + 1; j < n - 1; ++j) {
            for (int k = 1; k < m - 1; ++k) {
                for (int l = k + 1; l < m - 1; ++l) {
                    bool valid = true;

                    // Verificar las celdas en las filas superior e inferior
                    for (int r = i; r <= j; ++r) {
                        if (max_col[r][k] < a[r][k - 1] || max_col[r][l] < a[r][l + 1]) {
                            valid = false;
                            break;
                        }
                    }
                    if (!valid) continue;

                    // Verificar las celdas en las columnas izquierda y derecha
                    for (int c = k; c <= l; ++c) {
                        if (max_row[i][c] < a[i - 1][c] || max_row[j][c] < a[j + 1][c]) {
                            valid = false;
                            break;
                        }
                    }

                    if (valid) {
                        ++rec;
                    }
                }
            }
        }
    }

    return rec;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -