Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Блог пользователя Valeri_Stanchev

Автор Valeri_Stanchev, история, 9 лет назад, По-английски

Hello everybody,

I need your help! Given a string S (|S| <= 10^5) consisting of uppercase letters and an integer K (K <= |S|). Consider a set consisting of all uppercase letters. We are to choose some letters from that set and replace their occurences in S with a star ('*'). Our goal is to make at least one star appear in each substring of length K and we need to do this choosing minimum number of different letters from the set. Output the minimum number of letters and the letters in different lines. If multiple solutions exist, we can print any of them. For example, if S="ABA" and K=2, then we can choose either 'A' or 'B' and receive "*B*" and "A*A" respectively.

Thanks in advance! :)

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
9 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

OK, it was overkill

»
9 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

does O(26 * 2 ^ 26) solution become accept ?

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I always take 108 computations per second as a standard worst case for a solution to pass in online judges. So if time limit per test is  > 2 seconds it will

»
9 лет назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

For each K sized subsequences(there are N — K + 1 of them) find the mask of the letters that does not occur in that subsequence. Lets call them bad subsets.

Afterwards you need to eliminate all the subsets which is subset of one of the above bad subsets. We can do this by somekind of top bottom dp approach which leads to O((2^26 + N)26) complexity. It might be possible to eliminate factor 26. I did not think about it enoubh yet.