[20250728] BOJ / P4 / 소가 길을 건너간 이유 9 / 권혁준 #561
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/14463
🧭 풀이 시간
25분
👀 체감 난이도
✏️ 문제 설명
N마리의 소가 각각 원형 길의 한 지점으로 들어가서 다른 지점으로 나오며, 이 지점들은 모든 소에 대해 unique하다. -> 지점의 수는 2N개
경로가 무조건 겹치는 소가 몇 쌍인지 구해보자.
🔍 풀이 방법
소가 방문한 지점을 (s, e)로 나타내면, s가 빠른 순서대로 처리한다고 생각한다.
-> 끝 지점이 s ~ e내에 있는 소의 수가 곧 정답에 더해지게 된다. (시작 점은 반드시 더 작았기 때문에 무조건 경로가 겹치게 됨)
이걸 시간 내에 구현하려면 구간 합을 빠르게 구할 수 있어야 하고, 세그먼트 트리를 사용해 해결했다.
⏳ 회고
국밥