RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 COCI00690

Bojanje

설명

Marin, having become exceptionally skilled in competitive programming, decided to find a new hobby to
keep himself entertained while waiting for you to catch up. While you were solving previous problems,
Marin discovered a great love for painting.
He took a blank white canvas and two colors, red and blue. He began painting perfectly horizontal and
vertical strokes on the canvas, from one edge to the opposite edge. The canvas can be imagined as an
\(n \cdot n\) grid, where rows and columns are numbered from 1 to \(n\), and it starts completely white. Each of
Marin’s strokes can be imagined as choosing one of the two colors and a row or column, then coloring all
the cells in that row/column with the chosen color, regardless of what was previously on the field. Marin
will make a finite number of strokes and complete his painting.
However, his friend Stjepan found a painting that resembles Marin’s but is unsure if it is really his. The
painting he found can again be imagined as an \(n\) x \(n\) grid where each cell is white, blue, or red. The
painting is possibly Marin’s if there exists a sequence of strokes on a blank canvas, as described above,
that produces an image identical to the one found. Stjepan has asked you to help him determine whether
the painting might be Marin’s and, if so, to find a sequence of strokes that produces the found painting.

제약
입력 형식

The first line contains a positive integer \(n\) (\(1 \le n \le 2000\)).
In the next \(n\) lines, there are \(n\) integers \(a_{i,j}\) (\(0 \le a_{i,j} \le 2\)), where each represents the color in the \(i\)-th row
and \(j\)-th column (0 if white, 1 if red, and 2 if blue).

출력 형식

If the painting is possibly Marin’s, then in the first line, print the number of strokes \(K\) (\(0 \le K \le 4000\)).
In the next \(K\) lines, you should print three integers. The first will indicate whether the \(i\)-th stroke was on
a row or a column (1 for a row, 2 for a column). The second number will indicate the index of the row or
column where the stroke is performed, and the third number will indicate the color in the same way as
described in the Input section.
If the painting is certainly not Marin’s, print "-1" (without quotes) in the first and only line.

서브태스크
서브태스크점수설명

1

15점

\(a_{i,j} \le 1\)

2

35점

\(n \le 100\)

3

40점

No additional constraints.

예제 1
입력
3
0 0 1
1 1 1
0 0 1
출력
2
2 3 1
1 2 1
예제 2
입력
3
1 1 2
2 1 1
2 1 1
출력
-1
예제 3
입력
4
0 1 2 1
2 2 2 1
0 1 2 1
1 1 2 1
출력
5
2 2 1
1 2 2
2 4 1
1 4 1
2 3 2
문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2024/2025 Contest 3

평가 및 의견

Bojanje

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Bojanje

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8