CF1689B.Mystic Permutation

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Monocarp is a little boy who lives in Byteland and he loves programming.

Recently, he found a permutation of length nn. He has to come up with a mystic permutation. It has to be a new permutation such that it differs from the old one in each position.

More formally, if the old permutation is p1,p2,…,pnp_1,p_2,\ldots,p_n and the new one is q1,q2,…,qnq_1,q_2,\ldots,q_n it must hold that $$p_1\neq q_1, p_2\neq q_2, \ldots ,p_n\neq q_n.$$

Monocarp is afraid of lexicographically large permutations. Can you please help him to find the lexicographically minimal mystic permutation?

Monocarp 是一个住在 ByteLand 的小男孩,他热爱编程。

最近,他找到了一个长度为 nn 的排列。他需要构造一个“神秘排列”——这是一个全新的排列,且在每个位置上都与原排列不同。

更准确地说,若原排列为 p1,p2,…,pnp_1,p_2,\ldots,p_n,新排列为 q1,q2,…,qnq_1,q_2,\ldots,q_n,则必须满足

p_1neqq_1,p_2neqq_2,ldots,p_nneqq_n.p\_1\\neq q\_1, p\_2\\neq q\_2, \\ldots ,p\_n\\neq q\_n.

Monocarp 害怕字典序过大的排列。你能帮他找出字典序最小的神秘排列吗?

输入格式

There are several test cases in the input data. The first line contains a single integer tt (1≤t≤2001\leq t\leq 200) — the number of test cases. This is followed by the test cases description.

The first line of each test case contains a positive integer nn (1≤n≤10001\leq n\leq 1000) — the length of the permutation.

The second line of each test case contains nn distinct positive integers p1,p2,…,pnp_1, p_2, \ldots, p_n (1≤pi≤n1 \leq p_i \leq n). It's guaranteed that pp is a permutation, i. e. pi≠pjp_i \neq p_j for all i≠ji \neq j.

It is guaranteed that the sum of nn does not exceed 10001000 over all test cases.

输入数据包含多个测试用例。第一行包含一个整数 tt(1≤t≤2001\leq t\leq 200),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个正整数 nn(1≤n≤10001\leq n\leq 1000),表示排列的长度。

每个测试用例的第二行包含 nn 个互不相同的正整数 p1,p2,…,pnp_1, p_2, \ldots, p_n(1≤pi≤n1 \leq p_i \leq n)。保证 pp 是一个排列,即对所有 i≠ji \neq j,均有 pi≠pjp_i \neq p_j。

保证所有测试用例中 nn 的总和不超过 10001000。

输出格式

For each test case, output nn positive integers — the lexicographically minimal mystic permutations. If such a permutation does not exist, output −1-1 instead.

对于每个测试用例,输出 nn 个正整数——字典序最小的神秘排列。如果这样的排列不存在,则输出 −1-1。

输入输出样例

  • 输入#1

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

    输出#1

    2 3 1
    1 2 3 4 5
    1 2 4 3
    -1

说明/提示

In the first test case possible permutations that are mystic are [2,3,1][2,3,1] and [3,1,2][3,1,2]. Lexicographically smaller of the two is [2,3,1][2,3,1].

In the second test case, [1,2,3,4,5][1,2,3,4,5] is the lexicographically minimal permutation and it is also mystic.

In third test case possible mystic permutations are [1,2,4,3][1,2,4,3], [1,4,2,3][1,4,2,3], [1,4,3,2][1,4,3,2], [3,1,4,2][3,1,4,2], [3,2,4,1][3,2,4,1], [3,4,2,1][3,4,2,1], [4,1,2,3][4,1,2,3], [4,1,3,2][4,1,3,2] and [4,3,2,1][4,3,2,1]. The smallest one is [1,2,4,3][1,2,4,3].

在第一个测试用例中,可能的神秘排列有 [2,3,1][2,3,1] 和 [3,1,2][3,1,2]。其中字典序更小的是 [2,3,1][2,3,1]。

在第二个测试用例中,[1,2,3,4,5][1,2,3,4,5] 是字典序最小的排列,且它也是神秘排列。

在第三个测试用例中,可能的神秘排列有 [1,2,4,3][1,2,4,3]、[1,4,2,3][1,4,2,3]、[1,4,3,2][1,4,3,2]、[3,1,4,2][3,1,4,2]、[3,2,4,1][3,2,4,1]、[3,4,2,1][3,4,2,1]、[4,1,2,3][4,1,2,3]、[4,1,3,2][4,1,3,2] 和 [4,3,2,1][4,3,2,1]。其中最小的一个是 [1,2,4,3][1,2,4,3]。

输入解题思路,AI测评打分。不知道怎么写?

首页