A11481 | Water The Garden
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as $n$ consecutive garden beds, numbered from $1$ to $n$ . $k$ beds contain water taps ( $i$ -th tap is located in the bed $x_{i}$ ), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed $x_{i}$ is turned on, then after one second has passed, the bed $x_{i}$ will be watered; after two seconds have passed, the beds from the segment $[x_{i}-1,x_{i}+1]$ will be watered (if they exist); after $j$ seconds have passed ( $j$ is an integer number), the beds from the segment $[x_{i}-(j-1),x_{i}+(j-1)]$ will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment $[x_{i}-2.5,x_{i}+2.5]$ will be watered after $2.5$ seconds have passed; only the segment $[x_{i}-2,x_{i}+2]$ will be watered at that moment.
 The garden from test $1$ . White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.  The garden from test $1$ after $2$ seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed. Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
The garden can be represented as $n$ consecutive garden beds, numbered from $1$ to $n$ . $k$ beds contain water taps ( $i$ -th tap is located in the bed $x_{i}$ ), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed $x_{i}$ is turned on, then after one second has passed, the bed $x_{i}$ will be watered; after two seconds have passed, the beds from the segment $[x_{i}-1,x_{i}+1]$ will be watered (if they exist); after $j$ seconds have passed ( $j$ is an integer number), the beds from the segment $[x_{i}-(j-1),x_{i}+(j-1)]$ will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment $[x_{i}-2.5,x_{i}+2.5]$ will be watered after $2.5$ seconds have passed; only the segment $[x_{i}-2,x_{i}+2]$ will be watered at that moment.
 The garden from test $1$ . White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.  The garden from test $1$ after $2$ seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed. Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
输入格式
The first line contains one integer $t$ — the number of test cases to solve ( $1<=t<=200$ ).
Then $t$ test cases follow. The first line of each test case contains two integers $n$ and $k$ ( $1<=n<=200$ , $1<=k<=n$ ) — the number of garden beds and water taps, respectively.
Next line contains $k$ integers $x_{i}$ ( $1<=x_{i}<=n$ ) — the location of $i$ -th water tap. It is guaranteed that for each  condition $x_{i-1}<x_{i}$ holds.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $200$ .
Note that in hacks you have to set $t=1$ .
Then $t$ test cases follow. The first line of each test case contains two integers $n$ and $k$ ( $1<=n<=200$ , $1<=k<=n$ ) — the number of garden beds and water taps, respectively.
Next line contains $k$ integers $x_{i}$ ( $1<=x_{i}<=n$ ) — the location of $i$ -th water tap. It is guaranteed that for each  condition $x_{i-1}<x_{i}$ holds.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $200$ .
Note that in hacks you have to set $t=1$ .
输出格式
For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
输入输出样例
输入 #1
3 5 1 3 3 3 1 2 3 4 1 1
输出 #1
3 1 4
The first example consists of $3$ tests:
1. There are $5$ garden beds, and a water tap in the bed $3$ . If we turn it on, then after $1$ second passes, only bed $3$ will be watered; after $2$ seconds pass, beds $[1,3]$ will be watered, and after $3$ seconds pass, everything will be watered.
2. There are $3$ garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after $1$ second passes.
3. There are $4$ garden beds, and only one tap in the bed $1$ . It will take $4$ seconds to water, for example, bed $4$ .
1. There are $5$ garden beds, and a water tap in the bed $3$ . If we turn it on, then after $1$ second passes, only bed $3$ will be watered; after $2$ seconds pass, beds $[1,3]$ will be watered, and after $3$ seconds pass, everything will be watered.
2. There are $3$ garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after $1$ second passes.
3. There are $4$ garden beds, and only one tap in the bed $1$ . It will take $4$ seconds to water, for example, bed $4$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted