跳到正文

题解

Solution of AT_abc218_h [ABC218H] Red and Blue Lamps

tder约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年11月11日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 2 分钟
获赞
4

版本

  1. v1当前

你可以浏览这个题解的中文版本。

There is the obvious conclusion that choosing RR ones is equivalent to choosing N−RN-R ones, due to the fact that there is no essential difference between red and blue. This allows us to guarantee R≤N2R\le\frac N2.

At this point, there is a greedy conclusion that the red lattice is not continuous. This can be proved by the adjustment method, for example, if the colouring is {B,R,R,B,B}\{\tt B,R,R,B,B\}, the gain at this point is A1+A3A_1+A_3. And if adjusted to {B,R,B,R,R,B}\{\tt B,R,B,R,R,B\}, the gain at this point is A1+A2+A3+A4A_1+A_2+A_3+A_4, which is significantly better.

Thus, the problem is transformed into, pick RR discontinuous positions, pick the ii-th position with contribution Ai+Ai−1A_i+A_{i-1}, and find the maximum contribution. That is, the classical problem of contrite greed P1484 Planting Trees.

Complexity O(Nlog⁡N)\mathcal{O}(N\log N).

原文