結果

問題 No.999 てん vs. ほむ
ユーザー ccppjsrbccppjsrb
提出日時 2020-05-13 12:24:12
言語 Go
(1.22.1)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 2,172 bytes
コンパイル時間 11,660 ms
コンパイル使用メモリ 216,048 KB
実行使用メモリ 7,776 KB
最終ジャッジ日時 2023-10-12 16:58:05
合計ジャッジ時間 13,349 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,356 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 3 ms
4,352 KB
testcase_09 AC 25 ms
7,772 KB
testcase_10 AC 9 ms
5,472 KB
testcase_11 AC 5 ms
5,468 KB
testcase_12 AC 12 ms
5,476 KB
testcase_13 AC 27 ms
7,776 KB
testcase_14 AC 27 ms
7,776 KB
testcase_15 AC 27 ms
7,776 KB
testcase_16 AC 27 ms
7,776 KB
testcase_17 AC 21 ms
7,776 KB
testcase_18 AC 21 ms
7,768 KB
testcase_19 AC 21 ms
7,776 KB
testcase_20 AC 21 ms
7,772 KB
testcase_21 AC 26 ms
7,772 KB
testcase_22 AC 26 ms
7,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	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 getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(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
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner) << 1
	aa := makeGrid(2, n)
	for i := 0; i < n; i++ {
		aa[i%2][i] = getNextInt64(scanner)
	}
	for i := 0; i < n-1; i++ {
		for j := 0; j < 2; j++ {
			aa[j][i+1] += aa[j][i]
		}
	}
	var ans int64
	for i := 0; i <= n; i += 2 {
		ans = maxint(ans, before(i, aa[0])+after(i, aa[1])-(before(i, aa[1])+after(i, aa[0])))
	}
	fmt.Fprintln(writer, ans)
}
func maxint(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func before(i int, aa []int64) int64 {
	if i == 0 {
		return 0
	}
	return aa[i-1]
}

func after(i int, aa []int64) int64 {
	if i == 0 {
		return aa[len(aa)-1]
	}
	return aa[len(aa)-1] - aa[i-1]
}

func makeGrid(h, w int) [][]int64 {
	index := make([][]int64, h, h)
	data := make([]int64, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}
0