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

32610번 - Catchy Tunes 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 1024 MB39312074.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:

  • One line with integer $n$ (1ドル\leq n\leq 10^5$), the number of songs in Kate's playlist.
  • $n$ lines, each with two space-separated strings $a$ and $s,ドル the artist and the name of the song.

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.

제한

예제 입력 1

5
greenbiscuits hard2catch
greenbiscuits born2run
thebakers baking1000breads
2fast2fail flyinghigh
rock2thetop goingout

예제 출력 1

hard2catch
baking1000breads
flyinghigh
goingout
born2run

예제 입력 2

10
a a1
a a2
a a3
a a4
a a5
b b1
c c1
d d1
e e1
f f1

예제 출력 2

a1
b1
a2
c1
a3
d1
e1
a4
f1
a5

힌트

출처

University > Delft University of Technology > Freshmen Programming Contest 2023 C번

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

출처

대학교 대회

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

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