Quick Test CLI provides full support for Go with automatic compilation and execution of your competitive programming solutions.
File Extension
Go files must use the .go extension:
main.go
correct.go
gen.go
Compilation
Go files are compiled using the go build command with a special workflow:
cp main.go ~/.quicktest/go_mod/main.go && \
go build -buildmode=exe -o ./.qt/main ~/.quicktest/go_mod/main.go
Compilation Process
- Copy source file to
~/.quicktest/go_mod/main.go
- Build executable using
go build
- Output binary to
.qt/main
Quick Test CLI uses a dedicated directory at ~/.quicktest/go_mod/ to manage Go modules and dependencies.
Execution
After compilation, the binary is executed with:
Example Code
Here’s a typical Go solution for competitive programming:
package main
import (
"bufio"
"fmt"
"os"
)
var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)
func solveOne() {
var n int
fmt.Fscan(r, &n)
values := make([]int, n)
for i := 0; i < n; i++ {
fmt.Fscan(r, &values[i])
}
best := 0
for i := 0; i < n; i++ {
sum := 0
for j := i; j < n; j++ {
sum += values[j]
best = max(best, sum)
}
}
fmt.Fprintln(w, best)
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func main() {
defer w.Flush()
solveOne()
}
Usage with Quick Test
Compare Mode (cmp)
Compare your solution against a brute-force correct solution:
quicktest cmp --target-file=main.go --correct-file=correct.go --gen-file=gen.go
Stress Testing Mode
Test your solution’s performance:
quicktest stress --target-file=main.go --gen-file=gen.go --tout 1000 --tc 1000
Checker Mode
For problems with multiple valid answers:
quicktest check --target-file=main.go --checker-file=checker.go --gen-file=gen.go
Requirements
You must have Go installed on your system to compile and run Go files.
Verify your installation:
Installing Go
If you don’t have Go installed, visit go.dev/doc/install for installation instructions.
Fast I/O in Go
For competitive programming, use buffered I/O for better performance with large inputs:
import (
"bufio"
"fmt"
"os"
)
var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)
func main() {
defer w.Flush()
// Use fmt.Fscan(r, ...) for input
var n int
fmt.Fscan(r, &n)
// Use fmt.Fprintln(w, ...) for output
fmt.Fprintln(w, n)
}
Common Patterns
// Single integer
var n int
fmt.Fscan(r, &n)
// Multiple integers
var a, b, c int
fmt.Fscan(r, &a, &b, &c)
// Array/Slice
values := make([]int, n)
for i := 0; i < n; i++ {
fmt.Fscan(r, &values[i])
}
Helper Functions
Go doesn’t have built-in min/max for integers, so define them:
func min(a, b int) int {
if a < b {
return a
}
return b
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
Package Structure
All Go files for Quick Test CLI must be in the main package and have a main() function as the entry point.
package main
func main() {
// Your code here
}
Go compiles to native machine code and provides excellent performance for competitive programming, comparable to C++ and Rust.
- Linux: Full support
- Windows: Full support
- macOS: Full support