Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. ## define functions
  2. def loadMatrixes():
  3.     M = int(input())
  4.     Matrix = []
  5.     for i in range(0,M):
  6.         Matrix.append([int(x) for x in input().split()])
  7.     return M, Matrix
  8. def ExistenceSum(M, Matrix): #first count vertical occurences sum, then vertical
  9.     existences = 0
  10.     for i in range(N-1,M):
  11.         for j in range(0,M):
  12.             exists = True
  13.             for k in range(0,N):
  14.                 if Matrix[i-k][j] == 1:
  15.                     exists = False
  16.                     break
  17.             if exists:
  18.                 existences += 1
  19.     for i in range(0,M):
  20.         for j in range(0,M-N+1):
  21.             exists = True
  22.             for k in range(0,N):
  23.                 if Matrix[i][j+k] == 1:
  24.                     exists = False
  25.                     break
  26.             if exists:
  27.                 existences += 1
  28.     return existences
  29. ## Process input
  30. N, M,MatrixCount, Mlist, Matrixlist = int(input()), 38, 0, [], []
  31. while 1:
  32.     M, Matrix = loadMatrixes()
  33.     if M == 0:
  34.         break
  35.     Mlist.append(M)
  36.     Matrixlist.append(Matrix)
  37.     MatrixCount += 1
  38. ## Return sum of existences
  39. for i in range(MatrixCount):
  40.     print(ExistenceSum(Mlist[i],Matrixlist[i]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement