Logo
(追記) (追記ここまで)

30312번 - Hacky Ordering 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 1024 MB52353468.000%

문제

You have been asked to sort! Again! For the bazillionth time! Not even numbers, but strings! Ugh! Do people still not have this in their standard library? Why do you even need to learn this? Who even uses a language without sort function‽

Clearly, you have not been paying attention in class for such a stupid ubiquitous function, but now you have been asked to implement it! Without calling sort! But you just cannot!

But wait! You have a better approach: what if you just assume that the list is sorted already? The order of the characters in the alphabet is arbitrary anyway\ldots{} So, instead of sorting the list, you want to determine whether there exists some order of the characters of the alphabet such that the list of strings is sorted according to this order.

Note that when a string is a prefix of some longer string, the shorter string should be sorted before the longer string.

입력

The input consists of:

  • One line with an integer $n$ (1ドル\leq n\leq 10^5$), the number of strings.
  • $n$ lines, each with a string.

The strings only consist of English lowercase letters (a-z).

The total number of characters in the $n$ strings is at most 10ドル^5$.

The strings are not necessarily distinct.

출력

If it is impossible to determine an order of the alphabet, output "impossible".

If it is possible, output a permutation of the 26 letters of the English alphabet according to which the strings are sorted.

If there are multiple valid solutions, you may output any one of them.

제한

예제 입력 1

7
c
cplusplus
csharp
python
php
java
javascript

예제 출력 1

cpsyhjabdefgiklmnoqrtuvwxz

예제 입력 2

4
aa
ba
ab
bb

예제 출력 2

impossible

예제 입력 3

5
yyy
yyyy
z
xx
xx

예제 출력 3

qwertyuiopasdfghjklzxcvbnm

예제 입력 4

2
aa
a

예제 출력 4

impossible

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2023 Preliminaries H번

  • 문제를 만든 사람: Jorke de Vlas
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /