#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int kub[30], ile[N], wsk_min;
long long ans;
int asc(char a){
int z = (int)a-96;
return z;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
string S = ".";
string np;
cin>>np;
S+=np;
for(int i=1;i<=S.size()-1;i++){
for(int j=0;j<=28;j++) kub[j]=0;
string pom = ".";
for(int j=1;j<=i;j++){
kub[asc(S[j])]++;
}
int tmp = kub[asc(S[i])];
bool ok = true;
for(int j=1;j<=26;j++){
if(kub[j]&&kub[j]!=tmp){
ok = false;
break;
}
}
if(ok) ans++;
for(int j=i+1;j<=S.size()-1;j++){
kub[asc(S[j])]++;
kub[asc(S[j-i])]--;
ok = true;
tmp = kub[asc(S[j])];
for(int k=1;k<=26;k++){
if(kub[k]&&kub[k]!=tmp){
ok = false;
break;
}
}
if(ok) ans++;
}
}
cout<<ans;
return 0;
}
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 37 38 39 40 41 42 43 44 45 46 47 48 | #include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; int kub[30], ile[N], wsk_min; long long ans; int asc(char a){ int z = (int)a-96; return z; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); string S = "."; string np; cin>>np; S+=np; for(int i=1;i<=S.size()-1;i++){ for(int j=0;j<=28;j++) kub[j]=0; string pom = "."; for(int j=1;j<=i;j++){ kub[asc(S[j])]++; } int tmp = kub[asc(S[i])]; bool ok = true; for(int j=1;j<=26;j++){ if(kub[j]&&kub[j]!=tmp){ ok = false; break; } } if(ok) ans++; for(int j=i+1;j<=S.size()-1;j++){ kub[asc(S[j])]++; kub[asc(S[j-i])]--; ok = true; tmp = kub[asc(S[j])]; for(int k=1;k<=26;k++){ if(kub[k]&&kub[k]!=tmp){ ok = false; break; } } if(ok) ans++; } } cout<<ans; return 0; } |
English