Can someone help me in identifying, why my code keeps getting NZEC error? I have tried at least 20 times.
My approach is:-
-
Determine the unique numbers (m) and their frequencies.
-
Three cases-
a) Frequency=1, for all numbers.
(Calculate from the highest with the increasing power of 2)
b) Frequency=n, i.e. 1 unique number. (Answer is 2^n-1)
c) else, step 3. -
(i) Calculate all nCr values for unique frequencies and store in dp.
(ii) Create a precomuted matrix (ppp) having sum of combinations till the second
highest frequency for all unique numbers. (Dim=(sf+1, m))
(iii) Create ldp matrix having products from left side. i.e. kth column contains product of columns from 1-k. (Dim = (sf+1, m))
(iv) Create rdp matrix having products from right side. i.e. kth column contains product of columns from k-N. (Dim = (sf+1, m))
(v) For every unique number āiā.
----Ans = ldp[:, i-1]*dp[i]*rdp[1:, i+1] and for highest frequency add (sum of nCr from sf to N)*ldp[-1][i-1]*rdp[-1][i+1]
(I took mod for every product and summation to avoid overflow)
I have also tried to check for overflow problem due to NumPy but, nothing to avail.
https://www.codechef.com/viewsolution/36796480