結果

問題 No.77 レンガのピラミッド
コンテスト
ユーザー Kohei
提出日時 2026-10-13 20:59:08
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 42 ms / 5,000 ms
+ 794µs
コード長 821 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 89 ms
コンパイル使用メモリ 64,908 KB
実行使用メモリ 58,760 KB
最終ジャッジ日時 2026-10-13 20:59:17
合計ジャッジ時間 3,438 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N = int(input())
A = list(map(int, input().split())) + [0]*N

# k 乗根
def sqrt(n: int, k = 2):
    l = k - 1
    if not n: return 0
    y = 1 << (n.bit_length() + l) // k
    x = y + 1
    while y < x:
        x = y
        y = (l * x + n // (x ** l)) // k
    return x

total = sum(A)
H = sqrt(total)
ans = total
for h in range(1, H + 1): # ピラミッドの高さを固定
    #for l in range(2*N): # 開始地点(左端)を固定
    if 0 + 2*h - 2 >= 2*N:
        break
    model = 1
    sign = 1
    no_need_to_move = 0
    for i in range(2*h - 2 + 1):

        cur = A[0 + i]
        no_need_to_move += min(cur, model)

        if model == h: # 真ん中に到達
            sign *= -1

        model += sign
    score = total - no_need_to_move
    #print(h, l, score)
    ans = min(ans, score)
print(ans)
0