Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 1 KBi |
#2 |
Correcto
|
0.005 s | 1 KBi |
#3 |
Correcto
|
0.006 s | 1 KBi |
#4 |
Correcto
|
0.007 s | 1 KBi |
#5 |
Correcto
|
0.006 s | 1 KBi |
#6 |
Correcto
|
0.005 s | 1 KBi |
#7 |
Correcto
|
0.007 s | 1 KBi |
#8 |
Correcto
|
0.019 s | 1 KBi |
#9 |
Correcto
|
0.019 s | 1 KBi |
#10 |
Correcto
|
0.023 s | 1 KBi |
#11 |
Correcto
|
0.025 s | 1 KBi |
#12 |
Correcto
|
0.023 s | 1 KBi |
#13 |
Correcto
|
0.027 s | 1 KBi |
#14 |
Correcto
|
0.023 s | 1 KBi |
#15 |
Correcto
|
0.022 s | 1 KBi |
#16 |
Correcto
|
0.026 s | 1 KBi |
#17 |
Correcto
|
0.025 s | 1 KBi |
#18 |
Correcto
|
0.017 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[101][101]; int p[101][101]; 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]; } } 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++) { int suma = 0; //suma = p[i1][j1]; 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] - p[i1][j0-1] - p[i0-1][j1]; //cout<<"suma de "<<i0<<", "<<j0<<" hasta "<<i1<<", "<<j1<<" es = "<<suma<<endl; res = max(suma, res); } } } //cout<<endl; } cout<<res<<endl; return 0; }