No.397 NO MORE KADOMATSU
タグ : / 解いたユーザー数 204
作問者 :
koyumeishi
/ テスター :
btk
Problem Statement
A Kadomatsu sequence is a sequence $A_1, A_2, A_3$ of $3$ elements that satisfies the following 2 conditions.
- $A_1, A_2, A_3$ are all distinct
- Among the $3$ elements, $A_2$ is the largest or $A_2$ is the smallest
The Kadomatsu sequence contest held the other day was poorly received, so we are going to smash Kadomatsu sequences.
You are given a sequence $A$ of length $N$.
You may repeatedly perform the following operation
- Swap the $u$-th element and the $v$-th element of $A$ ($0 \leq u,v < N$ , $u \neq v$)
By repeating this operation, make $A$ contain no Kadomatsu sequence as a contiguous subarray.
Your answer is judged incorrect if, in $A$ after the operations, there exists an $i$ such that $A_i, A_{i+1}, A_{i+2}$ is a Kadomatsu sequence.
We thought it might be fun if the number of queries were visible, so this is a reactive problem. Read the Input and Output sections carefully.
Input
$N$
$A_0$ $A_1$ ... $A_{N-1}$
$Dummy$
The 1st line contains the length $N$ of the sequence, and the 2nd line contains the elements of $A$ separated by spaces.
The input on the 3rd line is a dummy input for the reactive judge. Read it after printing your answer.
(Your solution might pass without reading it, but read it just in case.)
All inputs are integers and satisfy the following constraints.
$3 \leq N \leq 100$
$1 \leq A_i \leq 100$
$Dummy = -1$
Output
$M$
$u_0$ $v_0$
$u_1$ $v_1$
$\vdots$
$u_{M-1}$ $v_{M-1}$
Print the number of operations on the 1st line, and from the 2nd line onward, print $u$,$v$ ($0 \leq u,v < N$ , $u \neq v$) of the i-th operation, one operation per line.
Finally, flush standard output.
There is no particular limit on the number of swaps, but if there are too many, the judge may get TLE.
Sample
Sample 1
Input
3 1 3 2 -1
Sample Output
2 0 1 1 2
This is one example of a valid output.
[1,3,2] -> [3,1,2] -> [3,2,1], after which no contiguous subarray is a Kadomatsu sequence.
Note that indices are 0-indexed. Also, read the dummy input after printing your answer.
Sample 2
Input
6 1 3 2 2 3 1 -1
Sample Output
1 1 5
[1,3,2,2,3,1] -> [1,1,2,2,3,3]
Sample 3
Input
10 1 2 3 4 5 6 7 8 9 10 -1
Sample Output
0
The sequence contains no Kadomatsu sequence from the start, so zero swaps is fine.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。