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

18548번 - Word Squared 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB89564761.842%

문제

Given a permutation of numbers from 1 to n, find a square matrix conforming to the following rules:

  1. The matrix should include only numbers from the permutation;
  2. The given permutation should occur in every row of the matrix as a contiguous subsequence, read from left to right;
  3. The given permutation should occur in every column of the matrix as a contiguous subsequence, read from top to bottom;
  4. The matrix size is the smallest possible.

입력

The first line of input is a positive integer n ≤ 500.

The second line of input consists of n space-separated integers: the permutation itself.

출력

The first line of output should be an integer m: the size of the matrix. The next m lines should list m consecutive rows of the matrix. Each of these lines should contain m integers separated by spaces: the values in the corresponding row.

The size m should be minimum possible. If there are several possible answers, print any one of them.

제한

예제 입력 1

2
1 2

예제 출력 1

3
1 2 1
2 1 2
1 2 1

힌트

Here is where the permutation occurs in the matrix from the example:

출처

Camp > Petrozavodsk Programming Camp > Winter 2019 > Day 8: Petrozavodsk SU Contest B번

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

출처

대학교 대회

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

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