What?
A quick and efficient template for writing code on CodeForces.com using Go. Mostly consists of input/output improvers and helpers.
Why?
Because I've needed my code to be more compact, wanted more clarity and ease of use. And to speed-up a bit too.
And now I share this template to you guys, to make Go a bit more appealing to use in competitive programming.
P.S.: Mike even updated Go compiler to the current latest version (1.17.3), so using Go can be quite worth a candle :)
How you've made it?
I've got rid of the rather slow group of simple scanners from "fmt", namely:
- fmt.Scan
- fmt.Scanln
- fmt.Scanf
because of their clumsiness and their slowness compared to other available options in Go. To learn more, start with checking some benchmarks from this post.
Instead, there is a reader from bufio, which reads from os.Stdin and is much faster. And it simplifies the code of the program too, because instead of:
var variable type
fmt.Scan(variable)
You can now write like:
variable := readType()
To read an Array (or Slice, actually) with items of some type, located on the current line and separated by spaces, just append 's' at the end of the desired read function like so:
arrayOfVars := readTypes()
Template itself
Suggestions?
Leave them in the comments below, I'll update the template, if necessary.
Happy solving! :)