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

Автор rajan4, история, 4 года назад, По-английски

This question was asked in internship test. I tried but can't get any idea on how to approach. Any solution provided will be useful P.S : Test was a week ago.. Not ongoing

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

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

We can apply digit DP idea here to solve this problem. Solution: https://ideone.com/MY6Lui

Please see the digit DP blog on codeforces for more info.

P.S. Don't use the code if the contest is currently active.

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

    Can u elaborate the logic little more.... P.S :ans the test has ended week ago.. its not active test.

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

      I'll assume that you know Digit DP.

      Let's say we're building a string t.

      The basic idea is to maintain three states.

      1. The index(idx) where we are at from the MSB side(left side) of the string.

      2. The value f(t[0...idx — 1]) % 7, i.e. the sum of ASCII value of characters from index 0 to idx — 1 MOD 7. The variable used for this in my code is mod.

      3. A flag value which tells if the string t that we're making has already become lexographically smaller than s at some index < idx. If the flag is set, it means that the string that we're making is already smaller than s, so we can put any character from 'a' to 'z' here. But if the flag is not set, it means, that we are constrained to put a character smaller than or equal to the character s[idx].

      The transitions are simple. You are at some index idx, you will want to try to put all the characters here and then move forward. But since we need to make the string t lexographically smaller than or equal to string s, we will be constrainted by the flag value and the character at the current index to put some specific range of characters here at this index.

      Once you've decided to put character ch at this index, just move forward to the index idx + 1, the mod value will change as (mod + ASCII value of ch) % 7, and the flag value will be set in either of these two conditions:

      1. If it's already set.

      2. If it's not set and the character ch that we're placing here is smaller than the corresponding character in the string s.

      You may see the code to catch other minute missed-out details.

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

        Thats great... Thank you for the great explaination and code too. Thanks a ton