DOJ logoDOJ
Problems
Recently added problemsSaved problemsWorkbooks
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

짬뽕 369

Back to problem

Editorial

  • 111부터 kkk까지 외쳤을 때 짬뽕 문자열의 길이를 len(k)\mathrm{len}(k)len(k)라 합시다. len(k)≥L\mathrm{len}(k) \ge Llen(k)≥L인 가장 작은 kkk를 이분탐색으로 찾으면, LLL번째 문자는 kkk번째 차례에 있습니다.
  • len(k)\mathrm{len}(k)len(k)는 111부터 kkk까지의 수를 세 종류로 나누어 구합니다.
    • 두 자리 이상이면서 맨 앞자리와 일의 자리가 모두 333, 666, 99 중 하나인 수: , 글자
  • JJAM과 PPONG은 JJAM부터 번갈아 나오고, JJAMPPONG은 이 순서에 영향을 주지 않습니다. 그래서 둘째 종류의 수가 ccc개이면 그 길이 합은 4⌈c/2⌉+5⌊c/2⌋4\lceil c/2 \rceil + 5\lfloor c/2 \rfloor4⌈c/2⌉+5⌊c/2⌋입니다.
  • 각 종류의 개수는 자릿수별로 맨 앞자리와 일의 자리를 따져 세면 됩니다. 한 번 세는 데 O(log⁡k)\mathcal{O}(\log k)O(logk)가 듭니다.
  • kkk를 찾은 뒤에는 kkk번째 차례부터 수를 하나씩 늘려 가며, 외칠 수나 단어를 R−L+1R - L + 1R−L+1글자가 될 때까지 이어 붙입니다. 이때 k−1k-1k−1번째 차례까지 나온 JJAM·PPONG 개수로 다음 단어를 정합니다.
  • 시간복잡도는 O(N(log⁡2R+R−L))\mathcal{O}(N(\log^2 R + R - L))O(N(log2R+R−L))입니다.
9
JJAMPPONG
999
  • 그 밖에 맨 앞자리나 일의 자리가 333, 666, 999 중 하나인 수: JJAM 또는 PPONG
  • 나머지 수: 자릿수만큼