結果

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

ソースコード

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 l + 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[l + 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