logo AlgoBeat OnlineJudge
登录 注册

#215115. [Nordic OI 2019] Thieves and Prisons

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

There are thieves and prisons. A thief is either on the run or caught in a prison. Initially all thieves are on the run.

A thief who is on the run can be caught by the police, and then ends up in one of the prisons. A thief who is on the run can also open the gate of a prison. Then every thief in that prison is released from the prison. It would be pointless to open the gate of an empty prison, so that never happens.

You are given a list of events of the form "thief has been caught" or "thief has opened the gate of a prison". Your task is to find a prison assignment that corresponds to the events, or determine that it is not possible.

输入格式

The first input line has three integers , and : the number of thieves, prisons and events. The thieves and prisons are numbered and .

After this, there are lines that describe the events. Each event is "C " (thief has been caught) or "O " (thief opens the gate of a prison).

输出格式

Print a valid prison assignment that consists of integers: for every event the corresponding prison. If there are no solutions, print "IMPOSSIBLE".

样例

样例输入 1

3 2 5
C 1
C 2
O 3
O 2
C 1

样例输出 1

1 2 2 1 1

样例输入 2

1 1 1
O 1

样例输出 2

IMPOSSIBLE

数据范围与提示

Subtask 1 (8 points)

Subtask 2 (13 points)

Subtask 3 (14 points)

Subtask 4 (18 points)

Subtask 5 (47 points)