結果

問題 No.77 レンガのピラミッド
ユーザー brthyyjpbrthyyjp
提出日時 2021-06-21 19:58:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 87 ms / 5,000 ms
コード長 648 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 76,292 KB
最終ジャッジ日時 2023-09-05 01:55:24
合計ジャッジ時間 3,609 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,280 KB
testcase_01 AC 67 ms
71,208 KB
testcase_02 AC 68 ms
71,168 KB
testcase_03 AC 67 ms
71,396 KB
testcase_04 AC 73 ms
71,008 KB
testcase_05 AC 68 ms
71,276 KB
testcase_06 AC 79 ms
76,256 KB
testcase_07 AC 70 ms
71,264 KB
testcase_08 AC 87 ms
76,092 KB
testcase_09 AC 78 ms
75,768 KB
testcase_10 AC 74 ms
75,452 KB
testcase_11 AC 73 ms
76,028 KB
testcase_12 AC 78 ms
76,292 KB
testcase_13 AC 81 ms
76,252 KB
testcase_14 AC 78 ms
75,936 KB
testcase_15 AC 73 ms
75,988 KB
testcase_16 AC 69 ms
71,200 KB
testcase_17 AC 70 ms
71,168 KB
testcase_18 AC 81 ms
76,036 KB
testcase_19 AC 67 ms
71,396 KB
testcase_20 AC 71 ms
71,232 KB
testcase_21 AC 78 ms
76,172 KB
testcase_22 AC 74 ms
75,444 KB
testcase_23 AC 80 ms
76,268 KB
testcase_24 AC 69 ms
71,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))
s = sum(A)
ans = 10**18
for k in range(1, 101):
    if k**2 > s:
        break
    B = list(range(1, k))+list(range(k, 0, -1))
    #print(B)
    m = len(B)
    temp = 0
    if m >= n:
        for i in range(m):
            if 0 <= i < n:
                if A[i] < B[i]:
                    temp += B[i]-A[i]
            else:
                temp += B[i]
        temp += s-sum(B)
    else:
        for i in range(n):
            if 0 <= i < m:
                if A[i] < B[i]:
                    temp += B[i]-A[i]
        temp += s-sum(B)
    #print(temp, B)
    ans = min(ans, temp)
print(ans)
0