CF729D.Sea Battle

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.

Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").

Galya has already made k shots, all of them were misses.

Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.

It is guaranteed that there is at least one valid ships placement.

加莉娅正在一个 1×n1 \times n 的网格上玩一维海战游戏。在该游戏中,网格上放置了 aa 艘船,每艘船占据 bb 个连续的格子。任意一个格子最多只能属于一艘船,但船之间可以相邻(即允许接触)。

加莉娅不知道船的具体位置。她可以向某些格子射击,每次射击后会被告知该格子是否属于某艘船(这种情况称为“命中”)或不属于任何船(这种情况称为“未命中”)。

加莉娅已经进行了 kk 次射击,且全部为未命中。

你的任务是计算:为确保至少命中一艘船,加莉娅最少还需射击多少个格子(即找出最小的格子集合,使得若她向该集合中所有格子射击,则必然至少有一次命中)。

题目保证至少存在一种合法的船只摆放方式。

输入格式

The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.

The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.

第一行包含四个正整数 nn、aa、bb、kk(1 ≤ n ≤ 2⋅1051 ≤ n ≤ 2·10^5,1 ≤ a, b ≤ n1 ≤ a, b ≤ n,0 ≤ k ≤ n − 10 ≤ k ≤ n - 1)——分别表示网格的长度、网格上船的数量、每艘船的长度,以及 Galya 已经进行的射击次数。

第二行包含一个长度为 nn 的字符串,仅由字符 0 和 1 组成。若第 ii 个字符为 1,则表示 Galya 已向该格子射击;否则表示尚未射击。保证该字符串中恰好有 kk 个 1。

输出格式

In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.

In the second line print the cells Galya should shoot at.

Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.

If there are multiple answers, you can print any of them.

第一行输出最小的格子数量,使得如果加莉娅向这些格子全部射击,则至少命中一艘船。

第二行输出加莉娅应当射击的格子。

每个格子必须恰好输出一次。格子可以以任意顺序输出。格子编号从左至右依次为 11 到 nn。

若存在多种答案,输出任意一种即可。

输入输出样例

  • 输入#1

    5 1 2 1
    00100

    输出#1

    2
    4 2
  • 输入#2

    13 3 2 3
    1000000010001

    输出#2

    2
    7 11

说明/提示

There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.

第一个样例中有一艘船。它可能位于加莉娅已经射击的位置(字符“1”)的左侧或右侧。因此,需要进行两次射击:一次射向左侧区域,一次射向右侧区域。

输入解题思路,AI测评打分。不知道怎么写?

首页