Information
- ID
- 9078
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- 5
- Tags
- # Submissions
- 4
- Accepted
- 4
- Uploaded By
#include <iostream>
using namespace std;
#define MAXN 2000006
using ll = long long;
char ch[MAXN];
int las[MAXN];
int cnt[MAXN];
int main()
{
int n;
cin >> n;
ll res = 0;
for (int i = 1; i <= n; i++)
{
cin >> ch[i];
int j = i - 1;
while (j > 0 && ch[j] != ch[i])
{
j = las[j] - 1;
}
las[i] = j;
if (j > 0)
{
res += cnt[i] = cnt[j - 1] + 1;
}
}
cout << res << endl;
return 0;
}
By signing up a HFOJ universal account, you can submit code and join discussions in all online judging services provided by us.