CHEFSHIP - Editorial

setter and tester sir can explain there solutions. Please sir.

i have also used LPS(Prefix sum technique) as setter solution but i did not get it! why @rishup_nitdgp used the (len*2>(i+1)). could you please explain me the little bit!

1 Like

It is for avoid overlapping. I explained it here:

@pastor Read about gcc compilers and try to find which gcc is your vs code running on. I mostly use ideone but seems like it still doesn’t support c++17. I used code and compile from codechef only.

can you please provide the cpp code by using hashing

For each iteration you are calculating the hashValue in O(n), thus making your overall complexity O(n*n) which will surely timeout. You need to do some preCalculation as you are calculating the same stuff again and again.
Have a look : CodeChef: Practical coding for everyone

1 Like

in kmp solution of setter why use 2 keys(0,1).is it can using only two 1d-array?
my question is why prefix function is calculated for reverse of array

i found a blog and now on i have c++17 running fine on codeblocks with the same mingw compiler but still no help in vs code i don’t know how to manipulate json in vscode and i guess thats why it is working

I have used the KMP approach. It is getting a WA
Can anybody find mistake in my CODE

Sir can you explain what do you mean by overlapping length ? PLz

@akashbhalotia isnt it also required to check the substrings when their hash values are same?

Why is this approach of find hash values wrong?

void computehashvalues(string s)
{
int l=s.length(),power=31;
hasharr[0]=(s.at(0)-‘a’+1);
for(int i=1;i<=l-1;i++)
{
hasharr[i]=hasharr[i-1]+((s.at(i)-‘a’+1)power);
power=power
p;
}
}
long long int findHash(int si,int ei)
{
if(si==0)
return hasharr[ei];
else
{
return (hasharr[ei]-hasharr[si])/pow(p,si);
}
}

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

https://www.codechef.com/viewsolution/33436196

Why is this approach wrong?

Since u ll be using some value as for modulus so it is quite possible hasharr[ei] < hasharr[si] (after modulus) so in the the findhash function u need to consider mod number as well …

Can plz correct it i am not able to uderstand what corrections do i have to make??

@akashbhalotia for what this if(2*len > i+1)
len = lps1[key][len - 1]; is for??

can anyone please tell why time limit is exceeded in my submission.i used the rolling hashing array
and time complexity according to me is O(n) for each test CodeChef: Practical coding for everyone
My code is in cpp

Hi
https://www.codechef.com/viewsolution/33330471
^^ here’s my solution for CHEFSHIP
(problem link: CHEFSHIP Problem - CodeChef)
(submit here: CodeChef: Practical coding for everyone)
:+1: :slightly_smiling_face:

1 Like

I loved your explanation