Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.023 s | 3 KBi |
#2 |
Correcto
|
0.021 s | 3 KBi |
#3 |
Incorrecto
|
0.021 s | 3 KBi |
#4 |
Correcto
|
0.022 s | 3 KBi |
#5 |
Incorrecto
|
0.022 s | 3 KBi |
#6 |
Correcto
|
0.024 s | 3 KBi |
#7 |
Correcto
|
0.022 s | 3 KBi |
#8 |
Incorrecto
|
1.357 s | 3 KBi |
#9 |
Correcto
|
1.115 s | 3 KBi |
#10 |
Correcto
|
1.233 s | 3 KBi |
#11 |
Correcto
|
1.377 s | 3 KBi |
#12 |
Incorrecto
|
1.115 s | 3 KBi |
#13 |
Incorrecto
|
1.381 s | 3 KBi |
#14 |
Tiempo límite excedido
|
1.582 s | 3 KBi |
#15 |
Correcto
|
1.433 s | 3 KBi |
#16 |
Correcto
|
1.245 s | 3 KBi |
#17 |
Tiempo límite excedido
|
1.506 s | 3 KBi |
#18 |
Correcto
|
1.039 s | 3 KBi |
import math def smsum(mat): N, M = len(mat), len(mat[0]) for r in range(1, N): mat[r][0] += mat[r - 1][0] for c in range(1, M): mat[0][c] += mat[0][c - 1] for r in range(1, N): for c in range(1, M): mat[r][c] += mat[r - 1][c] mat[r][c] += mat[r][c - 1] mat[r][c] -= mat[r - 1][c - 1] def query(m, r1, c1, r2, c2): if r1 == c1 == 0: return m[r2][c2] if r1 == 0: return m[r2][c2] - m[r2][c1 - 1] if c1 == 0: return m[r2][c2] - m[r1 - 1][c2] return m[r2][c2] - m[r1 - 1][c2] - m[r2][c1 - 1] + m[r1 - 1][c1 - 1] def max_submatrix(m): smsum(m) N, M = len(m), len(m[0]) mx = -math.inf for r in range(N): for c in range(M): for rr in range(r + 1, N): for cc in range(c + 1, M): mx = max(mx, query(m, r, c, rr, cc)) return mx if __name__ == "__main__": N, M = map(int, input().split(" ")) mat = [] for _ in range(N): row = map(int, input().split(" ")) mat.append(list(row)) print(max_submatrix(mat))