题解:CF1458D Flip and Reverse
Priestess_SLG · · 题解
这是给人想的????????????
构建图模型,把
代码经过了一点压行处理。
#pragma GCC optimize(3, "Ofast", "inline", "unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
using namespace std;
const int N = 1000010;
const int inf = 1e18;
const int mod = 1e9 + 7;
char s[N];
int buc[N];
signed main()
{
int T;
cin >> T;
while (T--)
{
scanf("%s", s + 1);
int n = strlen(s + 1), x = n;
fill(buc, buc + n + n + 2, 0), for_each(s + 1, s + n + 1, [&](char &o) { ++buc[(o == '1') ? (x++) : (--x)]; });
for_each(s + 1, s + (x = n) + 1, [&](...) { cout << ((buc[x - 1] && (buc[x - 1] > 1 || !buc[x])) ? (--buc[--x], 0) : (--buc[x++], 1)); });
cout << '\n';
}
return 0;
}