Hello, here is my code with Go :

package main

import (
"fmt"
)

var matrice [][]int

func creer(n int) [][]int {
matrice0 := [][]int{}
ligne0 := []int{}
for j := 1; j <= n; j++ {
ligne0 = append(ligne0, j)
}
matrice0 = append(matrice0, ligne0)
for i := 1; i < n; i++ {
ligne := []int{}
ligne = append(ligne, matrice0[i-1][n-1])
for j := 1; j < n; j++ {
ligne = append(ligne, matrice0[i-1][j-1])
}
matrice0 = append(matrice0, ligne)
}
return matrice0
}

func trace(matrice [][]int, n int) int {
tm := 0
for ti := 0; ti < n; ti++ {
tm += matrice[ti][ti]
}
return tm
}

func rotation(matrice [][]int, n int) [][]int {
ma := [][]int{}
for ri := 0; ri < n; ri++ {
lig := []int{}
lig = append(lig, matrice[ri][n-1])
for rj := 1; rj < n; rj++ {
lig = append(lig, matrice[ri][rj-1])
}
ma = append(ma, lig)
}
return ma
}

func verifier(matrice [][]int, n int, k int) (bool, [][]int) {
for v := 0; v < n; v++ {
tra := trace(matrice, n)
if tra == k {
return true, matrice
} else {
matrice = rotation(matrice, n)
}
}
return false, nil
}

func main() {
var t, n, k int

fmt.Scanf("%d", &t)

for u := 1; u < t+1; u++ {

fmt.Scanf("%d %d", &n, &k)

matrice = creer(n)

test, matrice := verifier(matrice, n, k)

if test == true {
fmt.Printf("Case #%d: POSSIBLE\n", u)

for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
fmt.Print(matrice[i][j], " ")
}
fmt.Println(" ")
}
} else {
fmt.Printf("Case #%d: IMPOSSIBLE\n", u)
}

}
}

it work fine with given test, but when I submit it , I get a WA (wrong
answer). Please give a particular sample test where the code fail. thanks

Le jeu. 9 avr. 2020 à 00:26, Matt Fenlon <[email protected]> a écrit :

> 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
> <https://groups.google.com/d/msgid/google-code/aa45436a-664c-408a-9b5a-076a5d919cca%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAK19nuu1OPxxPNRFX532_qLKJDQ0PxaRdDDnhzwCc_W3_22jfw%40mail.gmail.com.

Reply via email to