結果

問題 No.1174 盆栽の剪定
ユーザー 👑 tatyamtatyam
提出日時 2020-08-18 00:19:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 581 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 103,968 KB
最終ジャッジ日時 2024-04-19 19:29:32
合計ジャッジ時間 5,065 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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