# ADAROKS2 - a solution discussion

you remember once we are talking about algo with O(1/n) complexity . see his solution is little similar to that XD.

1 Like

Lololololol, I am the famous creator of O(1/N) algorithm which can be applied to any problem. I guess it has been leaked

Yea,the constraints were misleading, it is easy to do for n=1000,then n=100😂

1 Like

and impossible for further smaller N

1 Like

thank you so much for providing explantory solution

I came upon a mathematical generalisation to this.

There always exists such a way of placing rooks such that there are p^3 rooks in a p^2*p^2 board where p is a prime. This relies heavily on modular arithmetic. The basis idea to be considered it is that the set a.x mod p where x varies from 0 to p-1 comprises of all numbers between 0 and p-1 when a is co-prime to p.

Using this, I pre-computed solutions for 121, 169, 361 and 1369. Then, I crop out the first n^2 elements from whichever pre-computed solution is necessary.

https://www.codechef.com/viewsolution/24207746

Just in case someone wants a look.

2 Likes

Thanks for sharing, this is wonderful! I was trying to do something similar but wasn’t able to. I was hoping I’d find a solution like this in the editorial or in the blog, so feels great to find one. Other solutions are very boring and ugly (no offense ).

1 Like

Never really thought that this question could have been done this way also, very unique approach.