![:)](./images/smilies/icon_smile.gif)
First of all - input does not follow the specification, number and string don't have to be on the same line. I think I figured out how to read it properly, but it's TLE now.
I optimized my Java code as much as I could short of fiddling with I/O, but I/O alone is just 0.7 secs, shouldn't make that much of a difference.
This is what I do (n - number given (<=10), slen - length of the string):
- read string into an array (O(n))
- sort pointers to substrings (O(n*slen*log(slen)) <- bad?
- go through list of pointers and find the longest repeating sequence (O(n*slen))
I guess my algorithm is too slow, I am not sure what to do to speed things up. I was going to do it in C, but that would involve some learning on my part (strings, sorting,...), so I am trying to avoid it
![:)](./images/smilies/icon_smile.gif)
If it can be done without sorting, please let me know. Oh, I did try using Hashtable, but it gives me MLE - it is just too expensive to use (on UVa, at least).