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,则肯定能打掉一艘船;

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



【完整代码】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. struct abc
  4. {
  5. int l,r;
  6. };
  7. int n,a,b,k,now=0;
  8. char q[200009];
  9. vector < pair<int,int> > c;
  10. vector <int> ans;
  11. int main()
  12. {
  13. // freopen("F:\\rush.txt","r",stdin);
  14. cin >> n >> a >> b >>k;
  15. scanf("%s",q+1);
  16. for (int i = 1;i <= n;i++)
  17. {
  18. if (q[i] == '0')
  19. {
  20. int j = i+1;
  21. while (j<=n && q[j]=='0')
  22. j++;
  23. c.push_back(make_pair(i,j-1));
  24. now+=((j-i)/b);
  25. i = j-1;
  26. }
  27. }
  28. int num = 0;
  29. for (int i = 0;i <= c.size()-1;i++)
  30. {
  31. int t = b;
  32. while (num <=now-a)
  33. {
  34. if (t+c[i].first-1>c[i].second)
  35. break;
  36. ans.push_back(c[i].first+t-1);
  37. num++;
  38. t+=b;
  39. }
  40. if (num > now-a)
  41. break;
  42. }
  43. int len =ans.size();
  44. printf("%d\n",len);
  45. for (int i = 0;i <= len-2;i++)
  46. cout << ans[i] << " ";
  47. if (len>0)
  48. cout << ans[len-1]<<endl;
  49. return 0;
  50. }

【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. Java_Learn

    20180417 集合类 Collection 如果是实现了list接口的集合类,具备的特点是有序,可重复: 如果是实现了set接口的集合类,具备的特点是无序,不可重复: Collection中的方法 ...

  2. 一台服务器安装运行多个Tomcat及注册服务

    项目需要,自己配置了一下,顺便分享出来. 1.下载对应版本Tomcat,这里下载Tomcat7.0.65.zip; 下载地址:http://archive.apache.org/dist/tomcat ...

  3. 不固定高宽的 div 水平垂直居中

    <div class="father"> <div id="main"></div> </div> .fathe ...

  4. newgrp---将当前登录用户临时加入到已有的组中

    Linux中的newgrp命令主要是将当前登录用户临时加入到已有的组中,用法如下: [linuxidc@localhost etc]$ newgrp grptest 上面命令的含义是将用户linuxi ...

  5. 微信小程序从零开始开发步骤(七)引入外部js 文件

    上一章讲到小程序页面的四种常见的跳转的方法,这一章写如何引入一个外部的js文件,既utils文件夹的用处,其实步骤很简单: 1:准备好外部想要引入的外部文件,命名为util.js,并且填充固定的文件内 ...

  6. 缩放文本框ExpandTextView

    效果图: 代码: import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import ...

  7. OpenCASCADE Job - 上海地目

  8. javascript进阶课程--第二章--对象

    javascript进阶课程--第二章--对象 学习要点 理解面向对象的概念 掌握对象的创建方法 掌握继承的概念和实现方法 基本概念 对象究竟是什么?什么叫面向对象编程? 对象是从我们现实生活中抽象出 ...

  9. linux/unix 基本概念的认识(sha-bang 、PPA)

    PPA:Personal Package Archives : Ubuntu: 比如为安装 emacs,需要首先添加某个PPA: sudo add-apt-repository ppa:cassou/ ...

  10. Android 安卓直播开源: RTMP 推流SDK

    前些日子在github上提交了基于GPUImage的iOS直播推流SDK(https://github.com/runner365/GPUImageRtmpPush) 最近整理了Android直播推流 ...