[20251024] BOJ / G2 / 아맞다우산 / 한종욱 #1212
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/17244
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
모든 X를 다 수거해서 E갈 때 최소시간은?
🔍 풀이 방법
X의 최대 개수가 적고, 각 X를 수거한 순서에 따라 상태가 다르기 때문에 비트마스킹으로 visited배열을 구성했다. 나머지는 그냥 BFS로 풀면된다.
하지만 그냥 X값을 더하면 안되는게,
int mask2 = current[2] + v;이렇게 더하면 같은 곳을 두 번 방문했을 때 X값이 누적된다.int mask1 = current[2] | v;이렇게 처리해야 두 번 방문했던 값에는 누적으로 값이 더해지지 않아 적절해진다.⏳ 회고
비트마스킹을 할 때의 최댓값을 고려하지 않았다. BFS의 내부 코드가 복잡했다. AI는 나보다 훨씬 간단하게 작성했고 직관적이었다. or 연산을 통해 누적으로 더해지는 것을 방지한 것은 내가 생각하지 못한 것이었다.