思路:按照下图所示连接
代码:
#pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //#define mp make_pair #define pb push_back #define ls rt<<1, l, m #define rs rt<<1|1, m+1, r #define ULL unsigned LL #define pll pair<LL, LL> #define pii pair<int, int> #define piii pair<pii, pii> #define mem(a, b) memset(a, b, sizeof(a)) #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout); //head const int N = 1e5 + 100; char s[N]; bool vis[N]; int main() { scanf("%s", s); int n = strlen(s); for (int i = 0; i < n; i++) { if(s[i] == '1') vis[i+1] = true; } if(vis[1] == 0 || vis[n-1] == 0 || vis[n] == 1) { printf("-1 "); return 0; } for (int i = 2; i < n-1; i++) { if(vis[i] != vis[n-i]) { printf("-1 "); return 0; } } stack<int> st; for (int i = 1; i <= n; i++) { if(vis[i]) { while(!st.empty()) printf("%d %d ", st.top(), i), st.pop(); } if(i != n)st.push(i); } while(!st.empty()) printf("%d %d ", st.top(), n), st.pop(); return 0; }