Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/1467
🧭 풀이 시간
180분
👀 체감 난이도
✏️ 문제 설명
세준이는 N자리의 수를 가지고 있다. 세준이는 N자리의 수가 너무 커서 부담을 느낀 나머지 숫자를 몇 개 지워서 이 수를 줄이기로 했다.
숫자를 지울 때는 같은 숫자가 여러 번 등장하더라도 그 중 하나만 지운다. 예를 들어 12534에서 5를 지우면 1234가 되고, 1253452에서 5를 지우면 123452나 125342 둘 중 하나로 만들 수 있다.
세준이는 숫자들을 지웠을 때 결과로 나올 수 있는 수가 한 가지가 아니라는 것을 알고, 남은 수를 가장 크게 만들려고 한다.
세준이가 가지고 있는 수와 지울 숫자들이 주어졌을 때, 남은 수를 가장 크게 만드는 프로그램을 작성하시오.
🔍 풀이 방법
처음에는 어떻게 삭제하나, 로 접근했다가 시간 날렸다.
그 다음에는 9부터 숫자 하나씩 어느위치를 살릴까, 로 접근했다가 시간 날렸다.
핵심은 제일 큰 경우를 구하는 것 .
따라서 결과에서 한 자리씩 제일 큰 숫자부터 하나씩 넣어보며, 되는지 안되는 지는 확인하였다.
예를 들어 정답의 i번째 자리에 숫자 8을 넣을 수 있는 지 확인해보자. 이때 이전에 원래 배열에서 마지막으로 숫자가 들어간 위치가 j인 경우, j+1부터 끝까지 중 8이 제일 먼저 나타나는 위치를 찾는 것이다. 이렇게 확정했을 때, 남은 숫자들로 완성을 할 수 있으면 그대로 진행하여 i+1번째 자리에 9가 들어가는지 확인, 안된다면 다시 i번째 자리에 숫자 7을 넣을 수 있는 지 확인하는 식으로 반복하였다.
⏳ 회고
문제 짧다고 덤볐다가 진짜 개털렸다