algo.tensai.me's blog

By algo.tensai.me, history, 15 months ago, In English

What?

A small, lean and efficient template for writing code on CodeForces.com using Go. Mostly consists of input/output improvements and helper functions.

Why?

Because I 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

Unroll me!

Suggestions?

Leave them in the comments below, I'll update the template, if necessary.

Happy solving! :)

 
 
 
 
  • Vote: I like it
  • +5
  • Vote: I do not like it

| Write comment?
»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by algo.tensai.me (previous revision, new revision, compare).

»
11 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Now, as generics have been introduced in Go, I think this template can be improved further.

»
11 days ago, # |
  Vote: I like it 0 Vote: I do not like it

In general, how do one make their templates in C++?