Array sum question

my code-https://ide.geeksforgeeks.org/Pa50ARrsfY
Problem Statement
Given a N*M binary matrix that is, it contains 0s and 1s only, we need to find and return sum of coverage of all zeros of the input matrix. Coverage for a particular 0 is defined as, total number of ones around a zero (i.e. in left, right, up and bottom directions).
Input Format :
Line 1: N and M (space-separated positive integers)
Next N lines: M elements of each row (separated by space).
Output Format :
Line 1: Print Sum Of Coverage Of All Rows
Constraints :
1 <= N <= 10^3
1 <= M <= 10^3

Time Limit : 1 sec
Sample Input 1 :
2 2
1 0
0 1
Sample Output 1 :
4
Sample Input 1 Explanation :
The 0 in first row have 2 1’s i.e. left and down, whereas 0 at second row also have 2 1’s i.e. top and right. So the total coverage value is 2 + 2 = 4.

why failing some testcases


you have miss this line
The ones can be anywhere till corner point in a direction.
it is not necessary to have 1 in just left or just right
1 can be anywhere in right and anywhere in left
same for up and down

Input :

mat[][] ={         0 0 0 0
                   1 0 0 1
                   0 1 1 0
                   0 1 0 0}

Output : 20
First four zeros are surrounded by only
one 1. So coverage for zeros in first
row is 1 + 1 + 1 + 1
Zeros in second row are surrounded by
three 1’s. Note that there is no 1 above.
There are 1’s in all other three directions.
Coverage of zeros in second row = 3 + 3.
Similarly counting for others also, we get
overall count as below.
1 + 1 + 1 + 1 + 3 + 3 + 2 + 2 + 2 + 2 + 2 = 20

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.