Here is a quick reference as to why it is not possible to efficiently 
generate all possible latin squares for one given size, let alone all of 
them from 1 to 50: https://en.wikipedia.org/wiki/Latin_square.
See specifically the Number section. There are 1.5*10^86 possible Latin 
squares of size 15; That's not counting the squares of size 16-50.

On Tuesday, April 7, 2020 at 12:55:57 PM UTC-4, Shivanjan Chakravorty wrote:
>
> I had a different approach to solving this problem. I generated all the 
> possible orthogonal latin squares of all possible sizes and for every size 
> cached the mattrices based on their trace. So that way it was like. Now for 
> 1 to 50 this thing is done in less than 3 seconds and now all you have to 
> do is read the input, check if the keys pair exists and print the answer. I 
> do not have any idea why it wasn't accepted. Can anyone tell where was I 
> missing the corner case?
>
> {
> "1": {},
> "2": {
> "2": [[ 1, 2],
> [ 2, 1]]
> },
> "3": {
> "3": [[ 1, 2, 3],
> [ 3, 1, 2],
> [ 2, 3, 1]],
>
> "6": [[ 1, 2, 3],
> [ 2, 3, 1],
> [ 3, 1, 2]]
> },
> "4": {
> "4": [[ 1, 2, 3, 4],
> [ 4, 1, 2, 3],
> [ 3, 4, 1, 2],
> [ 2, 3, 4, 1]],
>
> "8": [[ 1, 2, 3, 4],
> [ 2, 3, 4, 1],
> [ 3, 4, 1, 2],
> [ 4, 1, 2, 3]],
>
> "10": [[ 1, 2, 3, 4],
> [ 3, 4, 1, 2],
> [ 1, 2, 3, 4],
> [ 3, 4, 1, 2]]
> }
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/aa45436a-664c-408a-9b5a-076a5d919cca%40googlegroups.com.

Reply via email to