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

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

Автор AJ__20, история, 14 месяцев назад, По-английски

You are given an array of strings A of size N. You need to pick two strings Ai and Aj such that len(Ai)* len(Aj) is maximized. Thanks in advance. Edit : Sry, forgot to add the constraints : there was a condition stating those two strings should have no common characters, then what would be the optimal solution ?

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

»
14 месяцев назад, # |
  Проголосовать: нравится +17 Проголосовать: не нравится

You can't do that in less than O($$$\text{total length of all strings}$$$) since you need to read the strings.

»
14 месяцев назад, # |
Rev. 2   Проголосовать: нравится +11 Проголосовать: не нравится

I don't think there is any more optimal way than this?

Спойлер
  • »
    »
    14 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится +4 Проголосовать: не нравится

    Correct idea, but the code is wrong. You forgot to test if the length of a given string is smaller than the largest but larger than the second largest.

    Input:
    3
    a
    abc
    ab
    
    Correct Output:
    6
    
    Your Output:
    3
    
    Corrected code
    • »
      »
      »
      14 месяцев назад, # ^ |
        Проголосовать: нравится +11 Проголосовать: не нравится

      thanks, my bad. Updated the code.

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

      Could you please tell the optimal approach for the modified question?

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

        can you please tell what are the constraints on the length of the array of strings?

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

          That was was asked in test, i forgot the constraints but i tried brute force solution and got tle. My solution is n*n*n, so i was thinking what would be the optimized approach

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

            I guess, you can use bitmasking for this approach, wait lemme write it with the code.

            Time Complexity Analysis
            code