아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Palindrome

시간 제한1초메모리 제한1024 MB

요약
각 항목을 같은 길이의 0이 아닌 숫자 문자열로 바꿀 수 있을 때, 이어 붙인 결과가 회문이 되도록 바꿔야 하는 최소 항목 수를 구한다.
난이도

보통10점 중 5점

유형
문자열 매칭, 투 포인터, 구현
정답자
아직 제출이 없습니다

문제

Little Square found an array aa consisting of NN positive numbers formed of nonzero digits. He can replace any number from aa with another number consisting of as many digits, all nonzero.

After making all the changes he wants, Little Square will form a new number MM by writing the elements of the array aa in order, without spaces. What is the minimum numbers of elements of the array aa which need to be replaced by Little Square for the number MM obtained to be a palindrome.

입력

The first line of standard input will contain an integer NN, the size of the array aa. The second line will contain NN integers consisting only of nonzero digits representing the array aa.

Attention! The numbers read from the input file may be too big for the int data type. It is recommended to use the long long data type.

출력

The standard output will contain only one integer, representing the minimum number of elements of the array a that need to be replaced.

제한

  • 1≤N≤500,0001 ≤ N ≤ 500\\,000
  • 1≤a_i<10181 ≤ a\_i < 10^{18}, for every 1≤i≤N1 ≤ i ≤ N
  • A number is a palindrome if its first digit is equal to its last one, its second digit is equal is equal to the next to last digit and so on. Thus, numbers 44, 121121, 1454114541 are palindromes, while numbers 2121, 433433, 12343121234312 are not palindromes.

힌트

In the first example, Little Square can replace the first number with 1387913879 and the third number with 448448. The number MM will become 13879984489978311387998448997831 which is a palindrome. There is no solution with less than two replacements.

In the second example, Little Square can replace the third number with 13477431125541347743112554.

예제2

  1. 예제 1

    입력
    6
    13577 98 348 997 8 31
    
    예상 출력
    2
    
  2. 예제 2

    입력
    3
    455 21 1347742112664
    
    예상 출력
    1