#P6411. [COCI 2008/2009 #3] MATRICA
[COCI 2008/2009 #3] MATRICA
Description
You need to construct an character matrix .
This character matrix must satisfy the following constraints:
- .
- It must contain exactly occurrences of the character .
Since there may be many valid constructions, you need to output the lexicographically smallest one.
Because the output would be too large, you only need to output columns. The exact requirement is stated in the Input Format.
If there is no solution, output IMPOSSIBLE.
Input Format
The first line contains two integers and , where is the number of constraints in constraint 2.
The next lines each contain an uppercase letter and an integer, which are and .
The next line contains an integer .
The next line contains integers, indicating the column indices you need to output, guaranteed to be in increasing order.
Output Format
Output an -row, -column character matrix. If there is no solution, output IMPOSSIBLE.
3 3
A 3
B 2
C 4
3
1 2 3
AAB
ACC
BCC
4 4
A 4
B 4
C 4
D 4
4
1 2 3 4
AABB
AACC
BCDD
BCDD
4 5
E 4
A 3
B 3
C 3
D 3
2
2 4
AC
BE
DE
ED
4 6
F 1
E 3
A 3
B 3
C 3
D 3
4
1 2 3 4
IMPOSSIBLE
Hint
Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , , , , .
Notes
This problem is translated from T4 MATRICA of Croatian Open Competition in Informatics 2008/2009 Contest #3.
Translated by ChatGPT 5
京公网安备 11011102002149号