CodeForces 534D Program B
Description
On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came in stayed in CTOP until the end of the day and never left.
At any time any three students could join together and start participating in a team contest, which lasted until the end of the day. The team did not distract from the contest for a minute, so when another student came in and greeted those who were present, he did not shake hands with the members of the contest writing team. Each team consisted of exactly three students, and each student could not become a member of more than one team. Different teams could start writing contest at different times.
Given how many present people shook the hands of each student, get a possible order in which the students could have come to CTOP. If such an order does not exist, then print that this is impossible.
Please note that some students could work independently until the end of the day, without participating in a team contest.
Input
The first line contains integer n (1 ≤ n ≤ 2·105) — the number of students who came to CTOP. The next line contains n integers a1, a2, ..., an (0 ≤ ai < n), where ai is the number of students with who the i-th student shook hands.
Output
If the sought order of students exists, print in the first line "Possible" and in the second line print the permutation of the students' numbers defining the order in which the students entered the center. Number i that stands to the left of number j in this permutation means that the i-th student came earlier than the j-th student. If there are multiple answers, print any of them.
If the sought order of students doesn't exist, in a single line print "Impossible".
Sample Input
5
2 1 3 0 1
Possible
4 5 1 3 2
9
0 2 3 4 1 1 0 2 2
Possible
7 5 2 1 6 8 3 4 9
4
0 2 1 1
Impossible
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- #include <stack>
- #include <queue>
- #include <map>
- #include <set>
- #include <vector>
- #include <math.h>
- #include <algorithm>
- using namespace std;
- #define ls 2*i
- #define rs 2*i+1
- #define up(i,x,y) for(i=x;i<=y;i++)
- #define down(i,x,y) for(i=x;i>=y;i--)
- #define mem(a,x) memset(a,x,sizeof(a))
- #define w(a) while(a)
- #define LL long long
- const double pi = acos(-1.0);
- #define Len 63
- #define mod 19999997
- const int INF = 0x3f3f3f3f;
- int n,a[300000],ans[300000],len;
- vector<int> vec[300000];
- int main()
- {
- int i,j,k;
- scanf("%d",&n);
- {
- len = 0;
- up(i,1,n)
- {
- scanf("%d",&a[i]);
- vec[a[i]].push_back(i);
- }
- int now = 0,flag = 1;
- up(i,1,n)
- {
- w(now>=0 && vec[now].size()==0)
- now-=3;
- if(now<0)
- {
- flag = 0;
- break;
- }
- ans[len++] = vec[now].back();
- vec[now++].pop_back();
- }
- if(flag)
- {
- printf("Possible\n");
- printf("%d",ans[0]);
- up(i,1,len-1)
- printf(" %d",ans[i]);
- printf("\n");
- }
- else
- printf("Impossible\n");
- }
- return 0;
- }
CodeForces 534D Program B的更多相关文章
- 【codeforces 534D】Handshakes
[题目链接]:http://codeforces.com/contest/534/problem/D [题意] n个人依次进入一个房间; 进进来的人会和房间里面没有组队的人握一次手; (这里的握手只计 ...
- CodeForces 468A Program F
Description Little X used to play a card game called "24 Game", but recently he has found ...
- CodeForces 540C Program D
Description You play a computer game. Your character stands on some level of a multilevel ice cave. ...
- Codeforce 水题报告(2)
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...
- Codeforces Round #443 (Div. 1) A. Short Program
A. Short Program link http://codeforces.com/contest/878/problem/A describe Petya learned a new progr ...
- Codeforces Round #879 (Div. 2) C. Short Program
题目链接:http://codeforces.com/contest/879/problem/C C. Short Program time limit per test2 seconds memor ...
- Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)
题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...
- Codeforces Round #443 (Div. 2) C. Short Program
C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces 879C/878A - Short Program
传送门:http://codeforces.com/contest/879/problem/C 本题是一个位运算问题——位运算的等价变换. 假设位运算符“&”“|”“^”是左结合的,且优先级相 ...
随机推荐
- go分页
简单的beego分页功能代码 一个简单的beego分页小插件(源代码在最下面): 支持条件查询 支持参数保留 支持自定义css样式 支持表/视图 支持参数自定义 默认为pno 支持定义生成链接的个数 ...
- synchronized与static synchronized 的区别
synchronized是对类的当前实例加锁,防止其他线程同时访问该类的该实例的synchronized块,这里的概念是“类的当前实例”,而static synchronized是对类的所有实例加锁, ...
- J2EE 第二阶段项目之编写代码(三)
我的任务就是项目统计. 1 效益统计 1 教育效益统计表 (教育效益统计表,增,改,查看,查) 2 农牧林效益统计表 (农牧林效益统计表,增,改,查看,查) 3 乡村效益统计表 (乡村效益统计表 ...
- Spring MVC 入门基础(一)
一.Spring Web MVC是什么? Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,使用了MVC架构模式的思想,将web层进行职责解 ...
- C++ 迭代器介绍 [转摘]
转摘地址为:http://blog.chinaunix.net/uid-20773165-id-1847758.html 迭代器 迭代器提供对一个容器中的对象的访问方法,并且定义了容器中对象的范围.迭 ...
- as的Enter_Frame与Timer
As3中的Timer和Event.EnterFrame是有明显的区别的. Evnet.EnterFrame是定时间隔多少时间出发.如果执行时间比间隔时间长,则会间隔执行时间这么久. 举个例子: Fla ...
- 33-Url辅助方法
Url辅助方法与HTML辅助方法很类似,HTML辅助方法用来产生HTML标签,而Url辅助方法则负责用来产生Url网址. @Url.Action("About") 最后的输出网址如 ...
- python 练习 3
#!/usr/bin/python # -*- coding: utf-8 -*- def z94(): #斐波那契数列 def filie(x): a,b,t=1,1,0 if x==1 or x= ...
- jQuery图表开源软件
jQuery图表插件 jQchart jQchart 是一个jQuery的插件,用来绘制图表的.支持各种形状的图表. 示例代码: == Mini sample == $('#canvasMyID'). ...
- GIS软件列表
3map:行星地球项目由3map驱动,这是一个自由软件,由Telstra宽带基金会创建并支持,提供客户端与服务器的能力以在线再现虚拟地球. Amein!:其界面介于ArcMap和UMN Mapserv ...