結果
問題 | No.2335 Jump |
ユーザー |
|
提出日時 | 2023-06-02 21:46:55 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 3,950 bytes |
コンパイル時間 | 20,180 ms |
コンパイル使用メモリ | 222,612 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-28 17:12:52 |
合計ジャッジ時間 | 17,917 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
package mainimport ("bufio""fmt""math""math/big""os""strconv")// 解答欄func solve(sc *myScanner, wr *myWriter) {n := sc.getInt()as := append([]int{0}, sc.getInts(n)...)ans := 0for i := 1; i < n+1; i++ {ans += (as[i] - as[i-1] - 1)}wr.println(ans)}// 入出力の準備(sc, wr)func main() {sc := &myScanner{bufio.NewScanner(os.Stdin)}wr := &myWriter{bufio.NewWriter(os.Stdout)}startBufSize := 4096maxBufSize := math.MaxInt64sc.Buffer(make([]byte, startBufSize), maxBufSize)sc.Split(bufio.ScanWords)solve(sc, wr)wr.Flush()}// useful funcs for slicefunc makeInts(n, x int) []int {res := make([]int, n)for i := range res {res[i] = x}return res}func makeBools(n int, b bool) []bool {res := make([]bool, n)for i := range res {res[i] = b}return res}func countTrue(bs []bool) int {res := 0for _, b := range bs {if b {res++}}return res}// inputtype myScanner struct {*bufio.Scanner}func (sc *myScanner) getInt() int {return sc._getIntOffset(0)}func (sc *myScanner) getInt2() (int, int) {return sc.getInt(), sc.getInt()}func (sc *myScanner) getInt3() (int, int, int) {return sc.getInt(), sc.getInt(), sc.getInt()}func (sc *myScanner) getInt4() (int, int, int, int) {return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()}func (sc *myScanner) getInts(n int) []int {return sc._getIntsOffset(n, 0)}func (sc *myScanner) getIntZeroIndexed() int {return sc._getIntOffset(-1)}func (sc *myScanner) getIntsZeroIndexed(n int) []int {return sc._getIntsOffset(n, -1)}func (sc *myScanner) _getIntOffset(x int) int {res, err := strconv.Atoi(sc.getString())if err != nil {panic(err)}return res + x}func (sc *myScanner) _getIntsOffset(n, x int) []int {res := make([]int, n)for i := range res {res[i] = sc._getIntOffset(x)}return res}func (sc *myScanner) getString() string {sc.Scan()return sc.Text()}func (sc *myScanner) getStrings(n int) []string {res := make([]string, n)for i := range res {res[i] = sc.getString()}return res}func (sc *myScanner) getRunes() []rune {return []rune(sc.getString())}func (sc *myScanner) getFloat() float64 {res, err := strconv.ParseFloat(sc.getString(), 64)if err != nil {panic(err)}return res}func (sc *myScanner) getFloats(n int) []float64 {res := make([]float64, n)for i := range res {res[i] = sc.getFloat()}return res}// outputtype myWriter struct {*bufio.Writer}func (wr *myWriter) println(a ...interface{}) {fmt.Fprintln(wr, a...)}func (wr *myWriter) printf(format string, a ...interface{}) {fmt.Fprintf(wr, format, a...)}// simple math funcs for intfunc max(as ...int) int {res := as[0]for _, a := range as {if res < a {res = a}}return res}func min(as ...int) int {res := as[0]for _, a := range as {if res > a {res = a}}return res}func chMax(a *int, b int) {*a = max(*a, b)}func chMin(a *int, b int) {*a = min(*a, b)}func abs(a int) int {if a < 0 {return -a}return a}func pow(a, n int) int {res := 1b := afor n > 0 {if n&1 > 0 {res *= b}n >>= 1b *= b}return res}func sum(s ...int) int {res := 0for _, v := range s {res += v}return res}func checkPrime(a int) bool {if a == 2 {return true} else if a%2 == 0 {return false}res := truefor q := 3; q*q <= a; q += 2 {if a%q == 0 {res = falsebreak}}return res}func toBInt(a int) *big.Int {return big.NewInt(int64(a))}/*めもint(64)の最大値: 9223372036854775807 = (2^63 - 1)19桁10^18 < 2^60 < 2^63 < 10^1910^19 はintだとオーバーフローするsliceの長さ: 10^8程度までは許される型によるがそれ以上は Out of memory の危険がある1~nの和: {n*(n+1)}/2(1~nの平均値)*n を式変形したもの先に掛け算をすることで必ず2で割り切れる*/