AlgoUniversity
  • Go Back
Discussion
Fit The Stamp :

Author

Akshay Sharma

Difficulty Level : Hard

Submissions : 79

Asked In : Rubrik

Marks :100

: 1 | : 0

You are given an m x n binary matrix grid where each cell is either 0 (empty) or 1 (occupied)

You are then given stamps of size stampHeight x stampWidth. We want to fit the stamps such that they follow the given restrictions and requirements:

Cover all the empty cells.

Do not cover any of the occupied cells.

We can put as many stamps as we want.

Stamps can overlap with each other.

Stamps are not allowed to be rotated.

Stamps must stay completely inside the grid.

Input

The first line of input contains two integers N and M the size of the matrix($$$ 1 \le N, M \le 10^5$$$)

The next lines contain the input for the matrix

The next line contains StampHeight and StampWidth. ($$$1 \le StampHeight ,StampWidth \le 10^5$$$)

Output

Return true if it is possible to fit the stamps while following the given restrictions and requirements. Otherwise, return false.

Examples

Input
5 4
1 0 0 0
1 0 0 0
1 0 0 0
1 0 0 0
1 0 0 0
4 3
Output
1
Input
4 4
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
2 2
Output
0

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.