Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 1 KBi |
#2 |
Correcto
|
0.005 s | 1 KBi |
#3 |
Correcto
|
0.005 s | 1 KBi |
#4 |
Correcto
|
0.005 s | 1 KBi |
#5 |
Correcto
|
0.006 s | 1 KBi |
#6 |
Correcto
|
0.005 s | 1 KBi |
#7 |
Correcto
|
0.006 s | 4 KBi |
#8 |
Correcto
|
0.047 s | 1 KBi |
#9 |
Correcto
|
0.053 s | 3 KBi |
#10 |
Correcto
|
0.046 s | 1 KBi |
#11 |
Correcto
|
0.05 s | 1 KBi |
#12 |
Correcto
|
0.044 s | 1 KBi |
#13 |
Correcto
|
0.044 s | 1 KBi |
#14 |
Correcto
|
0.052 s | 66 KBi |
#15 |
Correcto
|
0.045 s | 1 KBi |
#16 |
Correcto
|
0.04 s | 1 KBi |
#17 |
Correcto
|
0.047 s | 1 KBi |
#18 |
Correcto
|
0.039 s | 1 KBi |
#include <iostream> #include <vector> #include <limits> using namespace std; int main() { int rows, cols; cin >> rows >> cols; vector<vector<int>> m(rows, vector<int>(cols)); for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { cin >> m[r][c]; if (r - 1 >= 0) m[r][c] += m[r-1][c]; if (c - 1 >= 0) m[r][c] += m[r][c-1]; if (r - 1 >= 0 and c - 1 >= 0) m[r][c] -= m[r-1][c-1]; } } int answer = numeric_limits<int>::min(); // O(n^6) for (int r0 = 0; r0 < rows; r0++) { for (int c0 = 0; c0 < cols; c0++) { // La esquina superior izquierda de la submatriz es (r0, c0) for (int r1 = r0; r1 < rows; r1++) { for (int c1 = c0; c1 < cols; c1++) { // La esquina inferior derecha de la submatriz es (r1, c1) // Encontrar la suma de la submatriz delimitada por (r0, c0) y (r1, c1) int sum = m[r1][c1]; if (r0-1 >= 0) sum -= m[r0-1][c1]; if (c0-1 >= 0) sum -= m[r1][c0-1]; if (r0-1 >= 0 and c0-1 >= 0) sum += m[r0-1][c0-1]; answer = max(answer, sum); } } } } cout << answer << endl; return 0; }