-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABC-String
More file actions
36 lines (35 loc) · 748 Bytes
/
ABC-String
File metadata and controls
36 lines (35 loc) · 748 Bytes
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
28
29
30
31
32
33
34
35
36
#include<bits/stdc++.h>
using namespace std;
struct tipo{
long long int a,b,c;
};
bool operator <(const tipo a, const tipo b){
if(a.a==b.a)
if(a.b==b.b)
return a.c < b.c;
else
return a.b< b.b;
return a.a < b.a;
}
map <tipo,long long int> m;
int main(){
long long int sol;
sol=0;
string cad;
cin>>cad;
tipo aux;
aux.a=aux.b=aux.c=0;
m[aux]=1;
for(int i=0;i<cad.size();i++){
if(cad[i]=='A') aux.a++;
else if(cad[i]=='B') aux.b++;
else if(cad[i]=='C') aux.c++;
int resta=min(aux.a,min(aux.b,aux.c));
aux.a-=resta;
aux.b-=resta;
aux.c-=resta;
sol+=m[aux];
m[aux]++;
}
cout<<sol<<'\n';
}