Now that it's practice time, you can find out how much too slow it is. Try
having your program solve just some fraction of the test cases, and see
whether you get time limit or just wrong answer. Have it solve a different
subset of the same size to make sure you didn't get lucky or unlucky.

On Mon, May 7, 2018, 05:11 Valentin Vidić, <[email protected]> wrote:

> 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
> <https://groups.google.com/d/msgid/google-code/CA%2BAB850Z9gR%3DFCb12eSRii9GC0uDP%3DOm56bEwOymztyfHgxMdA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAHaiWHN%3D0brmjC28YVpF_s%3DE2_S0k4GDxXrf3MVyV%3D9XjF6iAA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to