CF1081B.Farewell Party
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1,2,…n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were ai persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let bi be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b1,b2,…,bn that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Chouti 和他的同学们即将升入大学。为了彼此告别,班级举办了一场盛大的欢送会,同学们、老师和家长们纷纷载歌载舞。
Chouti 记得当时共有 n 人参加了这场欢送会。为了让晚会更有趣,每人戴了一顶帽子,帽子共有 n 种奇特的款式,编号为 1,2,…,n。多人可能戴了同款帽子,也可能有某些款式的帽子无人佩戴。
晚会结束后,第 i 个人声称:有 ai 个人所戴的帽子与他自己的不同。
如今已过去数日,Chouti 已完全记不清其他人所戴帽子的款式,但他对此很好奇。设 bi 表示第 i 个人所戴帽子的款式编号,Chouti 希望你找出任意一组满足所有人陈述的 b1,b2,…,bn。由于部分人可能记性不好,该问题也可能无解。
输入格式
The first line contains a single integer n (1≤n≤105), the number of persons in the party.
The second line contains n integers a1,a2,…,an (0≤ai≤n−1), the statements of people.
第一行包含一个整数 n(1≤n≤105),表示派对中的人数。
第二行包含 n 个整数 a1,a2,…,an(0≤ai≤n−1),表示每个人的陈述。
输出格式
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b1,b2,…,bn (1≤bi≤n).
If there are multiple answers, print any of them.
如果没有解,输出一行 "Impossible"。
否则,输出 "Possible",然后输出 n 个整数 b1,b2,…,bn(其中 1≤bi≤n)。
如果存在多个答案,输出任意一个即可。
输入输出样例
输入#1
3 0 0 0
输出#1
Possible 1 1 1
输入#2
5 3 3 2 2 2
输出#2
Possible 1 1 2 2 2
输入#3
4 0 1 2 3
输出#3
Impossible
说明/提示
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible.
在第一个示例的答案中,所有帽子都相同,因此每个人都会说:没有人的帽子种类与第 1 类不同。
在第二个示例的答案中,第一人和第二人戴的是第 1 类帽子,其余所有人戴的都是第 2 类帽子。
因此,前两人会说:有三人所戴帽子与其自身帽子种类不同;类似地,最后三人会说:有两人所戴帽子与其自身帽子种类不同。
在第三个示例中,可以证明不存在满足条件的解。
在第一个和第二个示例中,还可能存在其他可行的配置。
输入解题思路,AI测评打分。不知道怎么写?