## COCI '19 Contest 6 #4 Skandi

View as PDF

Points: 17 (partial)
Time limit: 10.0s
Memory limit: 512M

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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 squares arranged in rows and 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 and from the task description.

Each of the next lines contain 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 .

Each of the next lines should describe one question that should be answered. The question description should be printed in the format R C direction, where is the row number of the question, 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.

#### Scoring

There will be at most squares with 1
and

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 of the allocated points for that subtask.

#### Sample Input 1

4 5
11111
10000
10000
10000

#### Sample Output 1

3
2 1 DESNO
3 1 DESNO
4 1 DESNO

#### Sample Input 2

6 4
1111
1011
1000
1011
1010
1000

#### Sample Output 2

4
1 2 DOLJE
4 4 DOLJE
5 3 DOLJE
3 1 DESNO

#### Sample Input 3

9 8
11111111
10000000
10001000
10010001
11100001
10100110
10001000
10100001
10010001

#### Sample Output 3

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

#### Explanation of Sample Output 3

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. and ), while some contain two questions (e.g. and ). In order to solve this crossword puzzle you need to know the answers to at least questions that are listed in the output. Can you solve it?