Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 1 KBi |
#2 |
Correcto
|
0.005 s | 37 KBi |
#3 |
Correcto
|
0.006 s | 7 KBi |
#4 |
Correcto
|
0.005 s | 1 KBi |
#5 |
Correcto
|
0.006 s | 4 KBi |
#6 |
Correcto
|
0.005 s | 3 KBi |
#7 |
Correcto
|
0.005 s | 1 KBi |
#8 |
Correcto
|
0.023 s | 1 KBi |
#9 |
Correcto
|
0.022 s | 1 KBi |
#10 |
Correcto
|
0.021 s | 1 KBi |
#11 |
Correcto
|
0.022 s | 1 KBi |
#12 |
Correcto
|
0.018 s | 9 KBi |
#13 |
Correcto
|
0.023 s | 1 KBi |
#14 |
Correcto
|
0.021 s | 1 KBi |
#15 |
Correcto
|
0.022 s | 1 KBi |
#16 |
Correcto
|
0.021 s | 1 KBi |
#17 |
Correcto
|
0.022 s | 1 KBi |
#18 |
Correcto
|
0.019 s | 8 KBi |
#include <iostream> #include <climits> using namespace std; int main() { int R,C; cin >> R >> C; int m[R][C]; int sum[R][C]; for (int r = 0; r < R; r++) { for (int c = 0; c < C; c++) { cin >> m[r][c]; } } for (int r = 0; r < R; r++) { for (int c = 0; c < C; c++) { int total = m[r][c]; if (r-1 >= 0 && c-1 >= 0) total -= sum[r-1][c-1]; if (r-1 >= 0) total += sum[r-1][c]; if (c-1 >= 0) total += sum[r][c-1]; sum[r][c ] = total; } } int answer = 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 result = sum[r1][c1]; if (r0-1 >= 0 && c0-1 >= 0) result += sum[r0-1][c0-1]; if (r0-1 >=0 ) result -= sum[r0-1][c1]; if (c0-1 >= 0) result -= sum[r1][c0-1]; answer = max(answer, result); } } } } cout << answer << endl; return 0; }