Given a string s, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation. Example 1: Input: "aacecaaa" Output: "aaacecaaa&quo…
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation. For example: Given "aacecaaa", return "aaacecaaa&qu…
Given a string s, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation. Example 1: Input: "aacecaaa" Output: "aaacecaaa&quo…
传送门: [1]:BZOJ [2]:洛谷 •题意 求串 s 中出现的所有奇回文串,并按照长度由大到小排序: 输出前 k 个奇回文串的乘积 mod 19930726; 如果奇回文串的个数不足 k 个,输出 -1: •题解 将串 s 跑一边回文自动机: 将求解出的 len,cnt 数组存入一个结构体中并按照 len 由大到小排序: 将前 k 个奇回文串的长度相乘就行: 记得用快速幂,并且只要奇回文串的长度乘积: •Code #include<bits/stdc++.h> using namespa…
manacher魔改,hash+二分都好写,但是我魔改了个回文自动机就写自闭了orz 根本上来说只要把==改成!=即可,但是这样一来很多停止条件就没了,需要很多特判手动刹车,最后统计一下size即可 #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=500005; int n,ch[N][2],fa[N],dis[N],si[N],con=1,la…
我们预处理出来以i为结尾的最长回文后缀(回文自动机的构建过程中就可以求出)然后就是一个区间覆盖,因为我懒得写贪心,就写了线段树优化的DP. #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int N=101010; const int INF=1e9; int L…
题目链接 题目要求: Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation. For example: Given "aacecaaa", return "a…