結果

問題 No.77 レンガのピラミッド
ユーザー yukirinyukirin
提出日時 2016-03-03 20:18:12
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 952 bytes
コンパイル時間 11,205 ms
コンパイル使用メモリ 222,308 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-19 06:49:57
合計ジャッジ時間 12,102 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 WA -
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 RE -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 RE -
testcase_15 WA -
testcase_16 RE -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 RE -
testcase_22 RE -
testcase_23 WA -
testcase_24 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	ns, sum := make([]int, n), 0
	for i := range ns {
		c := nextInt()
		sum += c
		ns[i] = c
	}

	h := 0
	for i := 1; ; i++ {
		if i*i > sum {
			h = i - 1
			if h*2-1 > len(ns) {
				h = n/2 + 1
			}
			break
		}
	}

	excess, shortage := 0, 0
	if h > ns[h-1] {
		shortage += h - ns[h-1]
	} else {
		excess += ns[h-1] - h
	}
	for i := 0; i < h-1; i++ {
		if i+1 > ns[i] {
			shortage += i + 1 - ns[i]
		} else {
			excess += ns[i] - (i + 1)
		}

		if h-i-1 > ns[i+h] {
			shortage += h - i - 1 - ns[i+h]
		} else {
			excess += ns[i+h] - (h - i - 1)
		}
	}

	count := excess - shortage
	count += shortage
	fmt.Println(count)
}

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

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}
0