Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <set>
- #include <map>
- #define fi first
- #define se second
- #define pb push_back
- typedef long long ll;
- using namespace std;
- string s;
- int cnt(int l, int r, char c) {
- if (r - l == 1) {
- return (s[l] != c);
- }
- int m = (l + r) / 2;
- int cnt_left = 0;
- for (int i = l; i < m; i++) {
- if (s[i] != c) cnt_left++;
- }
- int cnt_right = 0;
- for (int i = m; i < r; i++) {
- if (s[i] != c) cnt_right++;
- }
- return min(cnt_left + cnt(m, r, c+1), cnt_right + cnt(l, m, c+1));
- }
- int main() {
- cin >> s;
- cout << cnt(0, (int)s.size(), 'a');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment