So I keep fucking up with the bloody answer checking machine, it's straight-out unbelievable at this point.
The dealio this time was, there's a plaintext file which contains the dimensions of a matrix (M, N) and the number of queries to it (K) in the first line, the matrix itself in the next M lines, and the queries in the K lines after that. The queries are in x1, y1, x2, y2 format, and the program is supposed to calculate the sum of all elements of the matrix in the rectangle that has x1,y1 as its top left corner, and x2, y2 as its bottom right corner. Corners are included. The numbers in the matrix are positive or negative integers.
So I did this:
def count_matrix(matrix, query):
matrixFragment = matrix[query[1]-1:query[3]]
count = 0
for line in matrixFragment:
count += sum(line[query[0]-1:query[2]])
return count
initText = open('input.txt')
Lines = initText.readlines()
param = list(map(int, Lines.pop(0).split()))
matrix = [x.split() for x in Lines[:param[0]]]
matrix = [list(map(int, x)) for x in matrix]
queries = [x.split() for x in Lines[param[0]:param[0]+param[2]]]
queries = [list(map(int, x)) for x in queries]
for query in queries:
print(count_matrix(matrix, query))
and it seems to work perfectly well for me with multiple examples, but when I submit it, the machine insists that I fucked up almost everything. Is there anything that seems obviously wrong with the code here?