[20260124] BOJ / G5 / Contact / 이준희 #1825
Merged
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/1013
🧭 풀이 시간
70분
👀 체감 난이도
✏️ 문제 설명
전파의 기본 단위는 { 0 , 1 } 두 가지로 구성되어있으며, x+ ( ) 는 임의의 개수(최소 1개) x의 반복으로 이루어진 전파의 집합을 나타냅니다.
ex)
1+ = { 1, 11, 111, 1111, 11111, … }
10+ = { 10, 100, 1000, 10000, 100000, … }
(01)+ = { 01, 0101, 010101, 01010101, 0101010101, … }
(1001)+ = { 1001, 10011001, 100110011001, … }
10+11 = { 1011, 10011, 100011, 1000011, 10000011, … }
(10+1)+ = { 101, 1001, 10001, 1011001, 1001101, 100011011000001, … }
또 다른 기호 | 는 x 혹은 y를 의미하는 것으로 + 기호와 함께 사용했을 경우의 예시는 아래와 같습니다.
ex)
(0+ | 1+) 는 { 0 , 1 , 00 , 11 , 000 , 111 , … }
(100 | 11)+ = { 100 , 11 , 10011 , 11100 , 1110011100 , 100111111100100, … }
이 때 주어진 전파가 (100+1+ | 01)+ 의 조건을 만족하면 YES 아니면 NO를 출력하는 문제입니다.
🔍 풀이 방법
각 단계별로 DP? 처럼 분기를 여러 state로 두어서 처리했습니다.
예를들어 1로 시작했을 때 지금 숫자가 0인 경우면 100 패턴이 시작하는 state를 하나 두거나
0으로 시작했을 때 지금이 0이면 1000 패턴의 일부이고 0으로 시작했는데 지금이 1이면 01 패턴이거나 다른 패턴이 종료되거나 하는 식으로
최대한 단계별로 판단하여 풀었습니다.
⏳ 회고
분기 나누는게 복잡해서 조금 어려운 구현 문제인 줄 알았는데
풀이 후 적용 알고리즘을 보니 정규식 / 문자열 문제라고 되어 있었습니다.
알고보니 주어진 (100+1+ | 01)+ 를 정규식으로 하는 문자열 판별 라이브러리를 사용할 수 있었습니다.
알면 1분컷, 모르면 1시간도 걸리는 문제였던 것 같습니다.
그리고 애초에 문제 이해 자체가 쉽지 않았습니다.