Pagini recente » Cod sursa (job #3124964) | OwO | IAP #7: Community Ladder | Concert2 | Cod sursa (job #3202331)
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream in("substr.in");
ofstream out("substr.out");
int n, k, ans;
string s;
int check(int x)
{
unordered_map<string, int> m;
string a;
int nrmax = 0;
for(int i = 0; i<=(int)s.size() - x; i++)
{
a = s.substr(i, x);
//out<<a<<'\n';
if(++m[a] > nrmax)
{
nrmax = m[a];
}
}
return nrmax >= k;
}
int main()
{
in>>n>>k;
in>>s;
int st = 1;
int dr = n / k + (n % k);
int mij;
while(st <= dr)
{
mij = (st + dr) / 2;
if(check(mij))
{
ans = mij;
st = mij + 1;
}
else
{
dr = mij - 1;
}
//out<<'\n'<<'\n';
}
out<<ans;
return 0;
}