Can you try converting this Go code to Python to see if it helps with the
speed?
package main
import (
"bufio"
"fmt"
"os"
)
func build2(a []int) int {
s := []int{0}
for i := 0; i < len(a); i++ {
for j := len(s) - 1; j >= 0; j-- {
if s[j] <= a[i] * 6 {
w := s[j] + a[i]
if j == len(s) - 1 {
s = append(s, w)
} else if s[j+1] > w {
s[j+1] = w
}
}
}
}
return len(s) - 1
}
func main() {
in := bufio.NewReader(os.Stdin)
var T int
fmt.Fscan(in, &T)
for t := 0; t < T; t++ {
var n int
fmt.Fscan(in, &n)
a := make([]int, n)
for i := 0; i < n; i++ {
fmt.Fscan(in, &a[i])
}
res := build2(a)
fmt.Printf("Case #%d: %d\n", t + 1, res)
}
}
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/CA%2BAB850Z9gR%3DFCb12eSRii9GC0uDP%3DOm56bEwOymztyfHgxMdA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.