Problem Description
Alice get two strings and the lengths are both N. Bored Alice wanna know whether all equal length prefix string of these two strings are CycleEqual. For example, "abc" and "bca" and "cab" are CycleEqual. So you need output N character, '0' is no, '1' is yes.
Input
The input contains multiple test cases.
For each test case, the first contains one string and the second line contains one string. The lengths of strings are both N(1≤N≤10000) .
For each test case, the first contains one string and the second line contains one string. The lengths of strings are both N(1≤N≤10000) .
Output
For each test case, output N characters. For ith character, if prefix strings of first i character are CycleEqual, output '1', else output '0'.
Sample Input
abc cab aa aa
Sample Output
001 11
bitset瞎搞,想这种问题真废脑子啊,顺便知道了,数据范围是10000的很有可能就是这种套路。
#include<set> #include<map> #include<ctime> #include<cmath> #include<stack> #include<queue> #include<bitset> #include<cstdio> #include<string> #include<cstring> #include<iostream> #include<algorithm> #include<functional> #define rep(i,j,k) for (int i = j; i <= k; i++) #define per(i,j,k) for (int i = j; i >= k; i--) using namespace std; typedef __int64 LL; const int low(int x) { return x&-x; } const double eps = 1e-8; const int INF = 0x7FFFFFFF; const int mod = 998244353; const int N = 1e4; int T, n; char a[N], b[N]; bitset<N> as[N], bs[N], g[N], A[26], B[26], ans; int main() { g[0].reset(); g[0].set(0); rep(i, 1, N - 1) g[i] = g[i - 1] << 1, g[i].set(0); while (scanf("%s%s", a, b) != EOF) { n = strlen(a); rep(i, 0, 25) A[i].reset(), B[i].reset(); rep(i, 0, n - 1) { A[a[i] - 'a'].set(i); B[b[i] - 'a'].set(i); } as[0] = A[b[0] - 'a']; rep(i, 1, n - 1) as[i] = as[i - 1] & (A[b[i] - 'a'] >> i); bs[0] = B[a[0] - 'a']; rep(i, 1, n - 1) bs[i] = bs[i - 1] & (B[a[i] - 'a'] >> i); ans.reset(); rep(i, 0, n - 1) { int q = 0, r = n - i - 1; while (q <= r) { if (as[q + r >> 1][i]) q = (q + r >> 1) + 1; else r = (q + r >> 1) - 1; } if (i) ans |= (bs[i - 1] & g[q]) << i - 1; else if (q) ans |= g[q - 1]; } rep(i, 0, n - 1) printf("%d", (int)ans[i]); putchar(10); } return 0; }