| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 | 1024 MB | 39 | 31 | 20 | 74.074% |
Summer holidays are approaching, and Kate has to decide how to spend her time for two months. She was walking on the university campus, listening to music on her headphones, when suddenly she had an idea. When listening to her favourite playlist on shuffle, Kate noticed that sometimes the songs were not as shuffled as she would like them to be. She suddenly realised why this was happening: sometimes two songs from the same artist would be played in a row. "This is unacceptable," she thought, and asks you to write a program that would shuffle the songs in a way that consecutive songs played are from different artists.
Kate is not like any other listener: she likes diverse music. It is guaranteed that at least half of the songs in her playlist are from a unique artist (in other words, the artist of such a song has no other songs in the playlist).
Output the names of the songs in a well-shuffled playlist, where no two songs from the same artist are played in a row.
The input consists of:
The artist and song names have length between 1ドル$ and 20ドル$ characters, and only consist of English lowercase letters (a-z) and numbers (0-9).
The names of the songs are globally unique.
Output $n$ strings, the names of the songs in a well-shuffled playlist.
If there are multiple valid solutions, you may output any one of them.
5 greenbiscuits hard2catch greenbiscuits born2run thebakers baking1000breads 2fast2fail flyinghigh rock2thetop goingout
hard2catch baking1000breads flyinghigh goingout born2run
10 a a1 a a2 a a3 a a4 a a5 b b1 c c1 d d1 e e1 f f1
a1 b1 a2 c1 a3 d1 e1 a4 f1 a5