@taran_1407 Only two observations were to be made to solve the second question in O(1) time for each query.
F(A^N) = F(F(A)^N)
If the sum of digits of A is 1 or 9, the answer will always be the number itself. For 3 & 6, if N = 1, it will be the number itself. Else if N > 1, it will always be 9.
For the remaining numbers 2, 4, 5, 7 & 8 we just needed to find the cycle after how many multiplication the sum of digits will start repeating.
Here is the link to my solution which runs in constant time for all the subtasks.
Thanks man! Understood where I went wrong. Changed the hash function to b1+201*(b2+201*(p+201*(q)))+last; Using an unordered hash map and a hash of numbers instead of strings removes the TLE. The new hash function removes the WA. Got AC! Only if this has dawned on me during the contest time :\
Could you give further insights as to how you chose the hash function like this? A hash function of p+201*(q+201*(b1+201*(b2)))+last; fails even for the sample test case. Whatās the difference?
I need some help in question āToo much sweetnessā. I have implemented it in similar way as explained in editorial, but getting WA even for subtask#1.
You didnāt multiply p+201(q+201(b1+201*(b2))) by 2 before adding last. This causes collisions in your hash values. There must be atleast two different tuple (p,q,b1,b2,last) which give same hash value.
@teja349 Yes we do discuss the problems as well as the solutions. But if you see to it around 5% (of the total participants) got 100 points and that was the difficulty which I intended to put up for the 3rd problemā¦so that way it was fine.
I know this is not the best implementation and probably complex than other ones mentioned above, but i had implemented it this way, so i shared. This one use dp table instead of map, thus doesnāt use hash.
But my point was not regarding the difficulty. I was thinking that whether every coordinator you proposed to and also the testers did get an O(n^3) solution instead of O(n^2)(which was also pretty easy to point). Then I feel its a deep trouble because the point of coordinator or tester is atleast observing the O(n^2) solution even though you allow O(n^4)to pass (which I believe is unobserved by them or either not pointed out to you by your previous comments).
ANOTHER DOUBT(Anyone can clarify): Is there any possibility that I get an update through mail or any if get a reply to my comment here.