BINMT – Editorial

PROBLEM LINK:

Practice
Contest

Author: Md Shahid
Tester: Arkapravo Ghosh
Editorialist: Arkapravo Ghosh

DIFFICULTY:

SIMPLE

PREREQUISITES:

2D Array, Logical AND

PROBLEM:

Given a N* N matrix A containing only 0’s and 1’s, your task is to AND every element of the matrix with the elements of its corresponding row and column and output the resulting matrix.

EXPLANATION:

The task is to AND every element of the matrix with the elements of its corresponding row and column. So, it is very clear that if a an element is 0, then the result of ANDing the elements of its corresponding row or column will be 0 also (Recall (0 AND something) = 0). So we can keep two arrays, one corresponding each column and one corresponding each row. Initially we set all the elements of the array to false. Now, if we find a 0, then we will set the corresponding row of the 0 in the row array to true and do the same with the column array also. So, now when printing the matrix, if we see that the corresponding row or column array index has a true value, then a 0 was present in the corresponding row or column, thus making the result of the AND to 0.

You can find the author’s and editorialist’s solution below for further implementation details.

AUTHOR’S AND EDITORIALIST’S SOLUTIONS:

Author’s solution can be found here.
Editorialist’s solution can be found here