結果
| 問題 | No.77 レンガのピラミッド |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-06 20:43:43 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 865 bytes |
| 記録 | |
| コンパイル時間 | 66 ms |
| コンパイル使用メモリ | 81,440 KB |
| 実行使用メモリ | 67,032 KB |
| 最終ジャッジ日時 | 2026-10-06 20:44:08 |
| 合計ジャッジ時間 | 2,657 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 5 |
| other | WA * 20 |
ソースコード
N = int(input())
A = [0]*N + list(map(int, input().split())) + [0]*N
print(A)
# 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(3*N): # 開始地点(左端)を固定
if l + 2*h - 2 >= 3*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)