python测试数据最后一个有换行 题目数据有问题

P1719 最大加权矩形

zzuBobby @ 2021-04-13 21:13:12

前4个顺利ac 最后一个下载数据发现测试数据有问题

n = int(input())
m = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
    m[i] = list(map(int, input().split()))

# 求一维最大子段和
def mss(a):
    s = [0 for i in range(n)]
    s[0] = a[0]
    for i in range(1, n):
        if s[i-1] < 0:
            s[i] = a[i]
        else:
            s[i] = s[i-1] + a[i]
    s.sort()  # 这一步别忘了
    return s[n-1]

# 初始化ans
ans = mss(m[0])
# 压缩处理
for i1 in range(n):
    t = [0 for k in range(n)]
    for i2 in range(i1, n):
        for j in range(n):
            if i2 == i1:
                # 自身
                t[j] = m[i1][j]
            else:
                t[j] += m[i2][j]
        t_ans = mss(t)
        if t_ans > ans:
            ans = t_ans

print(ans)

by SMagic @ 2022-01-24 18:18:22

是这样的,最后一个数据应该是100*100的矩阵,但是它没有按照每行100个数字的方式给出来

我是这样处理的:

n = int(input())
ori = []
while True:
    try:
        tmp = input()
    except EOFError:
        break
    ori += list(map(int, tmp.split()))

data = []
for i in range(0, n*n, n):
    data.append(ori[i:i+n].copy())

|