Very hard hashing question.

hey can someone please check my code for SSTORY problem i am getting WA and i want to know the reason. i have used hashing + binary search it runs in O(n*(logn)^2). is it because of collisions? thanks for helping.

EDIT : my earlier code was getting WA because my hashing was wrong. there were overflow problems so i corrected it and got AC with same hashing method on a problem at codeforces. so i guess my hashing s correct. but this solution is getting WA here.

someone please tell what should be done in such a situation. i have spent the past week trying to debug this. i just cant find any case where my solution is failing. i am sure my code has some bug but i cant find it. codechef guys will never disclose the test cases also. so what should i do? leave this question and move on?


I was the setter for this problem and, in fact, during the contest, some weakness in test data was detected and we’ve updated the test cases to an harder version.

I suggest you to go trough the editorial and trough both my code, which uses Suffix Automaton concept to solve the task, and the testers/other contestants code, which use several things, from hashing to suffix arrays :slight_smile:

Good luck,


1 Like

yes i have to try some other approach if i am unable to debug this. but can you please give some test case where my current hashing solution would fail. currently i am learning hashing so its very important for me to solve this.