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. 【Hello 2018 B】Christmas Spruce

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 写个dfs看看是不是每个节点都有3个叶子节点就可以了. [代码] #include <bits/stdc++.h> us ...

  2. 【例题 8-12 UVA-12627】Erratic Expansion

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 规律+递归题 f[k][i] k时刻前i行的红气球个数 i<=2^(k-1) f[k][i] = 2*f[k-1][i]; i ...

  3. ArcGIS Engine中空间参照(地理坐标)相关方法总结

    转自原文 ArcGIS Engine中空间参照(地理坐标)相关方法总结 1.创建空间参考 /// <summary> /// 根据prj文件创建空间参考 /// </summary& ...

  4. Android实战简易教程-第二十五枪(基于Baas的数据表查询下拉刷新和上拉载入实现!)

    上一节我们实现了数据表的载入,可是,当数据表数据非常多时.我们就要考虑数据的分页.这里我们选用了PullToRefreshListView控件,先看一下该控件的说明: 效果图:            ...

  5. Linux网络编程--字节序

    1 .谈到字节序,那么会有朋友问什么是字节序 非常easy:[比如一个16位的整数.由2个字节组成,8位为一字节,有的系统会将高字节放在内存低的地址上,有的则将低字节放在内存高的地址上,所以存在字节序 ...

  6. sqlserver存储过程实现多表分页

    if @PageIndex = 1 begin if @strWhere != ’’ set @strSQL = ’select top ’ + str(@PageSize) +’ ’+@strGet ...

  7. Mahout项目开发环境搭建(Eclipse\MyEclipse + Maven)

    继续 http://www.tuicool.com/articles/rmiEz2 http://www.cnblogs.com/jchubby/p/4454888.html

  8. Cisco安全防护读书笔记之一Cisco系统设备协议漏洞

    650) this.width=650;" onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" ...

  9. Linux下基于LDAP统一用户认证的研究

    Linux下基于LDAP统一用户认证的研究                   本文出自 "李晨光原创技术博客" 博客,谢绝转载!

  10. 解决vmware 和hyper-v不能共存的问题

    只需在 Windows 中以管理员身份运行命令提示符 cmd 1.运行 bcdedit /copy {current} /d "Windows 8 (关闭 Hyper-V)"命令, ...