結果

問題 No.1174 盆栽の剪定
ユーザー 👑 tatyamtatyam
提出日時 2020-08-18 00:19:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 581 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,496 KB
実行使用メモリ 120,064 KB
最終ジャッジ日時 2024-04-19 19:27:14
合計ジャッジ時間 4,075 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
52,096 KB
testcase_01 AC 32 ms
52,224 KB
testcase_02 AC 31 ms
51,968 KB
testcase_03 AC 33 ms
52,608 KB
testcase_04 AC 33 ms
52,352 KB
testcase_05 AC 32 ms
51,712 KB
testcase_06 AC 33 ms
51,712 KB
testcase_07 AC 33 ms
51,968 KB
testcase_08 AC 35 ms
52,352 KB
testcase_09 AC 34 ms
51,712 KB
testcase_10 AC 34 ms
51,584 KB
testcase_11 AC 33 ms
51,968 KB
testcase_12 AC 33 ms
52,096 KB
testcase_13 AC 33 ms
52,480 KB
testcase_14 AC 31 ms
52,096 KB
testcase_15 AC 31 ms
51,840 KB
testcase_16 AC 31 ms
51,712 KB
testcase_17 AC 32 ms
52,608 KB
testcase_18 AC 34 ms
52,352 KB
testcase_19 AC 154 ms
120,064 KB
testcase_20 AC 127 ms
117,504 KB
testcase_21 AC 94 ms
81,664 KB
testcase_22 AC 163 ms
119,168 KB
testcase_23 AC 185 ms
117,248 KB
testcase_24 AC 167 ms
115,584 KB
testcase_25 AC 147 ms
100,992 KB
testcase_26 AC 155 ms
109,056 KB
testcase_27 AC 140 ms
100,352 KB
testcase_28 AC 164 ms
112,768 KB
testcase_29 AC 134 ms
98,560 KB
testcase_30 AC 171 ms
117,888 KB
testcase_31 AC 138 ms
98,432 KB
testcase_32 AC 135 ms
97,280 KB
testcase_33 AC 151 ms
104,576 KB
権限があれば一括ダウンロードができます

ソースコード

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[j + 1][i * 2])
            cnt2 += max(0, dp[j - 1][i * 2])
        if i * 2 + 1 <= n:
            cnt1 += max(0, dp[j - 1][i * 2 + 1])
            cnt2 += max(0, dp[j + 1][i * 2 + 1])
        dp[j][i] = a[i] * j + max(cnt1, cnt2)

print(dp[0][1])
0