Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 1 KBi |
#2 |
Correcto
|
0.005 s | 2 KBi |
#3 |
Correcto
|
0.004 s | 1 KBi |
#4 |
Correcto
|
0.006 s | 1 KBi |
#5 |
Correcto
|
0.004 s | 1 KBi |
#6 |
Correcto
|
0.005 s | 2 KBi |
#7 |
Correcto
|
0.005 s | 1 KBi |
#8 |
Correcto
|
0.022 s | 1 KBi |
#9 |
Correcto
|
0.021 s | 2 KBi |
#10 |
Correcto
|
0.033 s | 1 KBi |
#11 |
Correcto
|
0.021 s | 2 KBi |
#12 |
Correcto
|
0.029 s | 1 KBi |
#13 |
Correcto
|
0.024 s | 1 KBi |
#14 |
Correcto
|
0.024 s | 1 KBi |
#15 |
Correcto
|
0.034 s | 1 KBi |
#16 |
Correcto
|
0.019 s | 4 KBi |
#17 |
Correcto
|
0.021 s | 1 KBi |
#18 |
Correcto
|
0.018 s | 1 KBi |
#include <iostream> #include <algorithm> // std::max #include <bits/stdc++.h> using namespace std; int main() { int R, C; cin >> R; cin >> C; int matrix[R][C]; int sums[R][C]; for(int i = 0;i<R;i++) { for(int j = 0;j<C;j++) { cin >> matrix[i][j]; } } int sumRow = 0; for(int i = 0;i<R;i++) { sumRow = 0; for(int j = 0;j<C;j++) { sumRow += matrix[i][j]; if(i-1 >= 0) sums[i][j] = sumRow + sums[i-1][j]; else sums[i][j] = sumRow; } } int max1 = INT_MIN; for(int r0 = 0;r0<R;r0++) { for(int c0 = 0;c0<C;c0++) { for(int r1 = r0;r1<R;r1++) { for(int c1 = c0;c1<C;c1++) { int sum = sums[r1][c1]; if(r0-1 >= 0)sum -= sums[r0-1][c1]; if(c0-1 >= 0)sum -= sums[r1][c0-1]; if(r0-1 >= 0 && c0-1 >=0)sum += sums[r0-1][c0-1]; max1 = max(max1, sum); } } } } cout << max1 << endl; return 0; }