Codeforces Round #469 C A. Zebras
題意: 除了開頭和結尾的一個0 能夠單獨存在之外 其餘的 子串都必須01交替 0開頭0結尾 並且這種“zebra” 串 的長度加起來 是母串的長度 輸出每個串的字元所在的位置
解釋樣例1
0 0 1 0 1 0 0
1 2 3 4 5 6 7
3 1 3 4 010
3 2 5 6 010
1 7
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
const int MAXN=200001;
int len,tot=0,now=0;
char s[MAXN];
vector<int> ans[MAXN];
int main(){
ios::sync_with_stdio(false);
cin>>(s+1);
len=strlen(s+1);
for(int i=1;i<=len;++i){
if(s[i]=='0'){
ans[++now].push_back(i);
}
else{
if(now==0){
cout<<-1;return 0;
}
ans[now--].push_back(i);
}
tot=max(tot,now);
}
if(tot!=now) cout<<-1;
else{
cout<<tot<<endl;
for(int i=1;i<=tot;++i){
int Size=ans[i].size();
cout<<Size;
for(int j=0;j<Size;++j)
cout<<" "<<ans[i][j];
cout<<endl;
}
}
return 0;
}
相關文章
- Codeforces Beta Round #76 (Div. 1 Only) A. Frames
- Codeforces Round #470 div2 C
- Codeforces Round 972 (Div. 2) C
- Codeforces Round 973 (Div. 2) C
- Codeforces Round 982 (Div. 2)(A~C)
- codeforces round 961題解(A、B、C)
- Codeforces Round 840題解(A、B、C)
- Codeforces Round 986 (Div. 2) A-C
- Codeforces Round 949題解(A、B、C、D)
- Educational Codeforces Round 100-C. Busy Robot
- Codeforces C. Colored Rooks 構造 (Codeforces Round #518 (Div. 2) )
- Codeforces Global Round 11 C. The Hard Work of Paparazzi
- 【Codeforces Round #437 (Div. 2) C】 Ordering Pizza
- Codeforces Round 933 (Div. 3) (C-G)
- Codeforces Round 955
- Codeforces Round 943 (Div. 3)(C-G1)
- Codeforces Round #665 (Div. 2)A-C題解
- Codeforces Round #537 (Div. 2)C Creative Snap (分治)
- Codeforces Round 977 (Div. 2)(B-C2)
- Educational Codeforces Round 163
- Codeforces Global Round 26
- Codeforces Global Round 27
- Codeforces Global Round 13
- C. Lose it!(思維)Codeforces Round #565 (Div. 3)
- Codeforces Round 976 (Div. 2) and Divide By Zero 9.0(A,B,C)IDE
- Codeforces Global Round 26 補題記錄(A~C2)
- Patrick and Shopping Codeforces Round #332
- Uncowed Forces Codeforces Round #334
- Codeforces Educational Round#98 A
- Codeforces Round 962(Div .3)
- Codeforces Global Round 26 (A - D)
- Educational Codeforces Round 172 Solution
- 2024.12.2 Educational Codeforces Round 172
- Codeforces Round #646 (Div. 2)【C. Game On Leaves 題解】GAM
- C. Dominant Piranha(思維) Codeforces Round #677 (Div. 3)NaN
- 【CodeForces訓練記錄】Codeforces Global Round 27
- Codeforces Round #670 (Div. 2) 深夜掉分(A - C題補題)
- Codeforces Round #373 (Div. 1) C. Sasha and Array 線段樹