Binary Grid
InterviewTime limit1sMemory limit1024 MB
Find the largest binary number spelled by the digits along a right-or-down path from the top-left to the bottom-right of a 0/1 grid.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Greedy, Matrix
- Solved
- No attempts yet
Problem
Each cell of an grid contains either or . Inseon starts at row 1, column 1 and moves to row , column . Inseon can move only one cell at a time, either right (toward increasing column number) or down (toward increasing row number).
Each time Inseon visits a cell, Inseon appends the digit written in that cell to the end of the string Inseon holds. For example, in the figure below, if Inseon starts at row 1, column 1 and moves right, then down, then right, the string Inseon holds is 1101.

When Inseon reaches row , column , Inseon reads the string as a binary number . For example, if the string is 1101, then . Find the maximum value of that Inseon can compute.
Input
The first line contains an integer , the size of the grid. ()
Each of the next lines contains integers separated by spaces. Each integer is either or . The -th number on line is the value written in the cell at row , column .
Output
Print the maximum value of . The answer can exceed the range of a 32-bit integer.