为啥第三题python暴力只能通过10%,代码有什么问题吗 ``` def solve(score, n, m): # n行m列 (41276)# 前缀和 preSum = [[0] * (m+1) for _ in range(n+1)] for i in range(1, n+1): for j in range(1, m+1): preSum[i][j] = preSum[i][j-1] + preSum[i-1][j] + score[i-1][j-1] - preSum[i-1][j-1] res = preSum[-1][-1] total = preSum[-1][-1] max_len = min(n, m) for l in range(1, max_len+1): # l是边长 l -= 1 for i in range(1, n+1-l): for j in range(1, m+1-l): cur_sum = preSum[i+l][j+l] - preSum[i+l][j-1] - preSum[i-1][j+l] + preSum[i-1][j-1] res = min(res, abs(total - 2*cur_sum)) return res n, m = map(int, input().split()) score = [[] for _ in range(n)] for i in range(n): score[i] = list(map(int, input().split())) print(solve(score, n, m)) ```
点赞 3

相关推荐

点赞 评论 收藏
分享
球球别再泡了:坏,我单9要了14
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 19:05
点赞 评论 收藏
分享
牛客网
牛客企业服务