#include <iostream>
#include <array>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
string S;
cin >> S;
int n = S.size();
long long res = -1LL + n + n;
for (int i = 0; i < n - 1; i++) {
array<int, 3> L = { 0, 0, 0 };
auto& [a, b, c] = L;
auto& comp = L[S[i] - 'a'];
L[S[i] - 'a']++, L[S[i + 1] - 'a']++;
for (int j = i + 2; j < n; j++) {
L[S[j] - 'a']++;
if ((a == 0 || a == comp) && (b == 0 || b == comp) && (c == 0 || c == comp)) res++;
}
}
cout << res;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <iostream> #include <array> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string S; cin >> S; int n = S.size(); long long res = -1LL + n + n; for (int i = 0; i < n - 1; i++) { array<int, 3> L = { 0, 0, 0 }; auto& [a, b, c] = L; auto& comp = L[S[i] - 'a']; L[S[i] - 'a']++, L[S[i + 1] - 'a']++; for (int j = i + 2; j < n; j++) { L[S[j] - 'a']++; if ((a == 0 || a == comp) && (b == 0 || b == comp) && (c == 0 || c == comp)) res++; } } cout << res; } |
English