ka16's blog

By ka16, history, 9 years ago, In English

To get better at Golang, I decided to try solving Codeforces (CF) problems in Go. I was a bit surprised that the current Go version on CF is (out-of-dated) 1.2, while the current stable Go version is 1.5.
Having said that, my solution for this C div 2 produced correct answers for the given two sample testcases on my computer (with Go 1.5), but gave wrong answers on CF. I've looked at the issue for a while, but could not understand the cause. Could anyone give me some hint?

By the way, is there any plan to update the Go version on Codeforces? I'm not sure who (Mike Mirzayanov?) I should ask for this, though.

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
Rev. 3   Vote: I like it +5 Vote: I do not like it

add "\n" to Scanf

fmt.Scanf("%d\n", &n)
....
fmt.Scanf("%d %d %d\n", &vi, &di, &pi),

Accepted: 13594647

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks, that solved my problem. A lesson learned when using Scanf, but I still does not thoroughly understand how the same code could produce different results on my computer vs CF, though.

    • »
      »
      »
      9 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I suppose, the behaviour of Scanf changed in new versions.

»
9 years ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

I would be also glad to see the update to the Go compiler.

I think it would be a positive change for the CodeForces project as a whole to update all the compilers (if there're new versions of course) at least once a year.

PS: I understand that I can't ask or demand anything, when CodeForces is already awesome :)

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Why are Golang's Scanf very slow. I usually get TLE.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Hi! If you want to read n lines with 3 numbers in line and manipulate with n1, n2, n3 inside for block use this code:

    n := 2
    n1, n2, n3 := 0, 0, 0
    for i:=0; i<n; i++ {
       fmt.Scanf("%d %d %d\n", &n1, &n2, &n3)
    }
    

    In your case use this code to store all numbers you need:

    n := make([]int, 6)
    fmt.Scanf("%d %d %d\n", &n[0], &n[1], &n[2])
    fmt.Scanf("%d %d %d\n", &n[3], &n[4], &n[5])
    

    Good luck in solving problems!