DOJ logoDOJ
Problems
Recently added problemsSaved problems
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord-backed certification.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

멋진 이름 짓기

Back to problem

Editorial

Claim. sis_isi​ 중 최대 점수를 받는 이름이 존재한다.

Proof. 어떤 이름 ttt가 최대 점수 vvv를 받는다고 가정하자. 다음 과정을 반복한다.

  • ttt가 sis_isi​ 중 어느 것과도 다르다면 마지막 글자를 제거한다.
  • ttt와 같은 sis_isi​가 존재한다면, 이 과정을 종료한다.

ttt가 sis_isi​ 중 어느 것과도 다르다면, i∈{1,2,…,n}i \in \{1, 2, \dots, n\}i∈{1,2,…,n} 중 가 의 접두사인 의 집합은 의 마지막 글자를 지워도 변하지 않는다. 따라서, 마지막 글자를 지워도 점수가 변하지 않는다. 의 길이가 유한하므로, 위 과정을 반복하다 보면 언젠가는 최대 점수를 가지며 중 적어도 하나와 같은 문자열에 도달하게 된다.

위 증명에 의해, nnn개의 문자열 sis_isi​가 가지는 점수를 모두 계산하고, 그 중 최댓값을 출력하면 된다. 이는 O(n∑∣si∣)O(n \sum |s_i|)O(n∑∣si 시간에 쉽게 구현할 수 있다. Trie 등의 자료구조를 사용해 시간으로 최적화하는 것도 가능하지만, 문제를 풀기 위해 요구되는 최적화는 아니다.

sis_isi​
ttt
iii
ttt
ttt
sis_isi​
​
∣
)
O(∑∣si∣)O(\sum |s_i|)O(∑∣si​∣)