結果

問題 No.1174 盆栽の剪定
ユーザー 👑 tatyamtatyam
提出日時 2020-08-15 20:56:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 581 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 45,884 KB
最終ジャッジ日時 2024-04-19 07:31:29
合計ジャッジ時間 3,329 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,496 KB
testcase_01 AC 31 ms
10,624 KB
testcase_02 AC 31 ms
10,624 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 32 ms
10,624 KB
testcase_06 AC 28 ms
10,496 KB
testcase_07 AC 32 ms
10,496 KB
testcase_08 RE -
testcase_09 AC 30 ms
10,752 KB
testcase_10 AC 31 ms
10,624 KB
testcase_11 AC 31 ms
10,624 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 32 ms
10,752 KB
testcase_15 AC 31 ms
10,496 KB
testcase_16 AC 32 ms
10,752 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
assert 1 <= n <= 10**5
a = [0, *map(int, input().split())]
for i in a:
    assert 0 <= i <= 10**9

dp = [[0] * (n + 1) for i in range(37)]

for i in range(n, 0, -1):
    lg = i.bit_length() - 1
    for j in range(-lg, lg + 1, 2):
        cnt1 = 0
        cnt2 = 0
        if i * 2 <= n:
            cnt1 += max(0, dp[i * 2][j + 1])
            cnt2 += max(0, dp[i * 2][j - 1])
        if i * 2 + 1 <= n:
            cnt1 += max(0, dp[i * 2 + 1][j - 1])
            cnt2 += max(0, dp[i * 2 + 1][j + 1])
        dp[i][j] = a[i] * j + max(cnt1, cnt2)

print(dp[1][0])
0