結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー aru aruaru aru
提出日時 2020-09-29 23:28:29
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,793 bytes
コンパイル時間 10,985 ms
コンパイル使用メモリ 214,032 KB
実行使用メモリ 5,544 KB
最終ジャッジ日時 2023-09-18 01:22:52
合計ジャッジ時間 13,167 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N, s, t := getInt(), getInt()-1, getInt()-1
	a := make([]int, N)
	tot := 0
	for i := 0; i < N; i++ {
		a[i] = getInt()
		tot += a[i]
	}
	b := make([]int, 0, N*2)
	for i := t + 1; i < N; i++ {
		b = append(b, a[i])
	}
	for i := 0; i < t; i++ {
		b = append(b, a[i])
	}
	// out(a, tot)
	// out(b)
	// out(a[s], b[N-1-t+s])
	pos := N - 1 - t + s
	n := (N - 2 + 1) / 2
	// out("pos", pos, "n", n)
	l := max(0, pos-n)
	r := min(N-2, pos+n) - n
	// out(l, r)
	totS := 0
	for i := 0; i <= n; i++ {
		totS += b[i+l]
	}
	// out(totS, tot)
	ans := totS - (tot - totS)
	// out(ans)
	for i := l; i < r; i++ {
		totS += -b[i] + b[i+n+1]
		// out(totS, b[i], b[i+n+1])
		x := totS - (tot - totS)
		if abs(x) < abs(ans) {
			ans = x
		}
		// out(totS - (tot - totS))
	}
	out(ans)
}
0