ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

How to write Go solutions

Go programs are compiled on the server by the Go 1.14.6 x64. The compiler is invoked with the following parameters:

go build %1

You can find the compiler here.

An example of solving a problem

A sample solution for the 1000. A + B problem in Go:

package main
import "fmt"

func main() {
   var a, b int
   fmt.Scan(&a)
   fmt.Scan(&b)
   fmt.Println(a + b)
}

A sample solution for the 1001. Reverse Root in Go:

package main
import "fmt"
import "math"

var a [262144]int64

func main() {
   n := 0
   for {
      var x int64
      k, _ := fmt.Scan(&x)
      if k != 1 {
         break
      }
      a[n] = x
      n++
   }
   for n > 0 {
      n--
      fmt.Printf("%.4f\n", math.Sqrt(float64(a[n])))
   }
}

More effective solution of the same problem:

package main
import "os"
import "fmt"
import "math"
import "bufio"
import "strings"
import "strconv"

func main() {
   in := bufio.NewReader(os.Stdin)
   out := bufio.NewWriter(os.Stdout)
   text, _ := in.ReadString(0)
   a := strings.Fields(text)
   for i := len(a) - 1; i >= 0; i-- {
      f, _ := strconv.ParseFloat(a[i], 64)
      fmt.Fprintf(out, "%.4f\n", math.Sqrt(f))
   }
   out.Flush()
}

Earlier compilers

  • Go 1.3.1 was used until September, 1 2020.