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

31507번 - Acceptable Seating Arrangements 스페셜 저지다국어

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

문제

Charlie is managing a classroom. The seats in the classroom are arranged in a grid with rows and columns. Each student has a distinct height.

A configuration of students to seats is acceptable if the following conditions are met:

  • Each student is assigned to exactly one seat.
  • The students are seated in increasing order of height from left to right in each row.

The students are initially seated in an acceptable arrangement. Charlie wants to rearrange students into a potentially different acceptable arrangement. To do this, he can swap any two students. However, he wants to ensure that the configuration stays acceptable after each swap.

Help Charlie devise a strategy to move the students from the original arrangement to his preferred arrangement. You don't need to minimize the number of swaps, but you are limited to at most 10ドル^4$ swaps.

It can be proven that this is always possible for all possible inputs that satisfy the input constraints.

입력

The first line of input contains two integers $r$ and $c$ (1ドル \le r,c \le 20$). Charlie's classroom has $r$ rows and $c$ columns of seats.

Each of the next $r$ lines contains $c$ integers $h$ (1ドル \le h \le r \cdot c$), representing the heights of the students in each row in the original arrangement. The heights are guaranteed to be distinct, and the arrangement is guaranteed to be acceptable.

Each of the next $r$ lines contains $c$ integers $h$ (1ドル \le h \le r \cdot c$), representing the heights of the students in each row in Charlie's desired arrangement. The heights are guaranteed to be distinct, and the arrangement is guaranteed to be acceptable.

출력

On the first line, output an integer $k,ドル which is the number of swaps to perform (0ドル \le k \le 10^4$).

Then, output the $k$ swaps which change the original arrangement to Charlie's preferred arrangement. On each of the next $k$ subsequent lines, output four integers $r_1, c_1, r_2, c_2$ (1ドル \le r_1, r_2 \le r,ドル 1ドル \le c_1, c_2 \le c,ドル $(r_1, c_1) \ne (r_2, c_2)$). This represents a swap of the student in row $r_1,ドル column $c_1$ with the student in row $r_2,ドル column $c_2$.

It can be proven that it's always possible to accomplish this in under 10ドル^4$ swaps for all possible inputs that satisfy the input constraints. Remember that the arrangement must be acceptable after each swap.

제한

예제 입력 1

2 3
1 4 5
2 3 6
3 5 6
1 2 4

예제 출력 1

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

힌트

출처

ICPC > Regionals > North America > Pacific Northwest Regional > 2023 ICPC Pacific Northwest Region > Division 1 B번

ICPC > Regionals > North America > Pacific Northwest Regional > 2023 ICPC Pacific Northwest Region > Division 2 H번

ICPC > Regionals > North America > South Central USA Regional > 2023 South Central USA Regional Contest > Division 2 E번

ICPC > Regionals > North America > Mid-Atlantic Regional > 2023 Mid-Atlantic USA Regional Contest > Division 2 E번

ICPC > Regionals > North America > Southeast USA Regional > 2023 Southeast USA Regional Programming Contest > Division 2 E번

  • 문제를 만든 사람: Lewin Gan
(追記) (追記ここまで)

출처

대학교 대회

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

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