[20250504] BOJ / G4 / 거짓말 / 이강현 #322
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/1043
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
파티의 개수와 파티에 참석하는 사람들의 리스트가 주어짐. 이때 지민이가 모든 파티 중 사람들에게 들키지 않고 거짓말을 할 수 있는 최대 파티 수를 구하는 문제. 이미 진실을 알고 있는 사람들이 주어지고 진실과 거짓말을 둘다 듣는 경우도 들통나는 경우임.
🔍 풀이 방법
진실을 알고 있는 사람들을 boolean 배열로 저장해두고 매 파티를 순회하면서 진실을 아는 사람이 참석한 경우 그 파티의 모든 사람들이 진실을 알고 있다고 체크함. 그리고 그 파티를 리스트에서 제거하고 이를 반복하다가 진실을 알고 있었던 사람 혹은 새롭게 알게된 사람들이 전혀 참석하지 않은 파티만이 남게 되었을 때 이 수를 출력함.
⏳ 회고
단순한 구현이었다고 생각함. 정렬을 통해 진실을 아는 사람들을 먼저 처리해야한다고 생각했으나 아니었음. 5개의 파티가 있을 때 1,2번 파티만 진실을 아는 사람이 있다고 가정하고 1,2번에 참석한 사람이 5번에 있고 5번에 참석한 사람이 3번에 있다면, 5번 파티가 3번 파티보다 더 먼저 처리되어야 하므로 정렬을 매 순간 반복해야하지만 그냥 정렬을 하지 않고 반복해서 순회하는 게 더 효율적이었던 것 같음.