問題一覧 > 通常問題

No.1051 PQ Permutation

レベル : / AI推定難易度 : 1800 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 49
作問者 : stoq / テスター : kakira9618
お気に入りにしたユーザー ProblemId : 4132 / 自分の提出
問題文最終更新日: 2020-09-13 09:42:47
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 247 (順位表) の他の問題:

Apology

The test cases were weak, so a rejudge was performed. We apologize for the inconvenience.

Problem Statement

You are given a permutation $A$ of $1$ to $N$. Find the lexicographically smallest permutation $B$ of $1$ to $N$ that satisfies all of the following conditions.
If no such $B$ exists, output -1.
(Conditions)
・$B$ is strictly greater than $A$ in lexicographic order
・In $B$, $P$ is to the left of $Q$

Input

$N \ P \  Q$
$A_1\ A_2\ \dots \ A_N$

$2 \leq N \leq 2 \times 10^5$
$1 \leq P,Q \leq N$
$P \neq Q$
Each of $1$ to $N$ appears exactly once in $A_i$

Output

Output the permutation $B$ satisfying the conditions, separated by spaces. If it does not exist, output -1.
Do not put a space after the last element, and print a newline at the end.

Sample

Sample 1
Input
5 1 2
2 1 5 3 4
Output
3 1 2 4 5

Sample 2
Input
8 5 2
2 5 8 6 4 3 1 7
Output
3 1 4 5 2 6 7 8

Sample 3
Input
4 3 4
4 1 2 3
Output
-1

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。