做法求 hack

P3435 [POI2006] OKR-Periods of Words

代码如下: ```cpp #include<bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, kmp[N], j, tem; string s; long long ans; int main(){ scanf("%d", &n); cin >> s; s = ' ' + s; for(int i = 2; i <= n; i++){ while(s[i] != s[j + 1] && j) j = kmp[j]; j += (s[i] == s[j + 1]); kmp[i] = j; } for(int i = 1; i <= n; i++){ if(kmp[i] == 0) continue ; tem = i - kmp[i]; tem *= ((i % tem) ? (i / tem) : (i / tem - 1)); ans += 1ll * tem; // printf("%d %d\n", i, tem); } printf("%lld", ans); return 0; } ```
by huangrenheluogu @ 2023-10-08 15:58:17


12 acdacfacdacf 答案应该为48,你这个是42
by lightovernight @ 2023-10-12 19:23:03


@[lightovernight](/user/865674) 谢谢大神
by huangrenheluogu @ 2023-10-17 20:37:47


|