library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub beet-aizu/library

:heavy_check_mark: test/aoj/2934.test.cpp

Depends on

Code

// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2934

#include<bits/stdc++.h>
using namespace std;

#define call_from_test
#include "../../string/manacher.cpp"
#include "../../tools/drop.cpp"
#undef call_from_test

signed main(){
  int n;
  cin>>n;
  string t;
  cin>>t;

  auto ms=manacher(t);
  for(int l=2;l<=n;l++){
    int flg=1;
    for(int i=l-1;i<n;i+=l-1)
      flg&=ms[i]==min(i+1,n-i);
    if(flg) drop(l);
  }

  assert(0);
  return 0;
}
#line 1 "test/aoj/2934.test.cpp"
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2934

#include<bits/stdc++.h>
using namespace std;

#define call_from_test
#line 1 "string/manacher.cpp"

#line 3 "string/manacher.cpp"
using namespace std;
#endif
// https://snuke.hatenablog.com/entry/2014/12/02/235837
//BEGIN CUT HERE
vector<int> manacher(string s){
  int n=s.size();
  vector<int> vs(n);
  for(int i=0,j=0;i<n;){
    while(i-j>=0 and i+j<n and s[i-j]==s[i+j]) j++;
    vs[i]=j;
    int k=1;
    while(i-k>=0 and i+k<n and k+vs[i-k]<j) vs[i+k]=vs[i-k],k++;
    i+=k;j-=k;
  }
  return vs;
}
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed main(){
  return 0;
}
#endif
#line 1 "tools/drop.cpp"

#line 3 "tools/drop.cpp"
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed main(){
  return 0;
}
#endif
#line 9 "test/aoj/2934.test.cpp"
#undef call_from_test

signed main(){
  int n;
  cin>>n;
  string t;
  cin>>t;

  auto ms=manacher(t);
  for(int l=2;l<=n;l++){
    int flg=1;
    for(int i=l-1;i<n;i+=l-1)
      flg&=ms[i]==min(i+1,n-i);
    if(flg) drop(l);
  }

  assert(0);
  return 0;
}
Back to top page