結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
tsuchinaga
|
| 提出日時 | 2019-04-24 17:34:21 |
| 言語 | Go (1.23.4) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 887 bytes |
| コンパイル時間 | 14,410 ms |
| コンパイル使用メモリ | 232,812 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 05:34:54 |
| 合計ジャッジ時間 | 15,359 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
ソースコード
package main
import (
"fmt"
"math"
)
func main() {
var n, a int
_, _ = fmt.Scan(&n)
total := 0
nums := make([]int, n)
for i := range nums {
_, _ = fmt.Scan(&a)
nums[i] = a
total += a
}
// fmt.Println(total)
// fmt.Println(nums)
ans := math.MaxInt64
for i := int(math.Sqrt(float64(total))); i >= 1; i-- { // 最大の高さを小さくしていく
w := 2*i - 1
expect := make([]int, w)
for j := 0; j < i; j++ {
expect[j] = j + 1
expect[w-j-1] = j + 1
}
// fmt.Println(i, w)
// fmt.Println(expect)
// 理想との差異を確認
d := 0
for j := 0; j < int(math.Max(float64(n), float64(w))); j++ {
if j < n && j < w { // 両方ある
if nums[j] > expect[j] {
d += nums[j] - expect[j]
}
} else if j < n { // numsだけある
d += nums[j]
}
}
// fmt.Println(d)
if ans > d {
ans = d
}
}
fmt.Println(ans)
}
tsuchinaga