// source code from laekov for c0x17 #define PRID "bxjl" #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long dint; const int maxn = 100003; const int mod = 998244353; char a[maxn]; int n, m, ne[maxn], sz[maxn]; void preNext() { ne[1] = 0; for (int i = 2, j = 0; i <= n; ++ i) { for (; j && a[i] != a[j + 1]; j = ne[j]); if (a[i] == a[j + 1] && j + 1 < i) { ne[i] = ++ j; } else { ne[i] = 0; } } memset(sz, 0, sizeof(sz)); for (int i = n; i; -- i) { ++ sz[i]; sz[ne[i]] += sz[i]; } } int main(int argc, char* args[]) { if (argc < 2 || strcmp(args[1], "-nf")) { freopen(PRID ".in", "r", stdin); freopen(PRID ".out", "w", stdout); } scanf("%s", a + 1); n = strlen(a + 1); preNext(); dint ans(0); for (int i = 1; i <= n; ++ i) { ans += sz[i]; } printf("%d\n", (int)(ans % mod)); }
时间: 2024-10-07 05:30:16