Problem Statement
You have a square grid with length . Each cell in the grid can be either
or
.
Return the length of the perimeter required to surround all the cells in the grid.
Input
Your first line will contain .
Your next lines will each contain
grids of
's and
s.
Output
A single integer representing the unit perimeter required to surround all the cells in the grid.
Constraints
For all test cases:
- All cells will be either
or
.
Example 1
Input
3
010
111
010
Output
12
Example 2
Input
4
0110
1110
0000
0110
Output
16
Example 3
Input
2
01
10
Output
8
Python Template
n = int(input())
grid = [list(map(int, input())) for _ in range(n)]
Comments