A - Zebras
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
0010100
3
3 1 3 4
3 2 5 6
1 7
111
-1 蛇皮走位 构造一个方阵,对行来说 0就前进,1就后退
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int N = ;
// name*******************************
vector<int>vec[N];
char s[N];
// function****************************** //***************************************
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
scanf("%s",s+);
int len=strlen(s+);
int r=,k=;
For(i,,len)
{
if(s[i]=='')
vec[++r].pb(i);
else
{
if(r<=)
{
cout<<-;
return ;
}
vec[r--].pb(i);
}
k=max(k,r);
}
if(k!=r)
{
cout<<-;
return ;
}
cout<<k<<endl;
For(i,,k)
{
cout<<vec[i].size()<<" ";
For(j,,vec[i].size()-)
{
cout<<vec[i][j]<<" ";
}
cout<<endl;
} return ;
}
A - Zebras的更多相关文章
- Codeforces Round #469 (Div. 2)C. Zebras(思维+模拟)
C. Zebras time limit per test memory limit per test 512 megabytes input standard input output standa ...
- Codeforces 950 C. Zebras
http://codeforces.com/contest/950/problem/C 题意: 给出一个01序列,问能否将这个序列分为若干个0开头0结尾的序列 输出方案 如果有解,几个1能在一个序列就 ...
- CodeForces - 950C Zebras 模拟变脑洞的天秀代码
题意:给你一个01串,问其是否能拆成若干形如0101010的子串,若能,输出所有子串的0,1 的位置. 题解:一开是暴力,然后瞎找规律, 最后找到一种神奇的线性构造法:扫一遍字符串,若为0就一直竖着往 ...
- Zebras CodeForces - 950C(思维)
借鉴自: https://www.cnblogs.com/SuuT/p/8619227.html https://blog.csdn.net/my_sunshine26/article/details ...
- codeforce469DIV2——C. Zebras
题意 0, 010, 01010 这一类的01交替且开头和结尾都为0的序列被称为zebra序列.给出一段01序列,尝试能否把他分为k个子序列使得每个子序列都是zebra序列. 分析 这个题应该算是水题 ...
- [CodeForces950C]Zebras
Description 题目地址: Codeforces 题意:给你一串只含01的字符串,判断能否将字符串分为k个子序列,使得子序列满足以下条件: 开头和结尾都是0 相邻的2个数是01或者10 如0, ...
- CF949A/950C Zebras
思路: 贪心乱搞. 实现: #include <bits/stdc++.h> using namespace std; vector<vector<int>> v; ...
- CF949A Zebras 构造
是一道不错的构造题. 我们观察,一个 111 的前后必须都有 000. 那么,我们开一个二维数组 (vector)(vector)(vector),这样每遇到一个 000 就将 000 加入到当前的 ...
- Codeforces 950C Zebras ( 贪心 && 模拟 )
题意 : 给出一个 01 串,要求你将其分隔出若干个子序列 ( 每个数字只能属于某一个子序列 ) ,子序列必须满足由 0 开头和结尾,且中间需 01 交替构成.若无法做到,则输出 -1. 分析 : ...
随机推荐
- CF712E Memory and Casinos
设\(f[i]\)为从\(i\)到\(r+1\)且不走出区间的概率 \(f[i]=p[i]f[i+1]+(1-p[i])f[i-1]\) \(f[i]-f[i-1]=p[i](f[i+1]-f[i-1 ...
- 微信小程序< 3 > ~ 微信小程序开源项目合集
简介 移动开发者想学习微信小程序需要学习一点HTML ,CSS和JS才能够比较快速的上手,参考自己学习Android学习过程,阅读源码是一个很好的方式,所以才收集了一些WeApp的开源项目. awes ...
- wampserver的配置教程
对于初做PHP网站的朋友来说,第一步肯定是希望在自己电脑是搭建PHP环境,省去空间和上传的麻烦!但搭建环境也不是件容易的事情,特别是对于新手同学来说!因此在这里跟大家介绍我作为一名新手在使用的方便好用 ...
- Python学习笔记之——requests库
requests库一个优雅而简单的用于Python的HTTP库,可以极大的简化我们发送http请求及获取响应的代码. requests是python的第三方库,所以使用之前需要先安装. 1.安装之后就 ...
- java实现文件复制粘贴功能
java编程思想中讲到了IO流的思想,以前对于java基础总是不够深入,浅尝辄止,如今碰到语句插桩的时候就感到书到用时方恨少啊! 文件的复制涉及到源文件和新文件(无需手动创建),给出源文件的路径和文件 ...
- 完美实现Android的屏幕常亮功能
笔者所在公司做的APP是股票类的,用户在查看股票报价页面的时候,往往需要开启盯盘模式,这个时候屏幕是不能黑屏的,黑屏会导致用户看不到一些关键报价涨跌,错过了买入卖出的最佳时机,就会给用户造成损失,这是 ...
- APP性能测试指标和测试方法
流量 常用方法 方法一:Android系统自带统计功能(总体流量数值) Proc/uid_stat/{UID}/tcp_snd和tcp_rcv UID是每个app安装时候分配的唯一编号用于识别该app ...
- bufferIO,Direct io,mmap, ZeroCopy
1 bufferIO(传统IO),Direct io(干掉内核cache),mmap(大数据映射),zeroCopy(网络IO) 2 linux 5种IO 3NIO 相关知识 这张图展示了mmap() ...
- axios的get,post方法
学习vue和nodejs的过程当中,涉及到了axios,今天为了测试,写了get和post两个方法来跟node服务端交互,结果因为header和参数弄了好久,在此记录一下,同时分享; 由于刚接触axi ...
- mysql InnoDB引擎索引超过长度限制
组合索引长度之和大于 767 bytes并无影响,当有某个字段定义长度大于 767 bytes(1000*3)时,仅产生告警,但不影响创建,超长字段会取前 255 字符作为前缀索引,并且组合索引中字段 ...