Meaning of the questions: https://codeforc.es/problemset/problem/1204/D2
01 gives you a string, such as: 0111001100111011101000, let you change the string (0 as much as possible so that any of the l ~ r LIS rise longest sequence length invariant).
Q: 0111001100111011101000
A: 0011001100001011101000
Ideas:
Reference Solution: Consider what the string can not be changed.
1.10 is not changed (we called fixed string), 00,01,11 can be changed.
2. Fixed string string plus fixed (and can not be changed).
1 + 3 + 0 string fixed (and can not be changed).
It is similar to the fixed series: 111000101100 like.
Easy to think: Fixed strings can be directly deleted, for example: 01 + 00 + 110010 + 110010 + 1 == 0 will not affect the front and back (and we found an equal number of zeros and ones), but you can not go and change fixed string.
So we can continue to eliminate fixed string.
What about the rest of it all can be changed to 1 0 up.
Problems will be transformed into a similar problem bracket matching, we will move forward from a record number of zeros after the match could well mark the 10 1, and finally the unmarked 1 to a 0 on the line.
1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include <cstdlib>//malloc exit strcat itoa system("cls") 4 #include <iostream>//pair 5 #include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin); 6 #include <bitset> 7 //#include <map> 8 //#include<unordered_map> 9 #include <vector> 10 #include <stack> 11 #include <set> 12 #include <string.h>//strstr substr 13 #include <string> 14 #include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9; 15 #include <cmath> 16 #include <deque> 17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less 18 #include <vector>//emplace_back 19 //#include <math.h> 20 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor 21 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare) 22 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation 23 #define fo(a,b,c) for(register int a=b;a<=c;++a) 24 #define fr(a,b,c) for(register int a=b;a>=c;--a) 25 #define mem(a,b) memset(a,b,sizeof(a)) 26 #define pr printf 27 #define sc scanf 28 #define ls rt<<1 29 #define rs rt<<1|1 30 typedef long long ll; 31 void swapp(int &a,int &b); 32 double fabss(double a); 33 int maxx(int a,int b); 34 int minn(int a,int b); 35 int Del_bit_1(int n); 36 int lowbit(int n); 37 int abss(int a); 38 //const long long INF=(1LL<<60); 39 const double E=2.718281828; 40 const double PI=acos(-1.0); 41 const int inf=(1<<30); 42 const double ESP=1e-9; 43 const int mod=(int)1e9+7; 44 const int N=(int)1e6+10; 45 46 char s[N]; 47 bool f[N]; 48 49 int main() 50 { 51 int l; 52 s[0]='$'; 53 sc("%s",s+1); 54 l=strlen(s)-1; 55 int cnt=0; 56 for(int i=l;i>=1;--i) 57 { 58 if(s[i]=='0') 59 cnt++; 60 else 61 { 62 if(cnt) 63 cnt--,f[i]=1; 64 } 65 } 66 fo(i,1,l) 67 if(s[i]=='1'&&!f[i]) 68 s[i]='0'; 69 pr("%s\n",s+1); 70 return 0; 71 } 72 73 /**************************************************************************************/ 74 75 int maxx(int a,int b) 76 { 77 return a>b?a:b; 78 } 79 80 void swapp(int &a,int &b) 81 { 82 a^=b^=a^=b; 83 } 84 85 int lowbit(int n) 86 { 87 return n&(-n); 88 } 89 90 int Del_bit_1(int n) 91 { 92 return n&(n-1); 93 } 94 95 int abss(int a) 96 { 97 return a>0?a:-a; 98 } 99 100 double fabss(double a) 101 { 102 return a>0?a:-a; 103 } 104 105 int minn(int a,int b) 106 { 107 return a<b?a:b; 108 }