POI 2010 Antisymmetry
Posted evenbao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POI 2010 Antisymmetry相关的知识,希望对你有一定的参考价值。
【题目链接】
https://www.lydsy.com/JudgeOnline/problem.php?id=2084
【算法】
manacher
【代码】
#include<bits/stdc++.h> using namespace std; #define MAXN 500010 int n; char s[MAXN]; inline void Manacher() { int i,len,mx = 0,pos = 0; long long ans = 0; static char tmp[MAXN<<1]; static int p[MAXN<<1]; len = strlen(s+1); for (i = 1; i <= len; i++) { tmp[2*i-1] = ‘#‘; tmp[2*i] = s[i]; } tmp[len = 2 * len + 1] = ‘#‘; for (i = 1; i <= len; i++) { if (tmp[i] != ‘#‘) { p[i] = 1; continue; } if (mx > i) p[i] = min(p[2*pos-i],mx-i); else p[i] = 1; while (i - p[i] >= 1 && i + p[i] <= len && ((tmp[i-p[i]] == ‘#‘ && tmp[i+p[i]] == ‘#‘) || (tmp[i-p[i]] != tmp[i+p[i]]))) p[i]++; if (i + p[i] - 1 > mx) { mx = i + p[i] - 1; pos = i; } } for (i = 1; i <= len; i++) { if (tmp[i] == ‘#‘) ans += (long long)(p[i] - 1) / 2; } printf("%lld ",ans); } int main() { scanf("%d%s",&n,s+1); Manacher(); return 0; }
以上是关于POI 2010 Antisymmetry的主要内容,如果未能解决你的问题,请参考以下文章
BZOJ 2084: [Poi2010]Antisymmetry