Editorial for DMOPC '17 Contest 2 P4 - Mimi and Dictionary


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: Kirito

For 10\% of points, we can iterate over all prefixes, and check if they are a palindrome in \mathcal O(N) time, and see if the string exists in the remainder of the string in \mathcal O(N^2) time.

Time Complexity: \mathcal O(N^3)

For 20\% of points, we can iterate over all prefixes, and check if they are a palindrome in \mathcal O(N) time, and see if the string exists in the remainder of the string in \mathcal O(N) time, by using a linear time string finding algorithm, such as KMP or Rabin-Karp.

Time Complexity: \mathcal O(N^2)

For the remaining 70\% of points, we can run Manacher's Algorithm, and then run the Z-Algorithm, and then use either binary search or preprocessing to determine the answer.

Time Complexity: \mathcal O(N) or \mathcal O(N \log N)


Comments


  • 0
    Ninjaclasher  commented on Nov. 15, 2017, 9:10 p.m.

    Time limit not strict enough. My O(N^2) algorithm passes without a problem.


    • 1
      r3mark  commented on Nov. 15, 2017, 9:23 p.m.

      Yea, unfortunately there are multiple O(N^2) solutions which pass, some of which perform even better than O(N) solutions even on specially crafted data.


      • -1
        imaxblue  commented on Nov. 15, 2017, 11:46 p.m.

        wow its indcyc