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

Cezar

Unrated 레이팅 미적용
난이도
1s
시간 제한
64MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

1 \(s / 64\) \(MB / 100\) points

Mirko has an array of \(N\)

different words that he wants to encrypt using a substitution cypher.

We encrypt the text using a substitution cypher by first choosing a key – a permutation of the

English alphabet. Then we replace all occurrences of letter ‘a’ with the first letter of the key,

all occurrences of letter ‘b’ with the second letter of the key, and so on until letter ‘z’.

Besides the words, Mirko has an array \(A\) consisting of numbers from 1 to \(N\) given in a certain

order (in other words, array \(A\)

is a permutation of numbers from 1 to \(N\)

). Mirko wants to pick

a key such that the array of words after encrypting and lexicographic sorting corresponds to

array \(A\)

. More precisely, he wants the word initially located at \(A\)

_{i} ^{to} ^{be} ^{at} ^{location} ^{ }^{i} ^{after}

encryption and sorting.

Let’s recall that the lexicographic word order is the order in which the words appear in the

dictionary. If we are comparing two words, going from left to right, we search for the first

position in both words where the letters differ and, based on that, we determine which word

is lexicographically smaller. If word \(X\) is the beginning of the word Y, then word X is

lexicographically smaller than word \(Y\)

.

Mirko is currently not in the mood for encrypting, so he kindly asks you to do it for him.

제약

In test cases worth 30 points total, the words will consist of only the first 6 letters of the
English alphabet.

1 \(s / 64\) \(MB / 100\) points

입력 형식

The first line of input contains the integer \(N\)

(2 ≤ \(N\)

≤ 100).
Each of the following \(N\)

lines contains a single word that consists of at most 100 lowercase
letters of the English alphabet. The words will be mutually distinct.
The last line contains \(N\)

integers – the elements of array \(A\)

.

출력 형식

In the case when a solution doesn’t exist, output “NE”.
Otherwise, output “DA” in the first line, and in the second line output a word consisting of 26
different letters of the English alphabet – the key for the substitution cipher.
If multiple solutions exist, output any.

예제 1
입력
2
ab
bc
2 1
3
abc
bcd
add
1 2 3
3
bbb
ccc
ddd
2 3 1
출력
output
output
DA
bacdefghijklmnopqrst
uvwxyz
NE
DA
adbcefghijklmnopqrst
uvwxyz

Note: Outputs are split into multiple lines due to lack of horizontal space.
설명

Clarification of the first test case:
After encrypting, the words become “ba”, “ac”, after lexicographic sorting, the array becomes “ac”, “ba”,
which means the first word ended up in the second spot, and the second word in the first spot.

Clarification of the third test case:
After encrypting, the words become “ddd”, “bbb”, “ccc”, after lexicographic sorting, the array becomes
“bbb”, “ccc”, “ddd”, which means the first word ended up in the third spot, the third word in the second
spot, and the second word in the first spot.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2016/2017 Contest 1

평가 및 의견

Cezar

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Cezar

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