ADAROKS2 - a solution discussion


#22

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


#23

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


#24

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


#25

and impossible for further smaller N :rofl::rofl:


#26

Here is the unofficial editorial for ADAROOKS:- Unofficial Editorial for ADAROOKS2-MAY-2019-LONG-CHALLENGE


#27

I added a note in my original reply - please see above.


#28

thank you so much for providing explantory solution


#29

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.