結果
問題 | No.77 レンガのピラミッド |
ユーザー |
|
提出日時 | 2016-03-03 20:20:20 |
言語 | Go (1.23.4) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,002 bytes |
コンパイル時間 | 10,692 ms |
コンパイル使用メモリ | 230,496 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-10 23:30:31 |
合計ジャッジ時間 | 11,800 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 3 WA * 12 RE * 5 |
ソースコード
package mainimport ("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), 0for i := range ns {c := nextInt()sum += cns[i] = c}h := 0for i := 1; ; i++ {if i*i > sum {h = i - 1if h*2-1 > len(ns) {h = n/2 + 1}break}}excess, shortage := 0, 0if 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)}}for _, v := range ns[h*2-1:] {excess += v}count := excess - shortagecount += shortagefmt.Println(count)}func nextLine() string {sc.Scan()return sc.Text()}func nextInt() int {i, _ := strconv.Atoi(nextLine())return i}