A958 | Mowing Mischief--Platinum
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Bessie's younger cousins, Ella and Bella, are visiting the farm.
Unfortunately, they have been causing nothing but mischief since they arrived.
In their latest scheme, they have decided to mow as much grass as they can.
The farm's prime grassland is in the shape of large $T \times T$ square. The
bottom-left corner is $(0,0)$, and the top-right corner is $(T,T)$. The square
therefore contains $(T+1)^2$ lattice points (points with integer coordinates).
Ella and Bella plan to both start at $(0,0)$ and run at unit speed to $(T, T)$
while each holding one end of a very sharp and very stretchy wire. Grass in
any area that is swept by this wire will be cut. Ella and Bella may take
different paths, but each path consists of only upward and rightward steps,
moving from lattice point to lattice point.
Bessie is rather concerned that too much grass will be cut, so she invents a
clever plan to constrain the paths Ella and Bella take. There are $N$ yummy
flowers $(1 \leq N \leq 2 \cdot 10^5$) scattered throughout the grassland,
each on a distinct lattice point. Bessie will pick a set of $S$ flowers that
will be required for both Ella and Bella to visit (so Ella's path must visit
all the flowers in $S$, and so must Bella's path). In order to add as many
waypoints to these paths as possible, Bessie will choose $S$ to be as large as
possible among subsets of flowers that can be visited by a cow moving upward
and rightward from $(0,0)$ to $(T,T)$.
Ella and Bella will try to maximize the amount of grass they cut, subject to
the restriction of visiting flowers in $S$. Please help Bessie choose $S$ so
that the amount of grass cut is as small as possible.
Unfortunately, they have been causing nothing but mischief since they arrived.
In their latest scheme, they have decided to mow as much grass as they can.
The farm's prime grassland is in the shape of large $T \times T$ square. The
bottom-left corner is $(0,0)$, and the top-right corner is $(T,T)$. The square
therefore contains $(T+1)^2$ lattice points (points with integer coordinates).
Ella and Bella plan to both start at $(0,0)$ and run at unit speed to $(T, T)$
while each holding one end of a very sharp and very stretchy wire. Grass in
any area that is swept by this wire will be cut. Ella and Bella may take
different paths, but each path consists of only upward and rightward steps,
moving from lattice point to lattice point.
Bessie is rather concerned that too much grass will be cut, so she invents a
clever plan to constrain the paths Ella and Bella take. There are $N$ yummy
flowers $(1 \leq N \leq 2 \cdot 10^5$) scattered throughout the grassland,
each on a distinct lattice point. Bessie will pick a set of $S$ flowers that
will be required for both Ella and Bella to visit (so Ella's path must visit
all the flowers in $S$, and so must Bella's path). In order to add as many
waypoints to these paths as possible, Bessie will choose $S$ to be as large as
possible among subsets of flowers that can be visited by a cow moving upward
and rightward from $(0,0)$ to $(T,T)$.
Ella and Bella will try to maximize the amount of grass they cut, subject to
the restriction of visiting flowers in $S$. Please help Bessie choose $S$ so
that the amount of grass cut is as small as possible.
输入格式
The first line contains $N$ and $T$ ($1 \leq T \leq 10^6$). Each of the next
$N$ lines contains the integer coordinates $(x_i, y_i)$ of a flower. It is
guaranteed that $1 \leq x_i, y_i \leq T-1$ for all $i$, and no two flowers lie
on the same horizontal or vertical line.
In at least 20% of the test cases, it is further guaranteed that $N \leq
3200$.
$N$ lines contains the integer coordinates $(x_i, y_i)$ of a flower. It is
guaranteed that $1 \leq x_i, y_i \leq T-1$ for all $i$, and no two flowers lie
on the same horizontal or vertical line.
In at least 20% of the test cases, it is further guaranteed that $N \leq
3200$.
输出格式
A single integer, giving the minimum possible amount of cut grass.
输入输出样例
输入 #1
5 20 19 1 2 6 9 15 10 3 13 11
输出 #1
117
In the above example, it is optimal for Bessie to pick the flowers at $(10,3)$
and $(13,11)$. Then in the worst case, Ella and Bella will cut three
rectangles of grass with total area $117$.
and $(13,11)$. Then in the worst case, Ella and Bella will cut three
rectangles of grass with total area $117$.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted