Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## define functions
- def loadMatrixes():
- M = int(input())
- Matrix = []
- for i in range(0,M):
- Matrix.append([int(x) for x in input().split()])
- return M, Matrix
- def ExistenceSum(M, Matrix): #first count vertical occurences sum, then vertical
- existences = 0
- for i in range(N-1,M):
- for j in range(0,M):
- exists = True
- for k in range(0,N):
- if Matrix[i-k][j] == 1:
- exists = False
- break
- if exists:
- existences += 1
- for i in range(0,M):
- for j in range(0,M-N+1):
- exists = True
- for k in range(0,N):
- if Matrix[i][j+k] == 1:
- exists = False
- break
- if exists:
- existences += 1
- return existences
- ## Process input
- N, M,MatrixCount, Mlist, Matrixlist = int(input()), 38, 0, [], []
- while 1:
- M, Matrix = loadMatrixes()
- if M == 0:
- break
- Mlist.append(M)
- Matrixlist.append(Matrix)
- MatrixCount += 1
- ## Return sum of existences
- for i in range(MatrixCount):
- print(ExistenceSum(Mlist[i],Matrixlist[i]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement