kick start 2019 round C
A post-contest write-up.
Problem link
The main references were Kuang Shen’s livestream solution and the official Analysis.
Wiggle Walk
The easy idea is brute force. Simulate the entire command execution process and mark whether each cell has been visited before.
Time complexity: O(N ^ 2).
Although this happened to AC in practice, it is risky. In theory, it would TLE on the large test set.
1 |
|
We need a fast way to skip cells that have already been visited. One approach is the interval-recording method from the editorial. Time complexity: O(N log N). Each interval query costs O(log N).
1 |
|
Another approach is the method from Kuang Shen’s livestream. Use Union-Find, and note that direction matters when doing union. The time complexity is O(N).
1 |
|
Circuit Board
Kuang Shen used a relatively brute-force solution: O(R * C^2).
Record, for each cell, the number of cells before it whose difference is within K.
Then enumerate each column and K, scan the rows, and update the maximum area.
Judging from the data scale and actual tests, this can pass. Kick Start’s time complexity scale is basically around 10^6.
1 |
|
The official solution is O(N log N).
It uses a segment tree to query the maximum and minimum quickly, binary search to determine the right boundary that satisfies K, and largest-rectangle-under-histogram to get the maximum rectangle area.
It strongly tests familiarity with advanced data structures and algorithms, as well as the ability to implement them quickly.
1 |
|
Catch Some
A classic DP problem.
Each shirt color definitely only needs to be worn once, because two trips are definitely longer than one trip, while the number of observed dogs is the same.
Each color has two minimum costs: one where we need to return to the origin, and one where we do not.dp[i][j][0/1] represents the minimum cost after using the first i colors and observing j dogs, without returning / returning to the origin.
1 |
|
Afterword
To summarize the common topics in Kick Start:
- DP/knapsack
- Binary search
- Segment tree