Cyclically Shifted Maze
Time limit2sMemory limit512 MB
Given a maze that was cyclically shifted by some rows and columns, list every (row, column) shift that restores a connected maze.
- Level
Medium6 of 10
- Topics
- Matrix, BFS, Brute force
- Solved
- No attempts yet
Problem
Let's call a maze a rectangular grid of cells, where each cell is either empty or a wall. From an empty cell, you can move in four directions to an adjacent empty cell.
A maze is connected if every empty cell can be reached from every other empty cell by moving in four directions.
A connected maze of size was cyclically shifted: some rows were moved down and some columns were moved right. The exact shifts are unknown. Find all possible shifts.
Input
The first line contains two integers and (), the size of the maze. Each of the next lines contains characters, either '.' for an empty cell or '#' for a wall. The maze has at least one empty cell.
Output
On the first line, print the number of possible shifts (). Each of the next lines contains two integers and (, ): the original maze was shifted down by rows and right by columns. The original maze must be connected for each listed pair. Print the pairs in lexicographical order.