PivotOJ

Skandi

시간 제한: 10000ms메모리 제한: 512MB출처: COCI 2019-2020BOJ 19233

문제

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 × 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.

입력

The first line contains integers N and M (2 ≤ N, M ≤ 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.

출력

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.

예제

예제 1

입력
4 5
11111
10000
10000
10000
출력
3
2 1 DESNO
3 1 DESNO
4 1 DESNO

예제 2

입력
6 4
1111
1011
1000
1011
1010
1000
출력
4
1 2 DOLJE
4 4 DOLJE
5 3 DOLJE
3 1 DESNO

예제 3

입력
9 8
11111111
10000000
10001000
10010001
11100001
10100110
10001000
10100001
10010001
출력
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
코드를 제출하려면 로그인하세요.