Really nice approach. That part where you generated the required expression using expansion of e^x was really a new thing to learn !

# Can't wait for the editorials of ADAROOKS2 and BINARY

**psaini72**#43

If this is the intended solution then I really think the time limit is unfair. I had the exact same solution but mine was taking around 6 seconds for n=2\cdot 10^6. Also, n\log^2n for n = 2\cdot 10^6 is around 8.8\cdot 10^8.

Plus the n \log n in that is from NTT/FFT which has a high constant.

*Plus* there is an additional n \log k for actually calculating the polynomial you want to exponentiate. I even used a faster way to exponentiate ( as discussed here ) but still TLE.

If anyone got AC using NTT/FFT then I’m definitely stealing your code.

**psaini72**#44

If you like this then you might like PFRUIT and SERSUM. They also use the series expansion of e^x ( although the editorial for SERSUM doesn’t mention that approach. )

**alei**#45

Sketches of solutions in my blog: https://aleigorithms.wordpress.com/2019/05/06/codechef-may-challenge-2019/

Please find my mistake,am getting WA on submission MATCHES QN MAY LONG CHALLENGE

**psaini72**#46

I had the exact same solution but this just seemed like a random thing that worked. I would like to see a provably largest solution/bound for this.

**apptica**#47

I got AC using NTT. Since K = 1 for larger test cases, so you can actually calculated e^(nx) directly, no need to do exponentiation of the polynomial as the power series of e^x was similar to the generating function.

**psaini72**#48

I just saw that K=1 for the last subtask now .

I just assumed that the constraints for the last subtask are the same as the full constraints because I’ve never seen otherwise.

It is technically my fault but the problem statement writers really should’ve mentioned such an important detail elsewhere.

**kukreja_vlk**#49

I learned about Cayley’s formula and Prüfer sequence, though it wasn’t enough. Waiting for the tut.

**shoryaj**#51

@alei what was the time complexity of the solution expected by the setter, considering your post mentions you expected a lot of WAs for it?

**karangreat234**#52

Arre bidu, ye long challenge toh apann ne 4 ghante mai niptaaya tha vo bhi akhri din mai. Chill rehneka apun ke jaise

**alei**#53

for which problem? I didn’t expected too many WAs in ADAROOKS2 because its easy to check the conditions before submiting. I don’t know why BINARY got few ACs, I saw a similar problem in SnackDown last year, I was expecting it to be problem 3 or 4 in div2.

**shoryaj**#54

I am so sorry. I omitted the word BINARY

I tried a lot of solutions for this problem, and my last one was of linear time. Still I got TLE on 2 test cases. Hence the question.

ADAROOKS personally was easy for me, primarily because I used the concept of finite projective planes.

**shoryaj**#56

@alei basically I used the formula p^2 + p + 1 > N. Gave me all primes between 11 and 37, both inclusive, for given values of N. Then just chose my matrix based on the value of N. The approach worked solely because N started from 100 and thus the smallest matrix (100x100) has 9 rooks per row. And it only increases with N.

You didn’t answer my question though

What was the time complexity expected for BINARY?

**karangreat234**#57

I had a very amazing solution for Adarooks. I can place upto 10 rooks… in each row.

**psaini72**#58

Your solution looks very interesting. Could you explain it in a lot more detail? I looked through your code and I understand what it does but why does it work?

**aryanc403**#59

n*log^2n was not an intended soln for last subtask. O(n) was an intended soln for last subtask.