結果

問題 No.2423 Merge Stones
ユーザー t98slidert98slider
提出日時 2023-08-14 20:11:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,403 bytes
コンパイル時間 2,061 ms
コンパイル使用メモリ 177,928 KB
実行使用メモリ 14,008 KB
最終ジャッジ日時 2024-05-02 08:13:35
合計ジャッジ時間 7,454 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 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 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
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 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n), c(n);
    cin >> a >> c;
    a.insert(a.end(), a.begin(), a.end());
    c.insert(c.end(), c.begin(), c.end());
    for(auto &&v : c) v--;
    vector<vector<vector<ll>>> dp(2 * n + 1, vector<vector<ll>>(2 * n + 1, vector<ll>(50, -(1ll << 60))));
    int n2 = n * 2;
    for(int i = 0; i < n2; i++) dp[i][i + 1][c[i]] = a[i];
    ll ans = *max_element(a.begin(), a.end());
    for(int len = 2; len <= n; len++){
        for(int l = 0; l + len <= n2; l++){
            int r = l + len;
            for(int m = l + 1; m < r; m++){
                for(int i = 0; i < 50; i++){
                    int jr = min(50, i + k + 1);
                    if(dp[l][m][i] < 0) continue;
                    for(int j = max(0, i - k); j < jr; j++){
                        dp[l][r][i] = max(dp[l][r][i], dp[l][m][i] + dp[m][r][j]);
                        dp[l][r][j] = max(dp[l][r][j], dp[l][m][i] + dp[m][r][j]);
                        ans = max(ans, dp[l][r][i]);
                        ans = max(ans, dp[l][r][j]);
                    }
                }
            }
        }
    }
    cout << ans << '\n';
}
0