結果

問題 No.2423 Merge Stones
ユーザー dyktr_06dyktr_06
提出日時 2023-06-28 14:29:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,434 bytes
コンパイル時間 2,458 ms
コンパイル使用メモリ 206,016 KB
実行使用メモリ 24,536 KB
最終ジャッジ日時 2023-10-17 04:45:55
合計ジャッジ時間 8,596 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
5,756 KB
testcase_02 AC 2 ms
5,752 KB
testcase_03 AC 3 ms
5,752 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
5,748 KB
testcase_06 AC 2 ms
5,748 KB
testcase_07 AC 3 ms
5,752 KB
testcase_08 AC 2 ms
5,748 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
5,748 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;

bool dp[601][601][50];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k; cin >> n >> k;
    vector<long long> a(2 * n);
    vector<int> c(2 * n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i + n] = a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
        c[i]--;
        c[i + n] = c[i];
    }

    vector<long long> sum(2 * n + 1);
    for(int i = 0; i < 2 * n; i++){
        sum[i + 1] = sum[i] + a[i];
    }

    for(int i = 0; i < 2 * n; i++){
        dp[i][i][c[i]] = true;
    }

    long long ans = 0;
    for(int len = 1; len <= n; len++){
        for(int l = 0; l < 2 * n - len + 1; l++){
            int r = l + len - 1;
            for(int cl = 0; cl < 50; cl++){
                for(int i = l; i < r; i++){
                    bool bitl = dp[l][i][cl];
                    if(bitl == false) continue;
                    for(int cr = max(0, cl - k); cr <= min(49, cl + k); cr++){
                        bool bitr = dp[i + 1][r][cr];
                        if(bitl && bitr){
                            dp[l][r][cl] = true;
                            dp[l][r][cr] = true;
                        }
                    }
                }
                if(dp[l][r][cl]){
                    ans = max(ans, sum[r + 1] - sum[l]);
                }
            }
        }
    }
    cout << ans << endl;
}
0