Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Incorrecto
|
0.006 s | 1 KBi |
#2 |
Incorrecto
|
0.005 s | 2 KBi |
#3 |
Incorrecto
|
0.007 s | 12 KBi |
#4 |
Incorrecto
|
0.005 s | 2 KBi |
#5 |
Incorrecto
|
0.005 s | 1 KBi |
#6 |
Incorrecto
|
0.006 s | 22 KBi |
#7 |
Incorrecto
|
0.005 s | 1 KBi |
#8 |
Incorrecto
|
0.046 s | 1 KBi |
#9 |
Incorrecto
|
0.044 s | 1 KBi |
#10 |
Incorrecto
|
0.05 s | 1 KBi |
#11 |
Incorrecto
|
0.047 s | 1 KBi |
#12 |
Incorrecto
|
0.041 s | 20 KBi |
#13 |
Incorrecto
|
0.053 s | 1 KBi |
#14 |
Incorrecto
|
0.05 s | 1 KBi |
#15 |
Incorrecto
|
0.047 s | 1 KBi |
#16 |
Incorrecto
|
0.046 s | 1 KBi |
#17 |
Incorrecto
|
0.051 s | 1 KBi |
#18 |
Incorrecto
|
0.043 s | 1 KBi |
#include <algorithm> #include <bits/stdc++.h> using namespace std; long sum_of(vector<vector<long>> &matrix, int i, int r, int j, int c) { long total = matrix[r][c]; if (i > 0) { total -= matrix[i-1][c]; } if (j > 0) { total -= matrix[r][j-1]; } if (i > 0 and j > 0) { total += matrix[i-1][j-1]; } return total; } int main() { int R, C; cin >> R >> C; vector<vector<long>> matrix(R, vector<long>(C)); long max_sum = LONG_MIN; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { cin >> matrix[i][j]; max_sum = max(max_sum, matrix[i][j]); } } for (int i = 1; i < R; i++) { for (int j = 0; j < C; j++) { matrix[i][j] += matrix[i - 1][j]; max_sum = max(max_sum, matrix[i][j]); } } for (int i = 0; i < R; i++) { for (int j = 1; j < C; j++) { matrix[i][j] += matrix[i][j - 1]; max_sum = max(max_sum, matrix[i][j]); } } cout << endl; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { cout << matrix[i][j] << " "; } cout << endl; } for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { for (int r = i + 1; r < R; r++) { for (int c = j + 1; c < C; c++) { max_sum = max(max_sum, sum_of(matrix, i, r, j, c)); } } } } cout << max_sum << endl; }