time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

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.

Input

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.

Output

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.

Examples

input

5 1 2 1

00100

output

2

4 2

input

13 3 2 3

1000000010001

output

2

7 11

Note

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.

【题目链接】:http://codeforces.com/contest/738/problem/D

【题解】



这里的1会把整个序列分成若干个连续的0块;

先算出每个连续的0块里面最多能容纳下多少艘船(连续块的长度/b);

总的容纳船数目设为now;

然后题目所给的船数目为a;

则我们需要在这now艘船里面打掉(now-a+1)艘船(只是假想减小最大的船数目);

(更具体一点就是在每个连续的0块里面每个b个点打掉一个点,这样这个0块里面最大能容纳船的数目就会减1,总的最大能容纳船的数目也会减1);

这样总的最大的船数会小于a,则肯定能打掉一艘船;

记录下所有的连续点块的区间;然后一个一个区间地打就好;



【完整代码】

#include <bits/stdc++.h>

using namespace std;

struct abc
{
int l,r;
}; int n,a,b,k,now=0;
char q[200009];
vector < pair<int,int> > c;
vector <int> ans; int main()
{
// freopen("F:\\rush.txt","r",stdin);
cin >> n >> a >> b >>k;
scanf("%s",q+1);
for (int i = 1;i <= n;i++)
{
if (q[i] == '0')
{
int j = i+1;
while (j<=n && q[j]=='0')
j++;
c.push_back(make_pair(i,j-1));
now+=((j-i)/b);
i = j-1;
}
}
int num = 0;
for (int i = 0;i <= c.size()-1;i++)
{
int t = b;
while (num <=now-a)
{
if (t+c[i].first-1>c[i].second)
break;
ans.push_back(c[i].first+t-1);
num++;
t+=b;
}
if (num > now-a)
break;
}
int len =ans.size();
printf("%d\n",len);
for (int i = 0;i <= len-2;i++)
cout << ans[i] << " ";
if (len>0)
cout << ans[len-1]<<endl;
return 0;
}

【42.86%】【Codeforces Round #380D】Sea Battle的更多相关文章

  1. 【42.86%】【codeforces 742D】Arpa's weak amphitheater and Mehrdad's valuable Hoses

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. 【57.97%】【codeforces Round #380A】Interview with Oleg

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【26.83%】【Codeforces Round #380C】Road to Cinema

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【21.21%】【codeforces round 382D】Taxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【50.88%】【Codeforces round 382B】Urbanization

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【Codeforces Round 1137】Codeforces #545 (Div. 1)

    Codeforces Round 1137 这场比赛做了\(A\).\(B\),排名\(376\). 主要是\(A\)题做的时间又长又交了两次\(wa4\)的. 这两次错误的提交是因为我第一开始想的求 ...

  7. 【Codeforces Round 1132】Educational Round 61

    Codeforces Round 1132 这场比赛做了\(A\).\(B\).\(C\).\(F\)四题,排名\(89\). \(A\)题\(wa\)了一次,少考虑了一种情况 \(D\)题最后做出来 ...

  8. 【Codeforces Round 1120】Technocup 2019 Final Round (Div. 1)

    Codeforces Round 1120 这场比赛做了\(A\).\(C\)两题,排名\(73\). \(A\)题其实过的有点莫名其妙...就是我感觉好像能找到一个反例(现在发现我的算法是对的... ...

  9. 【Codeforces Round 1129】Alex Lopashev Thanks-Round (Div. 1)

    Codeforces Round 1129 这场模拟比赛做了\(A1\).\(A2\).\(B\).\(C\),\(Div.1\)排名40. \(A\)题是道贪心,可以考虑每一个站点是分开来的,把目的 ...

随机推荐

  1. 关于vue.js中v-model与表单控件的双向绑定。

    单选框:<input type="checkbox" id="checkbox" v-model="checked"><l ...

  2. [lougu2243]双端队列搜索

    正统双端队列搜索 回顾:普通队列进行边权为定值的最短路 每次到达都是最优的(意味着不用取min) why? 因为所有状态按照 入队的先后顺序 具有 层次单调性,每次扩展,都往外走一步,满足从起始到该状 ...

  3. Linux 内建命令和系统命令

    shell内建命令是指bash(或其它版本)工具集中的命令.一般都会有一个与之同名的系统命令,比如bash中的echo命令与/bin/echo是两个不同的命令,尽管他们行为大体相仿.当在bash中键入 ...

  4. FileChannel的深入理解

    一,官方描写叙述 一个读,写,映射,操作文件的通道. 文件通道有能够被查询和改动的一个当前位置.文件本身包括了一个可悲读写的变长字节序列,而且它的当前的size会被查询.当被写入的字节超过当前文件的大 ...

  5. Apache-DBUtils包对数据库的操作

    •commons-dbutils 是 Apache 组织提供的一个开源 JDBC工具类库,它是对JDBC的简单封装.学习成本极低.而且使用dbutils能极大简化jdbc编码的工作量,同一时候也不会影 ...

  6. UVa10397_Connect the Campus(最小生成树)(小白书图论专题)

    解题报告 题目传送门 题意: 使得学校网络互通的最小花费,一些楼的线路已经有了. 思路: 存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树 #include <ios ...

  7. 数据库中解析XML

    简介:OPENXML方法使用一例实现导入功能 DECLARE @strProjGUID AS VARCHAR(50)  DECLARE @strProjCode AS VARCHAR(50)  DEC ...

  8. STM32之CAN通讯接收过滤器过滤分析

    一.前言 学习了CAN通讯,底层的东东CAN控制器已经帮你处理完成,也就是CAN通讯协议已经做好,你按协议格式往对应的位扔数据发送就好,所以使用CAN通讯,我们只需要去关心制定发送的数据间的协议,也就 ...

  9. 【Uva 11080】Place the Guards

    [Link]: [Description] 一些城市,之间有道路相连,现在要安放警卫,警卫能看守到当前点周围的边,一条边只能有一个警卫看守,问是否有方案,如果有最少放几个警卫. [Solution] ...

  10. powerdesigner逆向自动生成mysql说明文档、PDM

    做EDI的项目的时候,用到相关工具powerdesigner,正好我们的一个项目对数据设计阶段时相关文档没有很好的保存下来,查找了一下powderdesigner相关文档,采用逆向工程,从mysql数 ...