fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define f(i, x, n) for (int i = x; i < (int)(n); ++i)
  5.  
  6. char s[8001];
  7. short kmp[8000][8000];
  8. int dp[8001], n;
  9.  
  10. inline int cst(int x) { int an = 0; while (x)++an, x /= 10; return an; }
  11.  
  12. int S(int l, int r){
  13. --l, --r;
  14. /*int &an = sh[l][r];
  15. if (an)return an;
  16. int k = kmp[l][r];*/
  17. return r - l + 1 - kmp[l][r - l];
  18. }
  19.  
  20. int main(){
  21. scanf("%s", s);
  22. n = strlen(s);
  23. f(i, 0, n){
  24. int k = 0;
  25. f(j, 1, n - i){
  26. while (k && s[j + i] != s[k + i])k = kmp[i][k - 1];
  27. if (s[j + i] == s[k + i])++k;
  28. kmp[i][j] = k;
  29. }
  30. }
  31. dp[0] = 0;
  32. f(i, 1, n + 1){
  33. dp[i] = 1e9;
  34. f(j, 1, i + 1){
  35. int l = S(j, i);
  36. if ((i - j + 1) % l)l = i - j + 1;
  37. dp[i] = min(dp[i], dp[j - 1] + l + cst((i - j + 1) / l));
  38. }
  39. }
  40. printf("%d\n", dp[n]);
  41. }
Success #stdin #stdout 0.01s 5508KB
stdin
Standard input is empty
stdout
0