Logo
(追記) (追記ここまで)

34587번 - Palindromic Distance 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB60463874.510%

문제

The edit distance between two strings $u$ and $v$ is the minimum number of edit operations that turns $u$ into $v$. There are three edit operations that can be applied to a string: Insert a character, delete a character, and substitute some character by a different one.

For example, we can turn hello into world with four substitutions, so the edit distance is at most 4ドル$. You can turn wally into walter with two substitutions and one insertion, so the edit distance is at most 3ドル$. Computing the edit distance between two strings is a well-known problem with many applications.

The task at hand is to compute the edit distance of a string to one of the closest palindromes. A palindrome is a string that is the same when read backwards, for example madam.

The edit distance of hello to the closest palindrome is only 2ドル$: We can turn hello into ollo, or hllh, or elle with two edit operations.

Write a program that can find the distance of a word to a closest palindrome.

입력

Each test contains multiple test cases. The first line contains the number of test cases $t$. The description of the test cases follows.

The only line of each test case contains a word $w$ consisting only of lowercase letters.

출력

For each test case, output the edit distance of the input word $w$ to its closest palindrome.

제한

  • 1ドル ≤ t ≤ 200$
  • The word $w$ has length at least one.
  • It is guaranteed that the sum of the lengths of the words $w$ over all test cases does not exceed 3000ドル$.

예제 입력 1

6
aaaaba
hello
palindrome
abba
x
bababac

예제 출력 1

1
2
5
0
0
1

노트

출처

ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2025 D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /