https://programmers.co.kr/learn/courses/30/lessons/60057
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int solution(string s) {
int size = s.size();
int answer = size;
string comp;
for(int i=1;i<size;i++){
int subAnswer =size;
comp = s.substr(0, i);
int count =1;
for(int j=i;j<=size-i;j+=i){
if(s.substr(j, i) == comp){
subAnswer -=i;
count++;
if(j+i> size-i)
subAnswer += to_string(count).size();
}else{
if(count>1) {
subAnswer += to_string(count).size();}
count=1;
comp = s.substr(j, i);
}
}
answer = min(answer, subAnswer);
}
return answer;
}
#include <bits/stdc++.h>
using namespace std;
int f(int n) {
if (n == 1) return 0;
int ret = 0;
while (n) ret++, n /= 10;
return ret;
}
int solution(string s) {
int answer = s.size(), n = s.size();
unordered_set<string> S;
for (int i = 1; i * 2 <= n; ++i) {
S.clear();
int j, len = 0, cnt = 1;
string prv = s.substr(0, i);
S.insert(prv);
for (j = i; j < n; j += i) {
if (S.find(s.substr(j, i)) != S.end()) ++cnt;
else {
len += f(cnt) + i;
S.erase(prv);
S.insert(prv = s.substr(j, i));
cnt = 1;
}
}
len += cnt > 1 ? f(cnt) + i : n - j + i;
answer = min(answer, len);
}
return answer;
}