Whats wrong in my code

Problem-ALG1705 here
I got the sample case correct,but I get WA when I submit my code.
Here is my code.
Please help.

1 Like

First of all you are applying brute force here which will definitely leads TLE. Your complexity goes upto

O(TNN) which will kill the given time limit! So first of all change your algorithm!

So i think this question is from LCP(Longest common prefix) so please read before!

Good luck

1 Like

@ayush933 you are getting WA because the problem requires all the distinct substrings be sorted and concatenated, so if a string appears more than once in the list of substrings you have to consider that just once. In your code you have considered all substrings, even duplicates. As it says in the problem statement- Note We have distinct substrings here, i.e. if string is aa, it’s distinct substrings are a and aa”.
However if you fix this (maybe using a set instead of a vector?) you will still get TLE. The fast approach requires suffix array and LCP array. The editorial is up for this problem, take a look here.

1 Like