#GD0000202. Biến xâu thành các cặp giống nhau (Get an Even String)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Biến xâu thành các cặp giống nhau (Get an Even String)
Get an Even String
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A string is called even if it can be partitioned into adjacent pairs of identical characters. Equivalently, its length is even and characters at each odd position match their immediate successors. The empty string is even.
For example, aa, aabb, and ttcccc are even, while aaa and abba are not.
Given a lowercase English string , you may delete characters at arbitrary positions while preserving the order of those that remain. Find the minimum number of deletions needed to obtain an even string. Do not output the resulting string.
Input
The only line contains a nonempty lowercase English string .
Output
Print one integer: the fewest deletions needed to make the remaining string a concatenation of equal-character pairs.
Subtasks
- Subtask 1 (20 points): ; Every character of is in
a–z. - Subtask 2 (30 points): ; Every character of is in
a–z. - Subtask 3 (50 points): ; Every character of is in
a–z.
Examples
Input
aabbdabdccc
Output
3
Explanation
The input contains the characters a a b b d a b d c c c. Deleting original positions (a), (b), and (c) leaves aabbddcc, four valid pairs. One deletion would leave ten characters, but no such deletion yields valid pairs; two deletions leave an odd length. Therefore three deletions are minimum.