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. Oracel 格式化日期 to_char()

    select empno,ename,job,mgr,to_char(HIREDATE,'yyyy-mm-dd') as 入职日期,sal,comm,deptno from emp order by ...

  2. spark ml阅读笔记

    参考文档:http://www.cnblogs.com/huliangwen/p/7491797.html

  3. POJ 2481 Cows (线段树)

    Cows 题目:http://poj.org/problem?id=2481 题意:有N头牛,每仅仅牛有一个值[S,E],假设对于牛i和牛j来说,它们的值满足以下的条件则证明牛i比牛j强壮:Si &l ...

  4. MySQL具体解释(13)------------事务

    一. 什么是事务 事务就是一段sql 语句的批处理.可是这个批处理是一个atom(原子) .不可切割,要么都运行,要么回滚(rollback)都不运行. 二.为什么出现这样的技术 为什么要使用事务这个 ...

  5. Cocos2d-x 之大牛看法

    (未完毕) cocos2d-x并非一个适合网游client(mmo)的游戏引擎.越是大型游戏,这个小引擎就越无法驾驭(尽管它很受欢迎). 之前我在原来的公司使用的是自主研发的C3引擎,已经对外开放(尚 ...

  6. java初探秘之推断输入的一串字符是否全为小写字母

    import java.io.IOException; import java.util.*; public class Two { public static void main(String[] ...

  7. jquery 04

    $('div').slice(1,3).css('background','red').end().css('color','blue');  入栈原理图: <!DOCTYPE HTML> ...

  8. listview-fading 滚动条样式设置

    fadingEdge-属性用来设置拉滚动条时 ,边框渐变的方向.它有三个属性值可以设置 none:(边框颜色不变) horizontal:(水平方向颜色变淡) vertical:(垂直方向颜色变淡). ...

  9. File Upload with Jersey

    package com.toic.rest; import java.io.File; import java.io.FileOutputStream; import java.io.IOExcept ...

  10. natapp解决Invalid Host header的问题

    最近在做一个微信公众号项目,用微信开发工具调试本地项目,需要做一下内网穿透,代理都配置好了,页面出现这个Invalid Host header错误,内网穿透工具我是用的frps做的,最后通过googl ...