Advertisement
YEZAELP

CUBE-085: String Partition

Jun 6th, 2021
1,530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int INF = 1e9;
  5. const int N = 1e5;
  6. char str[N+10];
  7.  
  8. int main(){
  9.  
  10.     scanf("%s", str);
  11.  
  12.     int L = strlen(str);
  13.     int mn = INF;
  14.  
  15.     for(int l=1;l<=L/2;l++){
  16.         if(L % l != 0) continue;
  17.         int cnt = 0;
  18.         for(int i=0;i<l;i++){
  19.             int K[27];
  20.             for(int j=0;j<=26;j++) K[j] = 0;
  21.             int mx = 0, c = -1;
  22.             for(int j=i;j<L;j+=l) {
  23.                 K[ str[j]-'a'+1 ] ++;
  24.                 if(K[ str[j]-'a'+1 ] > mx){
  25.                     mx = K[ str[j]-'a'+1 ];
  26.                     c = str[j]-'a'+1;
  27.                 }
  28.             }
  29.             for(int j=0;j<=26;j++){
  30.                 if(j != c){
  31.                     cnt += K[j];
  32.                 }
  33.             }
  34.         }
  35.         mn = min(mn, cnt);
  36.     }
  37.  
  38.     printf("%d", mn);
  39.  
  40.     return 0;
  41. }
  42.  
  43. /**
  44.  
  45. abbbab
  46. ababb
  47.  
  48. **/
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement