Royal Garden
Time limit2sMemory limit1024 MB
Given an a by b grid of letters, decide whether deleting one full row or column leaves only cells with the same letter.
- Level
Easy2 of 10
- Topics
- Brute force, Implementation
- Solved
- No attempts yet
Problem
The royal park is widely known for its collection of rare trees. It consists of rows of trees each. One day the king developed an unknown allergy. That same evening the royal gardener was ordered to cut down some of the trees so that only trees of one type remained, and he had until morning. Since he had never cut down a tree in his life (he is a gardener, not a lumberjack), he asked a wizard he knew for help. The wizard agreed to help and cut down one arbitrary row of trees.
The gardener has a plan showing the park as an rectangle of cells, each recording which tree grows there. He must point the wizard to one vertical or horizontal row on the plan, and the wizard cuts down every tree in that row. After the cutting, all remaining trees in the park must be identical.
Your task is to determine whether the wizard can help the gardener or not.
Input
The first line of the input contains two integers and (), the size of the park. Each of the next lines describes one row of the park. Each line contains exactly lowercase Latin letters, the tree species in that row.
Output
Print "Yes" if the gardener can choose a row in the required way, and "No" otherwise.