結果

問題 No.77 レンガのピラミッド
ユーザー maspy
提出日時 2020-02-02 22:14:53
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 544 ms / 5,000 ms
コード長 465 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 44,600 KB
最終ジャッジ日時 2024-09-18 21:29:08
合計ジャッジ時間 15,037 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
A = np.array(read().split() + [0] * 110,np.int64)

S = A.sum()
max_ht = int(S ** .5)

answer = 10 ** 18
for h in range(max_ht+1):
    p = np.hstack([np.arange(1,h+1), np.arange(1,h)[::-1]])
    n = len(p)
    x = np.maximum(0, p - A[:n]).sum() + (S - h*h)
    if answer > x:
        answer = x

print(answer)
0