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

23484번 - Amidakuji 스페셜 저지다국어

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

문제

You are given a positive integer $N$. Construct a sequence of permutations of $(1,2,\cdots,N),ドル $p_1,p_2,\ldots,p_K,ドル that satisfy following conditions, or report that it's impossible.

  • 0ドル \leq K \leq \lceil \log_2 N \rceil + 1,ドル where $K$ is the length of the sequence.
  • $p_1,p_2,\ldots,p_K$ are permutations of $(1,2,\ldots,N)$.

In other words, they are bijections from $\{1,2,\ldots,N\}$ to $\{1,2,\ldots,N\}$.

  • For all $x$ and $y$ (1ドル \leq x,y \leq N$), there is a sequence of bijections $q_1,q_2,\ldots,q_K$ such that $(q_K \circ q_{K-1} \circ \cdots \circ q_1)(x) = y$ and $q_i=p_i$ or $p_i^{-1}$ for all $i$.

Here, $\circ$ denotes function composition, and when $K=0,ドル $q_K \circ q_{K-1} \circ \cdots \circ q_1$ is defined as an identity function.

입력

Input is given from Standard Input in the following format:

$N$

출력

If there is no solution, print $-1$. Otherwise, print the answer in the following format:

$K$

$p_{1,1}$ $p_{1,2}$ $\cdots$ $p_{1,N}$

$\vdots$

$p_{K,1}$ $p_{K,2}$ $\cdots$ $p_{K,N}$

Here, $p_{i,j}$ must be a value of $p_i(j)$.

If there are multiple solutions, you can print any of them.

제한

  • 1ドル \leq N \leq 1000$

예제 입력 1

3

예제 출력 1

3
1 3 2
2 3 1
3 1 2

예제 입력 2

4

예제 출력 2

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

노트

In Sample 1 for $x=2,y=1,ドル we can set $q_1 = p_1, q_2 = p_2^{-1}, q_3 = p_3$ and get $q_3(q_2(q_1(2)))=1$.

출처

Contest > Open Cup > 2019/2020 Season > Stage 15: Grand Prix of Tokyo I번

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

출처

대학교 대회

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

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