798A - Mike and palindrome
Let cnt be the number of such that si ≠ sn - i + 1.
If cnt ≥ 2 then the answer is NO since we must change more than 1 character.
If cnt = 1 then the answer is YES.
If cnt = 0 and n is odd answer is YES since we can change the character in the middle, otherwise if n is even the answer is NO because we must change at least one character.
Complexity is O(|s|).
798B - Mike and strings
First of all, you must notice that the operation of removing the first character and appending it to the left is equivalent to cyclically shifting the string one position to the left.
Let's denote by dpi, j the smallest number of operations for making the first i strings equal to string si moved j times.
Let f(i, j) be the the string si moved j times,then .
The answer is min(dpn, 0, dpn, 1, ..., dpn, |sn| - 1).
The complexity is O(|S|3 × n).