結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー ccppjsrbccppjsrb
提出日時 2020-08-07 23:42:47
言語 Go
(1.22.1)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 2,035 bytes
コンパイル時間 13,964 ms
コンパイル使用メモリ 225,608 KB
実行使用メモリ 5,488 KB
最終ジャッジ日時 2023-10-25 05:46:01
合計ジャッジ時間 15,743 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 1 ms
4,372 KB
testcase_12 AC 1 ms
4,372 KB
testcase_13 AC 1 ms
4,372 KB
testcase_14 AC 2 ms
4,372 KB
testcase_15 AC 1 ms
4,372 KB
testcase_16 AC 1 ms
4,372 KB
testcase_17 AC 1 ms
4,372 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 1 ms
4,372 KB
testcase_20 AC 1 ms
4,372 KB
testcase_21 AC 1 ms
4,372 KB
testcase_22 AC 12 ms
5,488 KB
testcase_23 AC 11 ms
5,488 KB
testcase_24 AC 11 ms
5,488 KB
testcase_25 AC 11 ms
5,488 KB
testcase_26 AC 13 ms
5,488 KB
testcase_27 AC 13 ms
5,488 KB
testcase_28 AC 13 ms
5,488 KB
testcase_29 AC 11 ms
5,488 KB
testcase_30 AC 12 ms
5,488 KB
testcase_31 AC 12 ms
5,488 KB
testcase_32 AC 12 ms
5,488 KB
testcase_33 AC 12 ms
5,488 KB
testcase_34 AC 12 ms
5,488 KB
testcase_35 AC 13 ms
5,488 KB
testcase_36 AC 13 ms
5,488 KB
testcase_37 AC 13 ms
5,488 KB
testcase_38 AC 11 ms
5,488 KB
testcase_39 AC 11 ms
5,488 KB
testcase_40 AC 12 ms
5,488 KB
testcase_41 AC 13 ms
5,488 KB
testcase_42 AC 11 ms
5,488 KB
testcase_43 AC 11 ms
5,488 KB
testcase_44 AC 14 ms
5,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	s := getNextInt(scanner) - 1
	t := getNextInt(scanner) - 1
	aa := make([]int64, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}
	if s < t {
		fmt.Fprintln(writer, calc(s, t, aa, 1))
		return
	}
	fmt.Fprintln(writer, calc(t, s, aa, -1))

}

func calc(s, t int, aa []int64, d int64) int64 {
	var ans int64
	n := len(aa)
	l := s
	r := t
	for l < r {
		ans += (aa[l] - aa[r]) * d
		l++
		r--
	}
	xx := make([]int64, 0)
	if l == r {
		xx = append(xx, aa[l%n])
	}
	l = t + 1
	r = s + n - 1
	for l < r {
		ans += (aa[r%n] - aa[l%n]) * d
		l++
		r--
	}
	if l == r {
		xx = append(xx, aa[l%n])
	}
	if len(xx) == 1 {
		ans += xx[0]
	}
	if len(xx) == 2 {
		ans += max(xx[0], xx[1])*2 - (xx[0] + xx[1])
	}
	return ans
}
func max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
0