Source Code
#include <iostream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <vector>
#include <set>
#include <map>
using namespace std;
int main() {
	string s;
	int n = 1e5, c = 0;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		c = 0;
		for (int j = 0; j < s.size(); j++) {
			if (i == j)continue;
			else {
				c += abs(s[i] - s[j]);
			}
		}
		n = min(n, c);
	}
	cout << n;
	return 0;
}
Copy
Palindrome Substrings Sarah
GNU G++17
1099 ms
828 KB
Time Limit Exceeded