/ * First consider lis calculated from the back, apparently contributed to 0 in many cases greater than 1 if there are 0, then the lis ++, if there are 1, then cnt1 ++, and updated with cnt1 lis ensure correct this greedy, because the [i, j] of this paragraph lis necessarily previous paragraph 0, after a period of one such configuration, the current more surface when a 0, apparently lis + 1 is currently more surface when a 1 if and only if the interval 1 is greater than the number of LIS, to make lis + 1, so if and only if the suffix [i, n] is greater than the number of 1s LIS, for all intervals [i, j], this effect was equivalent to 1 1, may alternatively * / #include <bits / STDC H ++.> the using namespace STD; #define N 200005 char S [N], T [N]; int main () { int n-; CIN >> S; n- = strlen (S ); int LIS = 0 , CNT1 = 0 ; for ( int I = N- . 1;i>=0;i--){ if(s[i]=='0')lis++; else cnt1++; if(cnt1>lis){ t[i]='0'; lis=cnt1; } else t[i]=s[i]; } cout<<t; }