Tag: While scanf%s turn double | | Char its online
Topic links
bzoj4503: Two strings
Exercises
Burst Bitset
F[I][J] Indicates if S[1..I] has a suffix to match t[1..j]
So suppose S[i+1] can match t[s], make f[i+1][s] | = F[i][s-1]
So the preprocessing sets where each character can match the T, set to [C]
So f[i]= ((f[i-1]<<1) | ( 1<<1)) & Mat[s[i]]
Just make a match on the mat.
Time complexity: O (| s| | T|/32)
Code
#include <cstdio> #include <bitset> #include <cstring> #include <algorithm> #define LL long long# Define GC GetChar () #define PC Putchar#define LD long doubleinline int read () {int x = 0,f = 1; char C = GC; while (C < ' 0 ' | | c > ' 9 ') C = GC; while (c <= ' 9 ' && C >= ' 0 ') x = x * ten + C-' 0 ', C = GC; return x * f;} void print (int x) {if (x >=) print (X/10); PC (x 10 + ' 0 '); } const int MAXN = 100007; Char S[MAXN],T[MAXN]; std::bitset<maxn>mat[30],ans; int main () {scanf ("%s%s", S + 1,t + 1); int n = strlen (s + 1), M = strlen (t + 1); for (int i = 1;i <= n;++ i) mat[s[i]-' A '].set (i); Ans.set (); for (int i = 1;i <= m;++ i) if (t[i]! = '? ') ans &= (mat[t[i]-' a '] >> (i-1)); int cnt = 0; for (int i = 1;i <= n-m + 1;++ i) if (ans[i] = = 1) cnt + +; Print (CNT); PC (' \ n '); for (int i = 1;i <= n-m + 1;++ i) if (ans[i] = = 1) print (i-1), PC (' \ n '); return 0; }
bzoj4503: Two strings of Bitset