You are given a text consisting of N characters (big and small letters of the English alphabet and
digits). A substring of this text is a subsequence of characters that appear on consecutive
positions in the
text. Given an integer K, find the length of the longest substring that appears in the text at least K times (1
≤
N
≤
16384).
Solution:
Having the text’s
suffixes sorted, iterate with a variable i from 0 to N – K and compute the longest
common prefix of suffix i and suffix i + K – 1. The biggest prefix found during
this operation represents
the problem’s solution.
Problem 4:
guess (training camp 2003)
You and the Peasant play a totally uninteresting game. You have a large string and the Peasant
asks you questions like ”does the following string is a substring of yours?”
The Peasant asks you many
questions and you have to answer as quick s you can. Because you are a programmer, you think that it
would be better to know all the substrings that appear in your string.
But before doing all this work, you
are wondering how many distinct substrings are in your string (1
≤
your string’s length
≤
10 000)
Dostları ilə paylaş: