传送门:http://codeforces.com/contest/1081/problem/B

B. Farewell Party

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 nn persons took part in that party. To make the party funnier, each person wore one hat among nn kinds of weird hats numbered 1,2,…n1,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 ii-th person said that there were aiai 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 bibi be the number of hat type the ii-th person was wearing, Chouti wants you to find any possible b1,b2,…,bnb1,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.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105), the number of persons in the party.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤n−10≤ai≤n−1), the statements of people.

Output

If there is no solution, print a single line "Impossible".

Otherwise, print "Possible" and then nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤n1≤bi≤n).

If there are multiple answers, print any of them.

Examples
input

Copy

30 0 0

output

Copy

Possible1 1 1 

input

Copy

53 3 2 2 2

output

Copy

Possible1 1 2 2 2 

input

Copy

40 1 2 3

output

Copy

Impossible

Note

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 11.

In the answer to the second example, the first and the second person wore the hat with type 11 and all other wore a hat of type 22.

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.

题意概括:

有 N 个人,每个人都佩戴一顶帽子(帽子种类有 1、2、3 ... N );

接下来 N 个数表示所有人里面 与 第 i 个人佩戴了不同帽子的总数。

解题思路:

ai 代表与自己佩戴了不同帽子的个数,那么反过来意思就是说有 N - ai个人佩戴了与自己相同帽子。

如果能满足 数量为 ai 的 个数 Si == N - ai, 则说明刚好有 N-ai 个人佩戴相同帽子。

如果 Si > N-ai ,则需要判断 这 Si 个人里面能否内部平衡掉, 也就是分成若干块 N-ai,每一块佩戴不同的帽子,但是块内的人佩戴的帽子是相同的,这样也满足条件。

即 Si%(N-ai) ?= 0;

如果 Si % (N-ai) != 0 则说明无法平衡。

最后按块编号,输出答案。

tip:代码实现和细节很重要。

AC code:

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <vector>
 6 #include <cmath>
 7 #define INF 0x3f3f3f3f
 8 using namespace std;
 9
10 const int MAXN = 1e5+10;
11 vector<vector<int> >num(MAXN);
12 int ans[MAXN];
13
14 int main()
15 {
16     int N, x;
17     scanf("%d", &N);
18     for(int i = 1; i <= N; i++){
19         scanf("%d", &x);
20         num[N-x].push_back(i);
21     }
22
23     int tp, no = 0;
24     bool flag = true;
25     for(int i = 1; i <= N; i++){
26         tp = num[i].size();
27         if(tp%i != 0){
28                 flag = false;
29                 break;
30         }
31         for(int j = 0; j < tp; j++){
32             if(j%i == 0) ++no;
33             ans[num[i][j]] = no;
34         }
35     }
36
37     if(flag){
38         puts("Possible");
39         for(int i = 1; i <= N; i++)
40             printf("%d ", ans[i]);
41     }
42     else{
43         puts("Impossible");
44     }
45     return 0;
46 }

Avito Cool Challenge 2018 B. Farewell Party 【YY】相关推荐

  1. Bash Cookbook 学习笔记 【高级】

    Read Me 本文是以英文版<bash cookbook> 为基础整理的笔记,力求脱水 [高级]部分,涉及脚本安全.bash定制.参数设定等高阶内容 本系列其他两篇,与之互为参考 [基础 ...

  2. 【leetcode】

    1. Two Sum [题目]https://leetcode.com/problems/two-sum/description/ [思路]将数组 利用 map 处理 即可 [代码] 1 class ...

  3. Bash Cookbook 学习笔记 【中级】

    Read Me 本文是以英文版<bash cookbook> 为基础整理的笔记,力求脱水 2018.01.21 更新完[中级].内容包括工具.函数.中断及时间处理等进阶主题. 本系列其他两 ...

  4. 【Elasticsearch】Elasticsearch 存储桶聚合

    1.概述 翻译:https://iridakos.com/programming/2018/10/22/elasticsearch-bucket-aggregations [Elasticsearch ...

  5. 自然场景文本检测识别技术综述【转】

    转载自https://blog.csdn.net/SIGAI_CSDN/article/details/80858565 番外青蛇: 姐, 图像文本检测和识别领域现在的研究热点是什么? 白蛇: 白纸黑 ...

  6. 【文学】大一上学期总结

    更新日志 2018.1.14 更新[前言] 2018.2.24 更新[结束语] 本文已完结. 前言 随着线性代数考试的完结(蛋),博主本学期的所有课程都已画(陷)上(入)句(凉)号(凉).本来说(毒) ...

  7. 机器学习在自动驾驶中的应用-以百度阿波罗平台为例【上】

    其它机器学习.深度学习算法的全面系统讲解可以阅读<机器学习-原理.算法与应用>,清华大学出版社,雷明著,由SIGAI公众号作者倾力打造. 书的购买链接 书的勘误,优化,源代码资源 原创声明 ...

  8. 【Linux】Linux中vim的使用

    文章目录 1.vim基本概念 2.vim基本操作 3.普通模式命令集 4.底行模式命令集 1.vim基本概念 vim共有12种模式,我们主要了解3种模式:普通模式.插入模式.底行模式: 普通/正常/命 ...

  9. 【Linux】Linux编辑器—vim使用

    目录 1.vim的基本概念 2.vim基本操作 3.vim命令模式命令集 4.vim末行模式命令集 5.简单vim配置 6.使用sudo提权 7.关闭vim时使用 ctrl + z 退出怎么解决? 为 ...

最新文章

  1. leetcode算法题--删除与获得点数★
  2. 用python中的cv2库打开摄像头
  3. UCINET 社会网络分析工具
  4. 编程之美-第3章 结构之法
  5. 脉脉因“App 整改下架”事件致歉;阿里云全年营收超 600 亿;腾讯防大量群消息骚扰专利获授权|极客头条...
  6. html中图片阴影怎么写,css如何给图片加阴影?
  7. 光端机和无缝带拼接混合矩阵切换器的配搭应用-某市户外广告投屏解决
  8. Qunee学习开发体会
  9. 进程间通信方式有哪些?各自有哪些优缺点?
  10. 驾驶证管理程序的实现java_驾驶证查询示例代码
  11. 凯联医疗完成逾亿元C轮融资 加速布局微量药物输注领域
  12. 远期、期货和互换(一)
  13. 26个思维转换,实现跨越式成长
  14. 原生JS 和 jQuery 通过url传递 和 接收 自定义参数
  15. ios 各种动画机制
  16. 小程序开发外包费用一般是多少?
  17. 计算机专业硕士学制,计算机研究生学制
  18. pcb过孔漏铜_过孔露铜改善评估报告
  19. 树莓派玩黄油,编译运行ONScripter
  20. 华为无线显示未连接到服务器,华为手机的无线显示功能怎么使用

热门文章

  1. 六个人传一个球,每两个人之间最多传一次,最多进行多少次传球
  2. 事务传播行为(重点隔离级别区别)
  3. CenterPoint论文和代码解析
  4. JDK8新特性之Lambda表达式、函数式接口
  5. 协程简史,一文讲清楚协程的起源、发展和实现
  6. adams行星齿轮副添加注意事项
  7. tp获取sql_tp5 sql语句 tp5 获取sql语句
  8. TP5学习(十二):安全
  9. Vue中v-model的用法
  10. 便携式医疗电子将科幻场景搬进生活