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

29997번 - Lexicographical Challenge 다국어

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

문제

In the picturesque village of Lexicoville there lived two friends, Lily and Ethan. One day, a mysterious letter arrived at their house, sealed with a bunch of beatiful insignia full of sparkle and enchantment. Inside the envelope, they found a riddle too complex, even for the wisest minds of their village.

In this riddle, they were given an integer K and a string S containing only lower-case letters, which could be changed according to a curious rule. At each moment, the villagers have the freedom to choose an index i; then, magically, the characters Si and Si+K will be swapped! The riddle will be solved when the lexicographically minimum string, using only the allowed operation, is found.

The village was filled with curiosity and excitement with this riddle, but none more so than Lily and Ethan. The friends, always craving adventure, decided to dive headfirst into this challenge. However, as they observed the string, they noticed that the road to success was paved with countless possible swaps.

With the riddle’s words echoing in their minds, they wondered: How could they navigate this web of possibilities to unveil the lexicographically minimum string? Every swap was like turning a page in a magical book, revealing new secrets and mysteries.

A long time has passed, but neither Lily nor Ethan have been able to solve the riddle. Can you help them?

입력

The first line contains the string S (1 ≤ |S| ≤ 105). The seconds line contains the integer K (1 ≤ K < |S|).

출력

Output a single line with the lexicographically earliest string that can be obtained.

제한

예제 입력 1

zaaab
4

예제 출력 1

baaaz

예제 입력 2

njoab
2

예제 출력 2

banjo

힌트

출처

ICPC > Regionals > Latin America > Sub-Regional Brasil do ACM ICPC > Maratona de Programação da SBC 2023 L번

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

출처

대학교 대회

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

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