RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00088

Matrica

Diamond V 다이아몬드 V
난이도
0.200s
시간 제한
32MB
메모리 제한
1
맞았습니다!!
1
제출 수
100.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 (\(M_{ij} = M_{ji}\) for all pairs of \(i\) and \(j\)).

Two symmetric matrices:

AAB    AAA
ACC    ABA
BCC    AAA

Two matrices that are NOT symmetric:

ABCD   AAB
ABCD   ACA
ABCD   DAA
ABCD

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 row-major 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\).

제약

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.
Contest #3, \(13^{th}\) December 2008

입력 형식

The first line of input contains two integers \(N\) (\(1 \le N \le 30000\)) and \(K\) (\(1 \le K \le 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 \(N^2\). No letter will appear more than once in the input.

The next line contains an integer \(P\) (\(1 \le P \le 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\) characters, without spaces. Otherwise, output IMPOSSIBLE (quotes for clarity).

Scoring: 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\).

서브태스크
서브태스크점수설명

Subtask 1

110점
예제 1
입력
3 3
A 3
B 2
C 4
3
1 2 3
출력
AAB
ACC
BCC
예제 2
입력
4 4
A 4
B 4
C 4
D 4
4
1 2 3 4
출력
AABB
AACC
BCDD
BCDD
예제 3
입력
4 5
E 4
A 3
B 3
C 3
D 3
2
2 4
출력
AC
BE
DE
ED
예제 4
입력
4 6
F 1
E 3
A 3
B 3
C 3
D 3
4
1 2 3 4
출력
IMPOSSIBLE
문제 정보

riseoj 작성

출처 COCI 2008/2009 Contest 3

평가 및 의견

Matrica

개요
출제자 난이도 Diamond V 다이아몬드 V 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Matrica

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8