A1158 | [COCI-2008_2009-contest3]#4 MATRICA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
A matrix is a rectangular table of letters. A square matrix is a matrix with an equal number of rows and columns. A square matrix M is called symmetric if its letters are symmetric with respect to the main diagonal (Mij = Mji for all pairs of i and j).
The following figure shows two symmetric matrices and one which is not symmetric:
Given a collection of available letters, you are to output a subset of columns in the lexicographically smallest symmetric matrix which can be composed using all the letters.
If no such matrix exists, output "IMPOSSIBLE".
To determine if matrix A is lexicographically smaller than matrix B, consider their elements in rowmajor order (as if you concatenated all rows to form a long string). If the first element in which the matrices differ is smaller in A, then A is lexicographically smaller than B.
The following figure shows two symmetric matrices and one which is not symmetric:
Given a collection of available letters, you are to output a subset of columns in the lexicographically smallest symmetric matrix which can be composed using all the letters.
If no such matrix exists, output "IMPOSSIBLE".
To determine if matrix A is lexicographically smaller than matrix B, consider their elements in rowmajor order (as if you concatenated all rows to form a long string). If the first element in which the matrices differ is smaller in A, then A is lexicographically smaller than B.
输入格式
The first line of input contains two integers N (1 ≤ N ≤ 30000) and K (1 ≤ K ≤ 26). N is the dimension of the matrix, while K is the number of distinct letters that will appear.
Each of the following K lines contains an uppercase letter and a positive integer, separated by a space.
The integer denotes how many corresponding letters are to be used. For example, if a line says "A 3",
then the letter A must appear three times in the output matrix.
The total number of letters will be exactly N2 . No letter will appear more than once in the input.
The next line contains an integer P (1 ≤ P ≤ 50), the number of columns that must be output.
The last line contains P integers, the indices of columns that must be output. The indices will be between 1 and N inclusive, given in increasing order and without duplicates.
Each of the following K lines contains an uppercase letter and a positive integer, separated by a space.
The integer denotes how many corresponding letters are to be used. For example, if a line says "A 3",
then the letter A must appear three times in the output matrix.
The total number of letters will be exactly N2 . No letter will appear more than once in the input.
The next line contains an integer P (1 ≤ P ≤ 50), the number of columns that must be output.
The last line contains P integers, the indices of columns that must be output. The indices will be between 1 and N inclusive, given in increasing order and without duplicates.
输出格式
If it is possible to compose a symmetric matrix from the given collection of letters, output the required columns on N lines, each containing P character, without spaces. Otherwise, output "IMPOSSIBLE"
(quotes for clarity).
(quotes for clarity).
输入输出样例
输入 #1
3 3 A 3 B 2 C 4 3 1 2 3
输出 #1
AAB ACC BCC
输入 #2
4 4 A 4 B 4 C 4 D 4 4 1 2 3 4
输出 #2
AABB AACC BCDD BCDD
输入 #3
4 5 E 4 A 3 B 3 C 3 D 3 2 2 4
输出 #3
AC BE DE ED
In test cases worth 60% of points, N will be at most 300.
In test cases worth 80% of points, N will be at most 3000.
In test cases worth 80% of points, N will be at most 3000.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted