Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 1 KBi |
#2 |
Correcto
|
0.005 s | 18 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 |
Incorrecto
|
0.006 s | 1 KBi |
#8 |
Correcto
|
0.027 s | 1 KBi |
#9 |
Correcto
|
0.021 s | 1 KBi |
#10 |
Correcto
|
0.02 s | 1 KBi |
#11 |
Correcto
|
0.027 s | 1 KBi |
#12 |
Correcto
|
0.015 s | 1 KBi |
#13 |
Incorrecto
|
0.018 s | 1 KBi |
#14 |
Incorrecto
|
0.019 s | 1 KBi |
#15 |
Correcto
|
0.019 s | 1 KBi |
#16 |
Incorrecto
|
0.024 s | 1 KBi |
#17 |
Incorrecto
|
0.019 s | 1 KBi |
#18 |
Correcto
|
0.016 s | 1 KBi |
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <queue> #include <set> #include <map> #include <vector> #include <stack> #include <algorithm> using namespace std; int main() { int f, c; int m[51][51]; int p[51][51]; int res = -10000000; cin>>f>>c; for(int i = 0; i < f; i++) { for(int j = 0; j < c; j++) { cin>>m[i][j]; if(i==0 && j==0) p[i][j] = m[i][j]; else if(i==0) p[i][j] = p[i][j-1] + m[i][j]; else if(j==0) p[i][j] = p[i-1][j] + m[i][j]; else p[i][j] = p[i-1][j] + p[i][j-1] - p[i-1][j-1] + m[i][j]; } } int suma = 0; for(int i0 = 0; i0 < f; i0++) { for(int j0 = 0; j0 < c; j0++) { for(int i1 = i0; i1 < f; i1++) { for(int j1 = j0; j1 < c; j1++) { if(i0==0 && j0==0) suma = p[i1][j1]; else if (i0 == i1 && j0 == j1) suma = m[i0][j0]; else if(i0==0) suma = p[i1][j1] - p[i1][j0-1]; else if(j0==0) suma = p[i1][j1] - p[i0-1][j1]; else suma = p[i1][j1] - p[i0-1][j0-1]; //cout<<"suma de "<<i0<<", "<<j0<<" hasta "<<i1<<", "<<j1<<" es = "<<suma<<endl; res = max(suma, res); } } } //cout<<endl; } cout<<res<<endl; return 0; }