The longest grid path

4

3 votes
Bit Manipulation, Basic Programming, Basics of Bit Manipulation
Problem

You are given a grid, find the longest path in it. The grid is filled with '#' which means blocked cell and '.' which means an empty cell. A path is a chain of empty cells that each cell is neighbor with the next one. Each cell is a neighbor with cells that share a side with it. A cell cannot appear twice in the path.

Input format

  • The first line contains n.
  • The next n lines contain the grid.

Output format

In the first line, print k denoting the length of the path.

In the next k lines, print the cells in order.

Constraints

1n1000

Test generation

At the first, a random number prob is generated in range (0, 1). Then each cell becomes '#' with probability prob.

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

Note that obviously, the printed path is not the longest path that can be found, it's just an example.

Editor Image

?