TACHEMIS - Editorial

One reason is that arr is not valid after putting in all those '#'es. You should have updated arr as well.

We cannot help you to debug your code, please only ask something related to the solution in the editorial!

@tuananh93 don’t be rude, of course he can ask for help

First thing is I do not understand how its possible that your code works when you read c[i] twice:

for(i=0;i<k;i++) {
	scanf("%c",&c[i]);
	scanf("%c%d",&c[i],&n[i]);
	res=res+(n[i]*(n[i]+1)/2);
}

but the problem is in n[i]*(n[i]+1)/2, try this test case:

1
1
A 1000000
2 Likes

but it will be typecasted int64 since res is int64…or not?

and one c[i] is just to manange new line

@mugurelionut @nims11 : I have seen hashing being used for string related problems many times, but never understood how its being implemented to solve such problems. Can you provide a brief overview of the concept used in this problem and how hashing is used coupled with a binary search ? (or a link to something similar where this has been explained?)

No, it’s not casted to long long if result is big enought, result type is depends on arguments if those are ints, result is int.

1 Like

@mugurelionut : hi,could you please explain your approach in detail,how exactly you are applying hashing ?

But I have handle them too in this part :-

int l = i - 1 - P[i];
l = l/2 - 1;
int r = i+1+P[i];
r = r/2 - 1;

Or could you tell me a test case where my code gives a WA?

@sandeepandey: In this problem hashing is used to check if a substring of the given string is a palindrome. Let’s say we have the substring from position i to position j. Then we compute a hash h1 for the substring from i to j and a hash h2 for the reverse substring from j to i. If h1=h2 then we can assume that the string from i to j is a palindrome (of course, we could be wrong, but it very unlikely if the hash function is good). The important part is to be able to compute such hashes in O(1) time (after some initial preprocessing).

2 Likes

thanks @utkarsh_lath

Ok, here is a test case

1
5
a 1
b 1
a 1
b 1
a 1

@mugurelionut: Thankyou. I understood your idea of using hashing.Thats pretty cool.but still i dont understand why you are using Binary Search here ?

@sandeepandey Binary search for determining the longest length of a palindrome centered at a point.

P[i]++ should be moved to end of loop.

@utkarsh Thx for that … I saw that mistake n changed the code to

http://www.codechef.com/viewsolution/2400905

but it still gives me WA. Can you plz give me a test case where it fails?

Thx for the repliers … I totally understood the question n solved it correctly :slight_smile: Manacher’s is in my mind now :smiley: