結果

問題 No.77 レンガのピラミッド
コンテスト
ユーザー Kohei
提出日時 2026-10-06 20:31:22
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 836 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 469 ms
コンパイル使用メモリ 82,024 KB
実行使用メモリ 65,896 KB
最終ジャッジ日時 2026-10-06 20:31:25
合計ジャッジ時間 2,826 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 3 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N = int(input())
A = list(map(int, input().split()))

# 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(N): # 開始地点(左端)を固定
        if l + 2*h - 2 >= N:
            break
        model = 1
        sign = 1
        no_need_to_move = 0
        for i in range(2*h - 2 + 1):

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

            if model == h: # 真ん中に到達
                sign *= -1
            model += sign
        score = total - no_need_to_move
        ans = min(ans, score)
print(ans)
0