can anybody please share the solution or the thought process of this problem? i am really having a hard time on it https://codeforces.me/gym/105192/problem/D Thanks!
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
4 | adamant | 160 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
8 | Dominater069 | 154 |
8 | nor | 154 |
can anybody please share the solution or the thought process of this problem? i am really having a hard time on it https://codeforces.me/gym/105192/problem/D Thanks!
Название |
---|
Auto comment: topic has been updated by SkyMagic (previous revision, new revision, compare).
First, consider the problem without the trees. It should be fairly intuitive that it's never worth it to change direction in this simpler version – just pick a direction and keep going there.
Consider any straight line in the plane. Now plot the Euclidean distance to a fixed point along the line. This will have a minimum, and increase monotonically in both directions. So when you have some interval along the line, the maximum in the interval will always be at either end of the interval. Consider all points you can reach in a certain number of steps. The set of points forms a diagonal square. All points in this square except its four corners (corresponding to picking a direction and sticking to it) are in the middle of some line segment entirely contained within the square, so cannot be optimal. (This argument is continuous while the actual problem is discrete, so it doesn't quite work, but it can be modified to work.)
Now, look at what happens once you are wrapped around a tree. By again picking a direction and repeatedly going there, you can increase the length of the leash by 1 unit per step. This is clearly optimal – you can't increase the length by more than the distance you move. Thus, it's never useful to wrap around more than one tree.
So, we can just try wrapping around every tree (look at each tree, compute time to get there (Manhattan distance) and length of the leash at the tree (Euclidean distance), and add the time remaining after reaching the tree to the length of the leash), and also try not wrapping around any tree (e.g. try all four directions). Then take the maximum. This runs in $$$\mathrm{O}(n)$$$.
Thank you very much!