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

20221번 - In-place Sorting 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB111504652.273%

문제

Woe is you -- for your algorithms class you have to write a sorting algorithm, but you missed the relevant lecture! The subject was in-place sorting algorithms, which you deduce must be algorithms that leave each input number in its place and yet somehow also sort the sequence.

Of course you cannot change any of the numbers either, then the result would just be a different sequence. But then it hits you: if you flip a 6 upside-down, it becomes a 9, and vice versa! Certainly no one can complain about this since you changed none of the digits! The deadline to hand in the exercise is in five hours. Try to implement this sorting algorithm before then!

입력

The input consists of:

  • A line with an integer $n$ (2ドル \leq n \leq 10,000円$), the number of integers in the input sequence.
  • $n$ lines, the $i$th of which contains a positive integer $x_i$ (1ドル\leq x_i \leq 10^{18}$), the $i$th number of the sequence.

출력

If the sequence cannot be sorted in non-decreasing order by flipping some of the digits 6ドル$ or 9ドル$ in the input1, output "impossible". Otherwise, output "possible" followed by the sorted sequence -- each number on its own line.

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

1Flipping any of the digits of $n$ is not allowed.

제한

예제 입력 1

4
9
7
7
9

예제 출력 1

possible
6
7
7
9

예제 입력 2

4
97
96
66
160

예제 출력 2

possible
67
69
99
190

예제 입력 3

3
80
97
79

예제 출력 3

impossible

예제 입력 4

2
197
166

예제 출력 4

possible
167
169

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2020 Preliminaries I번

  • 문제를 만든 사람: Timon Knigge
(追記) (追記ここまで)

출처

대학교 대회

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

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