'commit'
This commit is contained in:
16
TangDou/Topic/P4391.cpp
Normal file
16
TangDou/Topic/P4391.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 1000010;
|
||||
int n, ne[N];
|
||||
char p[N];
|
||||
int main() {
|
||||
cin >> n >> (p + 1);
|
||||
// 求模式串ne数组
|
||||
for (int i = 2, j = 0; i <= n; i++) {
|
||||
while (j && p[i] != p[j + 1]) j = ne[j];
|
||||
if (p[i] == p[j + 1]) j++;
|
||||
ne[i] = j;
|
||||
}
|
||||
printf("%d", n - ne[n]);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user