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

Table Recovery

Platinum IV 플래티넘 IV
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Bessie has an \(N\times N\) (\(1\le N\le 1000\)) addition table where the integer in
the cell at row \(r\) and column \(c\) is \(r+c\), for all \(1\le r,c\le N\). For
example, for \(N=3\), the table would look like this:

2 3 4
3 4 5
4 5 6

Unfortunately, Elsie got ahold of the table and permuted it by performing the
following three types of operations as many times as she wanted.

  1. Swap two rows
  2. Swap two columns
  3. Select two values \(a\) and \(b\) that are both present in the table, then simultaneously change every occurrence of \(a\) to \(b\) and every occurrence of \(b\) to \(a\).

Elsie will always perform operations in increasing order of type; that is, she
performs as many operations as she likes (possibly none) first of type \(1\), then
of type \(2\), and finally of type \(3\).

Help Bessie recover a possible state of the table after Elsie finished applying
all of her operations of types \(1\) and \(2\), but before applying any operations
of type \(3\). There may be multiple possible answers, in which case you should
output the lexicographically smallest one.

To compare two tables lexicographically, compare the first entries at which they
differ, when reading both tables in the natural order (rows from top to bottom,
left to right within a row).

Problem credits: Benjamin Qi

제약

SCORING

  • Inputs 4-5: \(N\le 6\)
  • Inputs 6-7: \(N\le 8\)
  • Inputs 8-11: \(N\le 100\)
  • Inputs 12-15: No additional constraints.

Problem credits: Benjamin Qi

입력 형식

The first line contains \(N\).

The next \(N\) lines each contain \(N\) integers, representing Bessie's addition
table after Elsie has permuted it.

출력 형식

The lexicographically minimum possible state of the table after all operations
of types 1 and 2, but before any operations of type 3. It is guaranteed that the
answer exists.

예제 1
입력
1
2
출력
2
설명

Regardless of what operations Elsie performs, the table won't change.

예제 2
입력
3
3 4 2
5 2 3
6 3 5
출력
4 2 3
5 3 4
6 4 5
설명

Here is a possible sequence of operations Elsie might have performed.

2 3 4
3 4 5
4 5 6
-> (op 1: swap columns 2 and 3)
2 4 3
3 5 4
4 6 5
-> (op 1: swap columns 1 and 2)
4 2 3
5 3 4
6 4 5
-> (op 3: swap values 2 and 3)
4 3 2
5 2 4
6 4 5
-> (op 3: swap values 3 and 4)
3 4 2
5 2 3
6 3 5

Note: the following is also a possible state of the table after operations of
types 1 and 2, but it is not the lexicographically smallest because the second
entry of the first row is larger than in the correct answer.

4 6 5
3 5 4
2 4 3
예제 3
입력
6
8 10 5 6 7 4
12 11 10 4 8 2
5 4 6 7 9 8
10 2 4 8 5 12
6 8 7 9 3 5
4 12 8 5 6 10
출력
7 5 8 9 10 6
4 2 5 6 7 3
8 6 9 10 11 7
5 3 6 7 8 4
9 7 10 11 12 8
6 4 7 8 9 5
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > January > Silver

태그

평가 및 의견

Table Recovery

개요
출제자 난이도 Platinum IV 플래티넘 IV 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Table Recovery

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