# | 제출 시각UTC-0 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
519646 | Giantpizzahead | Rope (JOI17_rope) | C++17 | 1286 ms | 58344 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Solution: The problem statement can be simplified as follows.
Given an array C of N integers, each in the range [1, M]. (Guaranteed at least 1 of each color)
For each c in [1, M], what's the minimum # of elements you must change to create an array that:
- Only has one or two colors, one of which is c
- Can be separated into contiguous ranges of same elements, with the middle ranges having an even size
After fixing 2 colors, how to find minimum cost quickly?
. . 1 . 2 2 . 1 2 . . . 2 1 1 . 2 . . . 1
Fix parity (location of evens)
. . 1 . 2 2 . 1 2 . . . 2 1 1 . 2 . . . 1
^ ^ ^ ^ ^ ^ ^ ^ ^ ^
For each pair, optimal cost can be easily determined
No match (. .) = 2
One match (1 ., . 1, 2 ., . 2) = 1
Both match (1 2, 2 1) = 1
Same match (1 1, 2 2) = 0
Might need to add one element matching either of the target colors on the ends (special for loc 0 and N-1)
Don't need to fix two colors to calc above cost (can process each independently), it doesn't affect anything
O(NM^2)
Total cost of a pair = sum of min(cost 1, cost 2) for each element
Each pair can only have up to one color = 0, only up to two colors = 1, everything else will be = 2
Total cost of a pair = 2 * (# of pairs) - Places with improvement
Only 1s will conflict, and only conflict between 2 colors (call these "conflict pairs")
Total cost of a pair =
2 * (# of pairs) - 2 * # with 0 in either color - # with 1 in either color + # where colors conflict
O(N+M^2)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |