実行環境
Go

Go の環境

言語のバージョン

$ go version
go version go1.20.6 darwin/arm64

ライブラリ

go.mod
module atcoder

go 1.20

require (
        git.sr.ht/~sbinet/gg v0.5.0 // indirect
        github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b // indirect
        github.com/campoy/embedmd v1.0.0 // indirect
        github.com/emirpasic/gods v1.18.1 // indirect
        github.com/go-fonts/liberation v0.3.1 // indirect
        github.com/go-latex/latex v0.0.0-20230307184459-12ec69307ad9 // indirect
        github.com/go-pdf/fpdf v0.9.0 // indirect
        github.com/goccmack/gocc v0.0.0-20230228185258-2292f9e40198 // indirect
        github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
        github.com/liyue201/gostl v1.2.0 // indirect
        github.com/pmezard/go-difflib v1.0.0 // indirect
        golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
        golang.org/x/image v0.13.0 // indirect
        golang.org/x/mod v0.13.0 // indirect
        golang.org/x/text v0.13.0 // indirect
        golang.org/x/tools v0.14.0 // indirect
        gonum.org/v1/gonum v0.14.0 // indirect
        gonum.org/v1/plot v0.14.0 // indirect
)

ディレクトリ構成

  • go.mod
  • go.sum
        • main.go
  • テンプレート

    main.go
    package main
     
    import (
    	"bufio"
    	"fmt"
    	"os"
    	"strconv"
    	"strings"
    )
     
    func main() {
     
    }
     
    type number interface {
    	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64
    }
     
    type customComparable interface {
    	number | string
    }
     
    func sum[T number](arr ...T) T {
    	sum := arr[0]
    	for i := 1; i < len(arr); i++ {
    		sum += arr[i]
    	}
    	return sum
    }
     
    func pow(x, n int) int {
    	res := 1
    	for n > 0 {
    		if n&1 == 1 {
    			res = res * x
    		}
    		x = x * x
    		n >>= 1
    	}
    	return res
    }
     
    func modPow(x, n, m int) int {
    	res := 1
    	for n > 0 {
    		if n&1 == 1 {
    			res = res * x % m
    		}
    		x = x * x % m
    		n >>= 1
    	}
    	return res
    }
     
    func lcm(a, b int) int {
    	return a / gcd(a, b) * b
    }
     
    func gcd(a, b int) int {
    	if b == 0 {
    		return a
    	}
    	return gcd(b, a%b)
    }
     
    func abs[T number](x T) T {
    	if x < 0 {
    		return -x
    	}
    	return x
    }
     
    func min[T customComparable](arr ...T) T {
    	min := arr[0]
    	for _, v := range arr {
    		if v < min {
    			min = v
    		}
    	}
    	return min
    }
     
    func max[T customComparable](arr ...T) T {
    	max := arr[0]
    	for _, v := range arr {
    		if v > max {
    			max = v
    		}
    	}
    	return max
    }
    func ceilDiv(a, b int) int {
    	if b < 0 {
    		return ceilDiv(-a, -b)
    	}
    	if a < 0 {
    		return a / b
    	}
    	return (a + b - 1) / b
    }
     
    func floorDiv(a, b int) int {
    	if b < 0 {
    		return floorDiv(-a, -b)
    	}
    	return (a - positiveMod(a, b)) / b
    }
     
    func positiveMod(a, b int) int {
    	return (a%b + b) % b
    }
     
    var _stdInReader = bufio.NewReader(os.Stdin)
     
    func readLine() string {
    	line, _ := _stdInReader.ReadString('\n')
    	return strings.TrimSpace(line)
    }
     
    func readString() string {
    	return readLine()
    }
     
    func readInt() int {
    	strs := readString()
    	num, _ := strconv.Atoi(strs)
    	return num
    }
     
    func readLong() int64 {
    	strs := readString()
    	num, _ := strconv.ParseInt(strs, 10, 64)
    	return num
    }
     
    func readStrings() []string {
    	line := readLine()
    	return strings.Split(line, " ")
    }
     
    func readInts() []int {
    	strs := readStrings()
    	arr := make([]int, len(strs))
    	for i := 0; i < len(strs); i++ {
    		arr[i], _ = strconv.Atoi(strs[i])
    	}
    	return arr
    }
     
    func readLongs() []int64 {
    	strs := readStrings()
    	arr := make([]int64, len(strs))
    	for i := 0; i < len(strs); i++ {
    		arr[i], _ = strconv.ParseInt(strs[i], 10, 64)
    	}
    	return arr
    }
     
    func readDoubles() []float64 {
    	strs := readStrings()
    	arr := make([]float64, len(strs))
    	for i := 0; i < len(strs); i++ {
    		arr[i], _ = strconv.ParseFloat(strs[i], 64)
    	}
    	return arr
    }
     
    func scanStringVariables(args ...*string) {
    	n := len(args)
    	scanned := 0
    	for n > scanned {
    		inputSlice := readStrings()
    		m := len(inputSlice)
    		if m == 0 || m > n-scanned {
    			fmt.Print("Something wrong in scanStringVariables !!!")
    			return
    		}
    		for i := 0; i < m; i++ {
    			*args[i+scanned] = inputSlice[i]
    		}
    		scanned += m
    	}
    }
     
    func scanIntVariables(args ...*int) {
    	n := len(args)
    	scanned := 0
    	for n > scanned {
    		inputSlice := readInts()
    		m := len(inputSlice)
    		if m == 0 || m > n-scanned {
    			fmt.Printf("m %d n %d scanned %d. ", m, n, scanned)
    			fmt.Print("Something wrong in scanIntVariables !!!")
    			return
    		}
    		for i := 0; i < m; i++ {
    			*args[i+scanned] = inputSlice[i]
    		}
    		scanned += m
    	}
    }
     
    func scanLongVariables(args ...*int64) {
    	n := len(args)
    	scanned := 0
    	for n > scanned {
    		inputSlice := readLongs()
    		m := len(inputSlice)
    		if m == 0 || m > n-scanned {
    			fmt.Print("Something wrong in scanIntVariables !!!")
    			return
    		}
    		for i := 0; i < m; i++ {
    			*args[i+scanned] = inputSlice[i]
    		}
    		scanned += m
    	}
    }
     
    func write(arg ...interface{})                 { fmt.Print(arg...) }
    func writeLine(arg ...interface{})             { fmt.Println(arg...) }
    func writeFormat(f string, arg ...interface{}) { fmt.Printf(f, arg...) }