meaning of the title
Sol
When I hit cf, I was really mentally disabled. I made an abcdad of my own data and had a good time playing with it for a long time... In the end, it's good that ycr gave me a way of thinking, otherwise it would be cold...
First of all, it's not hard to see that we can make the string in the form of \ (aaaabbb \) at last. If the current bit is different from the next bit, we can directly convert it
Pay attention to the last position
/* */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<vector> #include<set> #include<queue> #include<cmath> #include<tr1/unordered_map> //#include<ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/hash_policy.hpp> #define Pair pair<int, int> #define MP(x, y) make_pair(x, y) #define fi first #define se second //#define int long long #define LL long long #define ull unsigned long long #define rg register #define pt(x) printf("%d ", x); //#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++) //char buf[(1 << 22)], *p1 = buf, *p2 = buf; //char obuf[1<<24], *O = obuf; //void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';} //#define OS *O++ = ' '; using namespace std; //using namespace __gnu_pbds; const int MAXN = 1e5 + 10, INF = 1e9 + 10, mod = 998244353; const double eps = 1e-9; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int N, flag[MAXN]; string s, r; string RE(string s, int pre) { for(int i = 0; i < pre; i++) swap(s[i], s[pre - i]); return s; } main() { cin >> s; int N = s.length(); for(int i = 0; i < N; i++) { if(s[i] != s[i + 1]) s = RE(s, i), flag[i] = 1; // cout << s << endl; } string a = s, b = RE(s, N - 1); //cout << a << " " << b << endl; if(flag[N - 1] && (b < a)) flag[N - 1] = 0; for(int i = 0; i < N; i++) printf("%d ", flag[i]); return 0; }