結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー aru aruaru aru
提出日時 2020-09-30 21:30:16
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 2,054 bytes
コンパイル時間 12,605 ms
コンパイル使用メモリ 210,284 KB
実行使用メモリ 7,780 KB
最終ジャッジ日時 2023-09-20 17:11:45
合計ジャッジ時間 15,286 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,356 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,356 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,360 KB
testcase_08 AC 1 ms
4,356 KB
testcase_09 AC 1 ms
4,356 KB
testcase_10 AC 2 ms
4,356 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,356 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,356 KB
testcase_15 AC 1 ms
4,360 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 1 ms
4,356 KB
testcase_18 AC 2 ms
4,356 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 1 ms
4,356 KB
testcase_22 AC 11 ms
7,772 KB
testcase_23 AC 12 ms
7,768 KB
testcase_24 AC 10 ms
7,616 KB
testcase_25 AC 11 ms
7,776 KB
testcase_26 AC 12 ms
7,772 KB
testcase_27 WA -
testcase_28 AC 12 ms
7,780 KB
testcase_29 WA -
testcase_30 AC 11 ms
7,768 KB
testcase_31 AC 11 ms
7,772 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 12 ms
7,776 KB
testcase_36 AC 12 ms
7,776 KB
testcase_37 AC 12 ms
7,776 KB
testcase_38 AC 12 ms
7,768 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 12 ms
7,776 KB
testcase_42 WA -
testcase_43 AC 10 ms
7,780 KB
testcase_44 AC 13 ms
7,776 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]
	}
	a = append(a, a...)
	b := make([]int, 0, N)
	c := make([]int, 0, N)
	if s < t {
		for i := s + N + 1; i < t+N; i++ {
			b = append(b, a[i])
		}
		for i := s + N - 1; i > t; i-- {
			c = append(c, a[i])
		}
	} else {
		for i := s + 1; i < t+N; i++ {
			b = append(b, a[i])
		}
		for i := s - 1; i > t; i-- {
			c = append(c, a[i])
		}
	}
	for i := 1; i < len(b); i++ {
		b[i] += b[i-1]
	}
	for i := 1; i < len(c); i++ {
		c[i] += c[i-1]
	}
	// out(a, s, t)
	n := (N - 2 + 1) / 2
	ans := -10000000000
	b = b[:(len(b)+1)/2]
	c = c[:(len(c)+1)/2]
	b = append([]int{0}, b...)
	c = append([]int{0}, c...)
	// out(n)
	// out(b)
	// out(c)
	n++
	for i := 0; i < n; i++ {
		l := i
		r := n - 1 - i
		// out("lr", l, r, len(b), len(c))
		if l >= len(b) || r >= len(c) {
			continue
		}
		// out("ok", b[l])
		v := b[l] + c[r] + a[s]
		// out(l, r, v, tot-v)
		ans = max(ans, v-(tot-v))
	}
	out(ans)
}
0