CF1691B.Shoe Shuffling

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.

There are nn students in the class, and you are given an array ss in non-decreasing order, where sis_i is the shoe size of the ii-th student. A shuffling of shoes is valid only if no student gets their own shoes and if every student gets shoes of size greater than or equal to their size.

You have to output a permutation pp of 1,2,…,n{1,2,\ldots,n} denoting a valid shuffling of shoes, where the ii-th student gets the shoes of the pip_i-th student (pi≠ip_i \ne i). And output −1-1 if a valid shuffling does not exist.

A permutation is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array) and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

一个班级的学生每天穿同一双鞋感到厌烦,于是决定互相交换鞋子。在本题中,一双鞋不可拆分,被视为一个整体。

班上有 nn 名学生,给定一个非递减数组 ss,其中 sis_i 表示第 ii 名学生的鞋码。一次鞋子交换方案是合法的,当且仅当:

  • 没有任何学生拿到自己原来的鞋子;
  • 每位学生拿到的鞋子尺码均大于等于其自身鞋码。

你需要输出一个排列 pp(即 {1,2,…,n}\{1,2,\ldots,n\} 的一个排列),表示一种合法的鞋子交换方案,其中第 ii 名学生拿到第 pip_i 名学生的鞋子(即要求 pi≠ip_i \ne i)。若不存在合法的交换方案,则输出 −1-1。

排列 是指由 11 到 nn 这 nn 个互不相同的整数以任意顺序组成的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,而 [1,2,2][1,2,2] 不是排列(数字 22 出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中出现了 44)。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1051\leq n\leq10^5) — the number of students.

The second line of each test case contains nn integers s1,s2,…,sns_1, s_2,\ldots,s_n (1≤si≤1091\leq s_i\leq10^9, and for all 1≤i<n1\le i \lt n, si≤si+1s_i\le s_{i+1}) — the shoe sizes of the students.

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

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051\leq n\leq10^5),表示学生的数量。

每个测试用例的第二行包含 nn 个整数 s1,s2,…,sns_1, s_2,\ldots,s_n(1≤si≤1091\leq s_i\leq10^9,且对所有 1≤i<n1\le i \lt n,均有 si≤si+1s_i\le s_{i+1}),表示学生的鞋码。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

For each test case, print the answer in a single line using the following format.

If a valid shuffling does not exist, print the number −1-1 as the answer.

If a valid shuffling exists, print nn space-separated integers — a permutation pp of 1,2,…,n1,2,\ldots,n denoting a valid shuffling of shoes where the ii-th student gets the shoes of the pip_i-th student. If there are multiple answers, then print any of them.

对于每个测试用例,请按以下格式在一行中输出答案。

如果不存在合法的重排方案,则输出数字 −1-1 作为答案。

如果存在合法的重排方案,则输出 nn 个以空格分隔的整数——即 1,2,…,n1,2,\ldots,n 的一个排列 pp,表示一种合法的鞋子重排方案,其中第 ii 位学生获得第 pip_i 位学生的鞋子。若存在多个合法答案,输出任意一个即可。

输入输出样例

  • 输入#1

    2
    5
    1 1 1 1 1
    6
    3 6 8 13 15 21

    输出#1

    5 1 2 3 4 
    -1

说明/提示

In the first test case, any permutation pp of 1,…,n1,\ldots,n where pi≠ip_i\ne i would represent a valid shuffling since all students have equal shoe sizes, and thus anyone can wear anyone's shoes.

In the second test case, it can be shown that no valid shuffling is possible.

在第一个测试用例中,任意一个 1,…,n1,\ldots,n 的排列 pp(满足 pi≠ip_i\ne i)都构成一种合法的重新分配方案,因为所有学生的鞋码均相同,因此任何人都可以穿任何人的鞋子。

在第二个测试用例中,可以证明不存在合法的重新分配方案。

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

首页