一 原题

A. Zebras
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not.

Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days.

Input

In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters.

Output

If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≤ k ≤ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer li (1 ≤ li ≤ |s|), which is the length of the i-th subsequence, and then li indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1.

Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k.

Examples
input

Copy

0010100

output
3
3 1 3 4
3 2 5 6
1 7

input

Copy

111

output
-1

二 分析

题意:给定一个长度不超过2e5的01字符串s,zebra串的形式为0(01)*0,问s能否划分成若干子序列,每个子序列都是一个zebra串。

分析:每个zebra串中0的数量比1的数量多1,所以如果答案如果是可行,那么s中1的数量减去0的数量k就是子序列的数量。如果k<=0,肯定无解。假设有k个桶对应k个子序列,我们的任务就是把s中的每个字符放到一个桶中。桶可以分成两类:下一个字符需要0的和下一个字符需要1的。初始化时每个桶都是要0的,当0放入某个桶后,它成为需要1的那一类;当1放入某个桶后,它成为需要0的那一类。在放字符的过程中可能发生当前字符为x,而不存在需要x的桶,那么此时就可以判定无解了。最后,每个桶都应该进入需要1的状态(zebra串以0结束),如果此时还有需要0的桶,那么也无解。

其实有解的条件等价于对于s的任意前缀和后缀,其中0的数量要大于等于1的数量。满足该条件时,在上述算法中一定不会出现当前字符为x而没有需要x的桶的情况。

三 代码

/*
AUTHOR: maxkibble
LANG: c++ 17
PROB: cf 949A
*/#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>#define pb push_backconst int maxn = 2e5 + 10;char s[maxn];
int n, num;
std::queue<int> q0, q1;
std::vector<int> ans[maxn];int main() {scanf("%s", s + 1);n = strlen(s + 1);for (int i = 1; i <= n; i++) {if (s[i] == '0') num++;else num--;}if (num <= 0) {puts("-1");return 0;}for (int i = 0; i < num; i++) q0.push(i);for (int i = 1; i <= n; i++) {if (s[i] == '0') {if (q0.empty()) {puts("-1");return 0;}int x = q0.front(); q0.pop();q1.push(x);ans[x].pb(i);}else {if (q1.empty()) {puts("-1");return 0;}int x = q1.front(); q1.pop();q0.push(x);ans[x].pb(i);}}if (!q0.empty()) {puts("-1");return 0;}printf("%d\n", num);for (int i = 0; i < num; i++) {printf("%d", ans[i].size());for (int item: ans[i]) printf(" %d", item);puts("");}return 0;
}

cf 949A Zebras相关推荐

  1. 『参考』.net CF组件编程(4)——为自定义组件添加工具箱图标!

    前言: 在前三篇的文章中,和大家一起创建了一个用于TCP连接检测的小组件,如果你记不得了,可以通过以下链接去回顾一下: 『参考』.net CF组件编程(1)--基础之后 『参考』.net CF组件编程 ...

  2. OC对象 vs CF对象

    2019独角兽企业重金招聘Python工程师标准>>> OC对象 vs CF对象 在ARC场景下,对象所有权没有转换 使用__bridge关键字即可实现CF对象和OC对象之间的自由转 ...

  3. CF 990A. Commentary Boxes【数学/模拟】

    [链接]:CF [题意]:对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价. [分析]:分情况讨论,自己多举几个栗子. [代码]: #include<cstdio&g ...

  4. 推荐算法——基于协同过滤CF

    https://www.toutiao.com/a6643326861214482957/ 2019-01-06 18:21:09 前边我们已经介绍了推荐算法里的基于内容的推荐算法CB,今天我们来介绍 ...

  5. 索引贴——移动开发(.Net CF 停止更新)

    这是关于本人博客的技术索引贴,希望能方便的让您阅读到相关技术文章--不断更新中.一整理才发现,好多啊,哈哈- 一..Net CF技巧:搜集.转载一些和CF开发相关的辅助文章,比较适合初学者.开发入门者 ...

  6. 解答:CF截图保存在哪

    为什么80%的码农都做不了架构师?>>>    大家玩CF(穿越火线)的时候遇到精彩的画面总希望截图保存下来,然而有些游戏玩家截图后却不知道CF截图保存在哪!这不得不说是个悲剧,但是 ...

  7. CF里面的资源载入问题

    前一段时间已经发现CF在载入资源的时候会怪怪的,但是这一段时间都不曾记起要对这个问题研究一下.最近又发现这个问题了,实在是恼火.俗话说择日不如撞日(粤语),唉,就今天啦.这个问题是在VS2k5里面调试 ...

  8. [CF.Skills]播放嵌入资源的声音文件

    [CF.Skills]播放嵌入资源的声音文件 摘要:本文阐述了在Windows Mobile中如何播放潜入资源的声音文件KeywordsPlaySound, Windows Mobile, Embed ...

  9. CF#190DIV.1

    1 /* 2 CF#190DIV.1-C 3 题意:给你n个结点的树,给这些结点标记字母AB..Z,对于标记相同的结点路径上 4 的结点的标记必须有一个是大于该标记的:问是否可以标记(A是最大标记) ...

  10. 汇编SF、CF、 OF 、ZF、 PF

    SF=0(最高位是什么,ZF就是什么) CF=1(最高位有进位或借位就置1) ZF=0(结果为0,ZF就置1) OF=1(两个负数相加变成正数,溢出) PF=0(反映结果"1"的个 ...

最新文章

  1. win10 安装xilinx 14.7 之后打开new project 奔溃解决方法
  2. 重写equals和hashCode
  3. 前后端分离微服务架构如何设计?
  4. 小程序开发接口,微信公众平台开发地址
  5. 博客园客户端UAP开发随笔 -- 适配不同尺寸的屏幕
  6. 期刊投稿状态_这些SCI期刊的投稿显示状态是什么意思?
  7. 春运抢票靠加速包?试试这个 Python 开源项目吧
  8. 白板随手一画,嗖嗖变成代码
  9. Windows应用程序进阶2(非模态对话框 通用对话框)
  10. python取出字典重复值_在Python中的字典中查找具有重复值的键
  11. cmd模式下用cd命令进入其他盘或者文件夹
  12. RocketMQ——顺序消费(代码)
  13. Ubuntu 2004 鼠标可以移动但是点击无响应 排查流程
  14. 腾讯云轻量8核16G服务器18M带宽CPU流量性能测评
  15. android 下测试网络的丢包率和延迟
  16. 2022年中职组“网络安全”赛项湖南省任务书
  17. Python爬取cosplay小姐姐图片
  18. strtol()函数介绍
  19. ARM处理器的工作模式。
  20. 【MOT评价指标】MOTA MOTAL MOTP Rcll IDF1 MT ML FP FN ID_SW Frag Hz

热门文章

  1. 关于二分查找那些事儿~~~~看完至少节省你两个半月的时间!!!!!
  2. python:实现base64加密和base64解密算法(附完整源码)
  3. linux命令之journalctl —— 筑梦之路
  4. 第三方支付平台:微信支付接口
  5. 全息投影手机Alo将引领未来趋势!全息3d 网
  6. [Python]自学笔记36:论一只爬虫的自我修养3:隐藏
  7. 冰刃(icesword) V1.22 Final┊官方中文绿色版
  8. CAD系统变量(参数)大全
  9. 计算机的音乐怎样弹生日快乐,5 分钟让你学会用吉他弹《生日快乐》歌
  10. STM8入门以及程序编译、烧录、IAR使用方法(扫盲篇)