manacher

 1 void manacher(){
 2     int res = 0, id = 0;
 3     for(int i = 1; i <= m; i++) {
 4         if(res > i){
 5             p[i] = min(p[2 * id - i], res - i);
 6         }
 7         else{
 8             p[i] = 1;
 9         }
10         //p[i] = mx > i? min(mp[2*id-i], mx-i): 1;
11         while(s[i + p[i]] == s[i - p[i]]){
12             p[i]++;
13         }
14         //while(s[i+mp[i]] == s[i-mp[i]]) mp[i]++;
15         if(i + p[i] > res) {
16             res = i + p[i];
17             id = i;
18         }
19     }
20 }

 

posted on 2015-08-18 00:40  张济  阅读(156)  评论(0编辑  收藏  举报

导航