예제 #1
0
 def test_reshape(self):
     from numpypy import arange, array, dtype, reshape
     a = arange(12)
     b = reshape(a, (3, 4))
     assert b.shape == (3, 4)
     a = range(12)
     b = reshape(a, (3, 4))
     assert b.shape == (3, 4)
     a = array(range(105)).reshape(3, 5, 7)
     assert reshape(a, (1, -1)).shape == (1, 105)
     assert reshape(a, (1, 1, -1)).shape == (1, 1, 105)
     assert reshape(a, (-1, 1, 1)).shape == (105, 1, 1)
예제 #2
0
 def test_reshape(self):
     from numpypy import arange, array, dtype, reshape
     a = arange(12)
     b = reshape(a, (3, 4))
     assert b.shape == (3, 4)
     a = range(12)
     b = reshape(a, (3, 4))
     assert b.shape == (3, 4)
     a = array(range(105)).reshape(3, 5, 7)
     assert reshape(a, (1, -1)).shape == (1, 105)
     assert reshape(a, (1, 1, -1)).shape == (1, 1, 105)
     assert reshape(a, (-1, 1, 1)).shape == (105, 1, 1)

def solve(par):
    N, mat = par
    # construct the sum of each column in side the array
    # so kadane's algorithm can be used in each sub row sum
    for j in range(N):
        for i in range(1, N):
            mat[i, j] += mat[i - 1, j]

    maxSum = -1 * INF
    for i in range(N):
        for j in range(i, N):
            array = [mat[j, k] - mat[i, k] for k in range(N)]
            maxSum = max(maxSum, kadane(array))
    return maxSum


if __name__ == '__main__':
    sys.stdin = open('input.txt', 'r')
    N = int(input())
    mat = []
    while True:
        try:
            mat += map(int, raw_input().split())
        except:
            break
    mat = np.array(mat)
    mat = np.reshape(mat, (N, N))
    print(solve((N, mat)))