Logo
(追記) (追記ここまで)

33146번 - Latin Squares 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.5 초 (추가 시간 없음) 2048 MB23131359.091%

문제

A Latin square of size $N$ is an $N \times N$ matrix where each entry is an integer between 1ドル$ and $N,ドル and no two entries in the same row or column are equal.

Alice has a Latin square of size $N,ドル and she applied a list of transformations to it. Each transformation swaps either two distinct rows or two distinct columns of the matrix. The transformations are applied sequentially: the first transformation is applied to the original matrix, the second to the result of the first transformation, and so on. The final result is, of course, an $N \times N$ matrix.

Alice will not reveal any matrix to you, only the list of transformations. Your task is to determine whether there exists an original matrix that, after applying all transformations, is identical to the final matrix. If such a matrix exists, you must also provide a possible content for this original matrix.

입력

The first line contains two integers $N$ (2ドル ≤ N ≤ 500$) and $T$ (1ドル ≤ T ≤ 10^5$), indicating respectively the size of the Latin square and the number of transformations.

The next $T$ lines describe the transformations, in the order they are applied, one transformation per line. Each of these lines contains a character $X$ and two integers $I$ and $J$ (1ドル ≤ I, J ≤ N$ and $I \ne J$). The character $X$ is either the uppercase letter “R” or the uppercase letter “C” indicating respectively that rows $I$ and $J,ドル or columns $I$ and $J$ are swapped.

출력

If there exists an original matrix that, after applying all transformations, is identical to the final matrix, output $N$ lines with $N$ integers each, representing any such matrix.

If no such matrix exists, output a line with the character “*” (asterisk) instead.

제한

예제 입력 1

4 4
R 1 2
C 2 1
R 3 4
C 3 4

예제 출력 1

1 2 3 4
2 1 4 3
3 4 1 2
4 3 2 1

예제 입력 2

4 3
R 1 2
R 1 2
R 2 1

예제 출력 2

*

힌트

출처

ICPC > Regionals > Latin America > Latin America Regional Contests > Latin America Regional Contests 2024 L번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /