結果

問題 No.2423 Merge Stones
ユーザー t98slidert98slider
提出日時 2023-08-14 20:26:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,332 bytes
コンパイル時間 1,822 ms
コンパイル使用メモリ 175,876 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-02 08:29:15
合計ジャッジ時間 17,657 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 32 ms
6,944 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 99 ms
6,940 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 32 ms
6,944 KB
testcase_20 AC 162 ms
6,944 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 98 ms
6,944 KB
testcase_24 AC 99 ms
6,944 KB
testcase_25 AC 100 ms
6,940 KB
testcase_26 AC 100 ms
6,944 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 107 ms
6,944 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 161 ms
6,940 KB
testcase_37 AC 102 ms
6,940 KB
testcase_38 AC 101 ms
6,940 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 31 ms
6,940 KB
testcase_44 WA -
testcase_45 AC 101 ms
6,944 KB
testcase_46 WA -
testcase_47 AC 100 ms
6,940 KB
testcase_48 AC 101 ms
6,940 KB
testcase_49 AC 30 ms
6,944 KB
testcase_50 AC 30 ms
6,940 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
権限があれば一括ダウンロードができます

ソースコード

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, n2;
    cin >> n >> k;
    n2 = 2 * n;
    vector<int> a(n), c(n);
    vector<ll> sa(n2 + 1);
    cin >> a >> c;
    a.insert(a.end(), a.begin(), a.end());
    c.insert(c.end(), c.begin(), c.end());
    for(int i = 0; i < n2; i++){
        sa[i + 1] = sa[i] + a[i];
        c[i]--;
    }
    vector<vector<ll>> dp(n2 + 1, vector<ll>(n2 + 1));
    for(int i = 0; i < n2; i++) dp[i][i + 1] = 1ll << c[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++){
                dp[l][r] |= dp[l][m] & dp[m][r];
                for(int i = 1; i <= k; i++){
                    dp[l][r] |= dp[l][m] & (dp[m][r] >> k);
                    dp[l][r] |= dp[l][m] & (dp[m][r] << k);
                    dp[l][r] |= (dp[l][m] >> k) & dp[m][r];
                    dp[l][r] |= (dp[l][m] << k) & dp[m][r];
                }
            }
            if(dp[l][r]) ans = max(ans, sa[r] - sa[l]);
        }
    }
    cout << ans << '\n';
}
0