Problem list
Log in
#coci00556 · COCI 2019/2020 Contest 6

Skandi

Unrated 1.0 s 256 MB

Dragica is a captain of a local semi-professional bowling team, she is a passionate chef and probably one of the best crossword puzzle solvers in Croatia. A crossword puzzle consists of $N \times M$ squares arranged in $N$ rows and $M$ columns. Some of the squares are empty (and should be filled with letters by answering questions) and some of the squares are filled. Filled squares contain at most two questions which should either be answered horizontally to the right or vertically downwards. The answers to the questions are written in the empty squares before until we reach the crossword bound or an initially-filled square. An initially-filled square contains a horizontal question if a square to the right exists and is empty. Analogously, an initially-filled square contains a vertical question if a square beneath it exists and is empty. Dragica usually knows all the answers to the crossword puzzle questions, but wishes to read and answer as little questions as possible and still solve the entire crossword puzzle. Help her achieve her goal.

Input

The first line contains integers $N$ and $M$ ($2 \le N$, $M \le 500$) from the task description. Each of the next $N$ lines contain $M$ characters ‘0’ or ‘1’, where ‘0’ denotes an empty square which should be filled by answering a question and ’1’ denotes an initially filled square which may contain at most two questions as explained in the task description. The first row and first column will be filled with ‘1’ characters. It is guaranteed that there will be at least one character ’0’ in the input.

Output

In the first line you should output the minimal number of questions that can be answered in order to solve an entire crossword puzzle. Let’s denote that number with $X$. Each of the next $X$ lines should describe one question that should be answered. The question description should be printed in the format R C direction, where $R$ is the row number of the question, $C$ is the column number of the question and direction is either "DESNO" (Croatian for RIGHT) or "DOLJE" (Croatian for DOWN) depending on whether Dragica should answer the vertical or horizontal question. If there are multiple solutions, output any of them.

Constraints

Subtask Score Constraints 1 18 There will be at most 9 squares with ’1’ 2 32 $N \le 500$ and $M \le 10$ 3 60 No additional constraints. If your solution outputs the first line correctly on each test case of a subtask, but it fails to correctly output the other lines in some test case, you will score 50% of the allocated points for that subtask.

Example 1

Input
4 5
11111
10000
10000
10000
Output
3
2 1 DESNO
3 1 DESNO
4 1 DESNO

Example 2

Input
6 4
1111
1011
1000
1011
1010
1000
Output
4
1 2 DOLJE
4 4 DOLJE
5 3 DOLJE
3 1 DESNO

Example 3

Input
9 8
11111111
10000000
10001000
10010001
11100001
10100110
10001000
10100001
10010001
Output
14
5 2 DOLJE
5 8 DOLJE
8 3 DOLJE
2 1 DESNO
3 1 DESNO
3 5 DESNO
4 1 DESNO
4 4 DESNO
5 3 DESNO
6 3 DESNO
7 1 DESNO
7 5 DESNO
8 3 DESNO
9 4 DESNO

Clarification of the third example: An example of a real crossword puzzle which is equivalent to the one described in this example is given on the next page. Initially-filled squares are colored black and those squares that contain at least one question are numerated. Below the puzzle you can see the questions that should be solved to-the-right (column "across") and those that should be solved downwards (column "down"). Note that some initially-filled squares contain no questions, some contain a single question (e.g. 8 and 13), while some contain two questions (e.g. 10 and 12). In order to solve this crossword puzzle you need to know the answers to at least 14 questions that are listed in the output. Can you solve it?

Source
COCI 2019/2020 Contest 6
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code