CF645C.Enduring Exodus
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied.
Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance.
为了躲避“恶作剧制造者”(Mischievous Mess Makers)的捣乱,农夫约翰(Farmer John)已放弃自己的农场,动身前往波维尼亚(Bovinia)的另一侧。旅途中,他与他的 k 头奶牛决定入住豪华的“大哞达佩斯特酒店”(Grand Moo-dapest Hotel)。该酒店共有 n 个房间,沿一条直线排列,其中部分房间已被占用。
农夫约翰希望为他自己和他的奶牛预订一组共 k+1 个当前空闲的房间。他希望奶牛尽可能安全,因此希望最小化他所住房间到任意一头奶牛所住房间之间的最大距离。房间 i 与房间 j 之间的距离定义为 ∣j−i∣。请帮助农夫约翰保护他的奶牛,计算出这一可能的最小距离。
输入格式
The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John.
The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in.
输入的第一行包含两个整数 n 和 k(1≤k<n≤100000)——分别表示酒店中的房间总数以及与约翰农民一同旅行的奶牛数量。
第二行包含一个长度为 n 的字符串,用于描述各个房间的状态。该字符串的第 i 个字符为 '0' 表示第 i 个房间空闲,为 '1' 表示第 i 个房间已被占用。题目保证该字符串中至少有 k+1 个字符为 '0',因此必定存在至少一种方式,为约翰农民及其 k 头奶牛选择 k+1 个空闲房间入住。
输出格式
Print the minimum possible distance between Farmer John's room and his farthest cow.
输出农夫约翰的房间与其最远一头奶牛之间的最小可能距离。
输入输出样例
输入#1
7 2 0100100
输出#1
2
输入#2
5 1 01010
输出#2
2
输入#3
3 2 000
输出#3
1
说明/提示
In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms.
In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2.
In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
在第一个样例中,约翰农民可以为自己预订 3 号房间,并为他的奶牛预订 1 号和 4 号房间。到最远奶牛的距离为 2。注意,无法使该距离减小至 1,因为不存在三个连续的空闲房间组成的区间。
在第二个样例中,约翰农民可以为自己预订 1 号房间,并为他唯一的奶牛预订 3 号房间。他与奶牛之间的距离为 2。
在第三个样例中,约翰农民预订了所有三个可用的房间,并选择中间的房间作为自己的房间,使得两头奶牛都紧邻着他。他到最远奶牛的距离为 1。
输入解题思路,AI测评打分。不知道怎么写?