AtCoder Regular Contest 147
翻译中…
Problem Statement
翻译中…
You are given a permutation $P=(P_1,P_2,\ldots,P_N)$ of $(1,2,\ldots,N)$.
翻译中…
You can repeat the following two kinds of operations in any order to make $P$ sorted in increasing order.
翻译中…
- Operation
$A$: Choose an integer$i$such that$1 \leq i \leq N-1$, and swap$P_i$and$P_{i+1}$. - Operation
$B$: Choose an integer$i$such that$1 \leq i \leq N-2$, and swap$P_i$and$P_{i+2}$.
翻译中…
Find a sequence of operations with the following property:
翻译中…
- The number of Operations
$A$is the minimum possible. - The total number of operations is not larger than
$10^5$.
翻译中…
Under the Constraints of this problem, we can prove that a solution always exists.
翻译中…
Constraints
翻译中…
$2 \leq N \leq 400$$1 \leq P_i \leq N \,(1 \leq i \leq N)$$P_i \neq P_j \,(1 \leq i < j \leq N)$- All values in input are integers.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N
P_1 P_2 \ldots P_N
翻译中…
Output
翻译中…
Let $S$ be the number of operations in your answer. Print $S+1$ lines.
翻译中…
The first line should contain $S$.
翻译中…
The $(s+1)$-th ($1 \leq s \leq S$) line should contain the following:
翻译中…
A iif the$s$-th operation is Operation$A$, and the integer chosen in this operation is$i$.B iif the$s$-th operation is Operation$B$, and the integer chosen in this operation is$i$.
翻译中…
If there are multiple solutions satisfying the condition, printing any of them will be accepted.
翻译中…
样例
Input #1
4
3 2 4 1
Output #1
4
A 3
B 1
B 2
B 2
In this Sample Output, $P$ changes like this: $(3,2,4,1) \rightarrow (3,2,1,4) \rightarrow (1,2,3,4) \rightarrow (1,4,3,2) \rightarrow (1,2,3,4)$.
Note that you don't have to minimize the total number of operations.
Input #2
3
1 2 3
Output #2
0
Input #3
6
2 1 4 3 6 5
Output #3
3
A 1
A 3
A 5
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。