码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ2084 [Poi2010]Antisymmetry

时间:2015-03-16 19:12:38      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

首先我们重新定义0 ≠ 0, 0 = 1, 1 = 0, 1 ≠ 1,然后跑一边manacher就好啦~

然后去现学了manacher。。。

 

技术分享
 1 /**************************************************************
 2     Problem: 2084
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:24 ms
 7     Memory:6176 kb
 8 ****************************************************************/
 9  
10 #include <cstdio>
11 #include <algorithm>
12  
13 using namespace std;
14 typedef long long ll;
15 const int N = 5e5 + 5;
16  
17 int n;
18 char s[N];
19  
20 inline bool check(char a, char b) {
21     return min(a, b) == 0 && max(a, b) == 1;
22 }
23  
24 ll manacher(char st[], int n) {
25     static char s[N << 1];
26     static int rad[N << 1];
27     int mx = 1, id = 1, i;
28     ll res = 0;
29     for (s[0] = $, s[i = 1] = #; i <= n; ++i)
30         s[i << 1] = st[i], s[i << 1 | 1] = #;
31     n = n << 1 | 1;
32     for (i = 1; i <= n; ++i) {
33         rad[i] = max(min(rad[id + id - i], mx - i), 0);
34         while ((s[i + rad[i]] == # && s[i - rad[i]] == #) || (check(s[i + rad[i]], s[i - rad[i]]))) ++rad[i];
35         if (i + rad[i] > mx) mx = i + rad[i], id = i;
36         res += rad[i] >> 1;
37     }
38     return res;
39 }
40  
41 int main() {
42     scanf("%d", &n);
43     scanf("%s", s + 1);
44     printf("%lld\n", manacher(s, n));
45     return 0;
46 }
View Code

 

BZOJ2084 [Poi2010]Antisymmetry

标签:

原文地址:http://www.cnblogs.com/rausen/p/4342488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!