Palindromic Length

시간 제한0.5초메모리 제한2048 MB

요약
주어진 문자열을 가장 적은 수의 팰린드롬 부분 문자열로 나눌 때 그 최소 개수를 구한다.
난이도

어려움10점 중 8점

유형
문자열, 동적 계획법, 문자열 매칭
정답자
아직 제출이 없습니다

문제

A string is called a palindrome if it is read the same forward and backward. Palindromes are useful factors for measuring the complexity of strings like the asymmetry of the strings. The asymmetry of a string SS of length nn can be measured by its palindromic length, PL(S)PL(S), which is the minimum number of palindrome substrings into which SS can be partitioned. More precisely, PL(S)PL(S) is the minimum number tt (1≤t≤n1 ≤ t ≤ n) such that there exist palindrome substrings S_1,S_2,…,S_tS\_1, S\_2, \dots , S\_t whose concatenation S_1S_2⋯S_tS\_1S\_2 \cdots S\_t becomes SS. To make it easier to distinguish, we denote a partition of SS into S_1,S_2,…,S_tS\_1, S\_2, \dots , S\_t as S_1S\_1 | S_2S\_2 | ⋯\cdots | S_tS\_t.

For example, a string S=S = abaaca can be partitioned into two palindrome substrings as aba | aca, that is the minimum, so PL(PL(abaaca)=2) = 2. A string acaba cannot be partitioned into two palindrome substrings, but it can be partitioned into three palindrome substrings, S=S = aca | b | a or S=S = a | c | aba, so PL(PL(acaba)=3) = 3. For S=S = radar, PL(S)=1PL(S) = 1 because SS is a palindrome. PL(S)=5PL(S) = 5 for S=S = abcde.

Given a non-empty string SS of English lowercase letters, write a program to output PL(S)PL(S).

입력

Your program is to read from standard input. The input starts with a line containing a positive integer nn (1≤n≤100,0001 ≤ n ≤ 100\\,000), where nn is the number of letters of a string. The next line contains a string of nn English lowercase letters. Note that the string contains no space between the letters.

출력

Your program is to write to standard output. Print exactly one line. The line should contain a positive integer which is the palindromic length PL(S)PL(S) of the input string SS.

예제4

  1. 예제 1

    입력
    6
    abaaca
    
    예상 출력
    2
    
  2. 예제 2

    입력
    5
    acaba
    
    예상 출력
    3
    
  3. 예제 3

    입력
    5
    abcde
    
    예상 출력
    5
    
  4. 예제 4

    입력
    5
    radar
    
    예상 출력
    1