Algorithm-Library

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

View the Project on GitHub UScuber/Algorithm-Library

:heavy_check_mark: test/yosupo/String/Enumrate-Palindromes.test.cpp

Depends on

Code

#define PROBLEM "https://judge.yosupo.jp/problem/enumerate_palindromes"

#include "../../../template/template.hpp"

#include "../../../string/manacher.hpp"

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  char c;
  string s = "$";
  while((c = getchar()) != 10){
    s += c;
    s += '$';
  }
  const vi res = manacher(s);
  const int l = res.size();
  for(int i = 1; i < l-1; i++){
    if(i & 1) cout << (res[i]-1)/2*2+1 << " ";
    else cout << (res[i]-1)/2*2 << " ";
  }
  cout << "\n";
}
#line 1 "test/yosupo/String/Enumrate-Palindromes.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/enumerate_palindromes"

#line 1 "template/template.hpp"
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
#include <cctype>
#include <climits>
#include <functional>
#include <cassert>
#include <numeric>
#include <cstring>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define per(i, n) for(int i = (n) - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
constexpr int mod = 1000000007;
using namespace std;
template<class T, class U>
bool chmax(T &a, const U &b){ return a < b ? (a = b, 1) : 0; }
template<class T, class U>
bool chmin(T &a, const U &b){ return a > b ? (a = b, 1) : 0; }
#line 4 "test/yosupo/String/Enumrate-Palindromes.test.cpp"

#line 1 "string/manacher.hpp"
vector<int> manacher(const string &s){
  const int len = s.size();
  vector<int> r(len);
  int i = 0, j = 0;
  while(i < len){
    while(i-j >= 0 && i+j < len && s[i-j] == s[i+j]) j++;
    r[i] = j;
    int k = 1;
    while(i-k >= 0 && k+r[i-k] < j) r[i+k] = r[i-k], k++;
    i += k; j -= k;
  }
  return r;
}
#line 6 "test/yosupo/String/Enumrate-Palindromes.test.cpp"

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  char c;
  string s = "$";
  while((c = getchar()) != 10){
    s += c;
    s += '$';
  }
  const vi res = manacher(s);
  const int l = res.size();
  for(int i = 1; i < l-1; i++){
    if(i & 1) cout << (res[i]-1)/2*2+1 << " ";
    else cout << (res[i]-1)/2*2 << " ";
  }
  cout << "\n";
}
Back to top page