結果

問題 No.1174 盆栽の剪定
ユーザー chocoruskchocorusk
提出日時 2020-08-18 02:52:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,093 bytes
コンパイル時間 1,202 ms
コンパイル使用メモリ 126,456 KB
実行使用メモリ 33,280 KB
最終ジャッジ日時 2024-04-19 19:32:08
合計ジャッジ時間 3,131 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 86 ms
33,152 KB
testcase_20 AC 57 ms
33,280 KB
testcase_21 AC 15 ms
8,448 KB
testcase_22 AC 73 ms
33,256 KB
testcase_23 AC 58 ms
33,280 KB
testcase_24 AC 75 ms
30,848 KB
testcase_25 AC 51 ms
21,248 KB
testcase_26 AC 63 ms
26,240 KB
testcase_27 AC 50 ms
20,864 KB
testcase_28 AC 68 ms
28,672 KB
testcase_29 AC 45 ms
19,456 KB
testcase_30 AC 78 ms
31,872 KB
testcase_31 AC 46 ms
19,456 KB
testcase_32 AC 45 ms
18,816 KB
testcase_33 AC 53 ms
23,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
ll a[(1<<18)+1];
const int d=18;
ll dp[37][100010];
ll solve(int s, int x){
    if(x>n) return 0;
    if(dp[s+d][x]>=0) return dp[s+d][x];
    ll s1=solve(s+1, 2*x)+a[2*x]*(s+1), s2=solve(s-1, 2*x+1)+a[2*x+1]*(s-1);
    ll s3=solve(s-1, 2*x)+a[2*x]*(s-1), s4=solve(s+1, 2*x+1)+a[2*x+1]*(s+1);
    ll ans=max({0ll, s1, s1+s2, s1, s3+s4, s4});
    return dp[s+d][x]=ans;
}
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++) cin>>a[i];
    for(int i=1; i<=n; i++) for(int j=0; j<=2*d; j++) dp[j][i]=-1;
    cout<<solve(0, 1)<<endl;
    return 0;
}
0