█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 1011

Problema 0xa6 - Submatriz de suma máxima en una matriz no muy grande

  • Autor: abatesins
  • Fecha: 2020-10-07 11:52:45 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.024 s 3 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.022 s 3 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.023 s 3 KBi
#4
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.024 s 3 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.022 s 3 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.022 s 3 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.022 s 3 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.024 s 3 KBi
#9
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.023 s 3 KBi
#10
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.03 s 7 KBi
#11
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.024 s 3 KBi
#12
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.022 s 3 KBi
#13
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.024 s 3 KBi
#14
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.024 s 3 KBi
#15
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.022 s 3 KBi
#16
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.023 s 3 KBi
#17
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.022 s 3 KBi
#18
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 39, in <module>
    print(get_max_sum(mat))
  File "script.py", line 22, in get_max_sum
    sums_mat = get_integral_mat(mat)
NameError: name 'get_integral_mat' is not defined
0.022 s 3 KBi
Puntos totales: 0 / 100

Código

def kadane(arr):
    """
    Kadane's algorithm to find the max-sum sub-array
    """
    max_sum = last_sum = arr[0]
    for i in arr[1:]:
        last_sum = max(last_sum + i, i)
        # branchless assignment (faster than the IF statement):
        # decision = int(last_sum > max_sum)
        # max_sum = decision * last_sum + (1 - decision) * max_sum
        #
        # branched assignment (slower but easier to read):
        if last_sum > max_sum:
            max_sum = last_sum
    return max_sum



def get_max_sum(mat):
    nrows, ncols = len(mat), len(mat[0])
    max_sum = mat[0][0]
    sums_mat = get_integral_mat(mat)

    for up_i, upper_row in enumerate(mat):
        sum_cols = [0] * ncols  # running sum along columns
        for lo_i, lower_row in enumerate(mat[up_i:], start=up_i):
            sum_cols = list(map(lambda x, y: x + y, sum_cols, lower_row))  # O(ncols)
            max_subcol = kadane(sum_cols)
            if max_subcol > max_sum:
                max_sum = max_subcol

    return max_sum



if __name__ == "__main__":
    nrows, ncols = list(map(int, input().split()))
    mat = [list(map(int, input().split())) for _ in range(nrows)]
    print(get_max_sum(mat))