An Animal Contest 2 P1 - Koala Konundrum

View as PDF

Submit solution


Points: 5
Time limit: 2.0s
Memory limit: 256M

Authors:
Problem type

The koalas are having fun together at the annual Easter festival. Unfortunately, their festival is interrupted by the muttering of a strange koala witch. The koalas don't understand at first, but they eventually notice a pattern. The witch mutters N letters, forming a string S, then a number X. The koalas don't understand the meaning of X, so they rearrange the letters of S to look for a clue. To start off, for each permutation of S, they give it a score Y, with Y representing the minimal number of palindromic substrings this permutation can be split into. Note that each character in the permutation must belong to exactly one substring. After doing some calculations, the koalas notice that X is just the minimum score of Y across all permutations of S!

Now that the koalas know the rule, they devise a game. They will listen to the witch's string and predict X before she says it herself. However, the koalas don't have the brain power to calculate this number and need you to find the answer for them!

A palindrome is a string that is the same as its reverse. For example, strings tacocat, noon, x, and bbbb are palindromes, while strings abab and osuhow are not.

Constraints

1 \leq N \leq 10^6

All characters in string S are lowercase English letters.

Input Specification

The first line contains the integer N, the number of characters in string S.

The second line contains the string S.

Output Specification

Output an integer X, the minimum score of Y across all permutations of S.

Sample Input 1

6
dababy

Sample Output 1

2

Explanation for Sample 1

We arrange the above string into bybada and split it into byb and ada, giving us 2 palindromic substrings. It can be proven that this number is minimal.

Sample Input 2

20
whentheimposterissus

Sample Output 2

8

Comments


  • 0
    MrBloc01  commented on Feb. 26, 2023, 12:35 a.m.

    the sus koala imposter be like


  • 15
    tappbros  commented on Oct. 7, 2021, 1:02 a.m.

    I don't even want to imagine a koala muttering "whentheimposterissus". Would defenitely be... interesting


  • -19
    William_Tian1  commented on Sept. 10, 2021, 2:59 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • 4
      Spitfire720  commented on Sept. 15, 2021, 12:58 p.m.

      You want the min, not the max


  • 5
    HARRIBO  commented on May 17, 2021, 12:43 a.m.

    this problem is sus