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

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

Sorry for disturbing you .

I was trying to solve this SPOJ problem , but failed .

Any suggestion ? Hint ? Tutorial ? Or solution ?

Waiting for positive reply .

My main code

Thanks in advance .

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

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

The maximum possible answer is around $$$10^5$$$ (or less), just bruteforce over all numbers and check if they occurs should work.

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

    I tried this in the range of 1 to 100000. For all the numbers i converted it to a string using to_strint(val) function. Than i checked all sub string of the length of current value. But TLE.

    • »
      »
      »
      4 года назад, # ^ |
      Rev. 2   Проголосовать: нравится -8 Проголосовать: не нравится

      You can't check the occurrences naively. The complexity will be $$$O(10^5 \cdot n)$$$. You can either precalculate all numbers under $$$10^5$$$ that occurs or build a suffix-automaton on the string.

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

        I don't know about suffix-automaton. Can you help with a sample code or tutorial link ?

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

          No need to use that. The easiest way to get AC is:

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

      You shouldn't try every possible number. Think what to do with the maximum possible length of the answer.