結果

問題 No.77 レンガのピラミッド
ユーザー 👑 colognecologne
提出日時 2022-01-25 22:09:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 640 bytes
コンパイル時間 327 ms
コンパイル使用メモリ 86,856 KB
実行使用メモリ 75,684 KB
最終ジャッジ日時 2023-08-22 17:55:44
合計ジャッジ時間 3,692 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,408 KB
testcase_01 AC 73 ms
71,260 KB
testcase_02 AC 73 ms
71,104 KB
testcase_03 AC 74 ms
71,308 KB
testcase_04 AC 76 ms
70,828 KB
testcase_05 AC 74 ms
71,320 KB
testcase_06 AC 82 ms
75,588 KB
testcase_07 AC 73 ms
71,176 KB
testcase_08 AC 81 ms
75,512 KB
testcase_09 AC 73 ms
71,224 KB
testcase_10 AC 74 ms
71,308 KB
testcase_11 AC 75 ms
75,536 KB
testcase_12 AC 80 ms
75,632 KB
testcase_13 AC 81 ms
75,576 KB
testcase_14 AC 79 ms
75,604 KB
testcase_15 AC 72 ms
71,180 KB
testcase_16 AC 71 ms
71,344 KB
testcase_17 AC 73 ms
71,352 KB
testcase_18 AC 80 ms
75,612 KB
testcase_19 AC 74 ms
71,192 KB
testcase_20 AC 72 ms
71,308 KB
testcase_21 AC 78 ms
75,684 KB
testcase_22 AC 71 ms
71,348 KB
testcase_23 AC 78 ms
75,576 KB
testcase_24 AC 73 ms
71,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys


def input(): return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    *A, = map(int, input().split())

    def pyramid(M):
        return list(range(1, M)) + list(range(M, 0, -1))

    def dist(a, b):
        u, d = 0, 0
        for i in range(max(len(a), len(b))):
            A = a[i] if i < len(a) else 0
            B = b[i] if i < len(b) else 0
            if A > B:
                u += A-B
            else:
                d += B-A
        return max(u, d) if u <= d else float('inf')

    ans = min(dist(pyramid(i), A) for i in range(1, N+1))

    print(ans)


if __name__ == '__main__':
    main()
0