Answer to Question #259006 in Python for sindhu

Question #259006

Given an integer N  denotes N×N  matrix. Initially, each cell of matrix is empty. U r given K  tasks. In each task, you are given a cell (i,j)  where cell (i,j)  represents

ith  row and jth  column of given matrix.

I/p format

  • first line contains two space-separated integers N and K where N is number of rows and columns in given matrix and K is number of tasks respectively.
  • Next K lines contain two space-separated integers i and j.

O/p format

Print K space-separated integers denoting numberr of empty cells in matrix.

Constraints

1≤N≤105

1≤K≤1000

1≤i,j≤N

Sample Input

3 3  ==>   Matrix Size is 3  and Tasks is 3.  

It should be a square matrix like 2 4 6 8...and max can be 100 x 100

Initial Matrix


Final Result

4 2 0


Initially all cells [{1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}] are empty.

After first task:

Empty cells are [{2, 2}, {2, 3}, {3, 2}, {3, 3}]. Therefore, answer is 4.

After second task:

Empty cells are [{2, 2}, {3, 2}]. Therefore, answer is 2.

After third task:

No cells remain empty. Therefore, answer is 0.




1
Expert's answer
2021-10-30T10:37:25-0400
n, k = map(int, input().split(" "))


inp = []


rows = []


columns = []


left = n*n


for i in range(k):


      j, k = map(int, input().split(" "))


      if j not in rows:


            rows.append(j)


            left = left - n + len(columns)


      if k not in columns:


            columns.append(k)


            left = left - n + len(rows)


      print(left, end = " ")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog