結果

問題 No.2423 Merge Stones
ユーザー drken1215drken1215
提出日時 2023-08-12 19:32:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,149 bytes
コンパイル時間 2,476 ms
コンパイル使用メモリ 210,376 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-30 14:38:00
合計ジャッジ時間 30,180 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 WA -
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 550 ms
6,940 KB
testcase_12 AC 141 ms
6,940 KB
testcase_13 AC 548 ms
6,944 KB
testcase_14 AC 343 ms
6,944 KB
testcase_15 AC 243 ms
6,944 KB
testcase_16 AC 482 ms
6,944 KB
testcase_17 AC 345 ms
6,940 KB
testcase_18 AC 480 ms
6,940 KB
testcase_19 AC 142 ms
6,940 KB
testcase_20 AC 342 ms
6,944 KB
testcase_21 AC 548 ms
6,940 KB
testcase_22 AC 344 ms
6,940 KB
testcase_23 AC 241 ms
6,940 KB
testcase_24 AC 242 ms
6,940 KB
testcase_25 AC 240 ms
6,944 KB
testcase_26 AC 242 ms
6,940 KB
testcase_27 AC 416 ms
6,940 KB
testcase_28 AC 551 ms
6,944 KB
testcase_29 AC 483 ms
6,940 KB
testcase_30 AC 342 ms
6,940 KB
testcase_31 AC 343 ms
6,940 KB
testcase_32 AC 547 ms
6,940 KB
testcase_33 AC 242 ms
6,940 KB
testcase_34 AC 418 ms
6,944 KB
testcase_35 AC 343 ms
6,944 KB
testcase_36 AC 341 ms
6,940 KB
testcase_37 AC 239 ms
6,944 KB
testcase_38 AC 238 ms
6,940 KB
testcase_39 AC 549 ms
6,940 KB
testcase_40 AC 480 ms
6,940 KB
testcase_41 AC 422 ms
6,940 KB
testcase_42 AC 551 ms
6,944 KB
testcase_43 AC 142 ms
6,940 KB
testcase_44 AC 552 ms
6,940 KB
testcase_45 AC 240 ms
6,940 KB
testcase_46 AC 420 ms
6,940 KB
testcase_47 AC 241 ms
6,944 KB
testcase_48 AC 242 ms
6,944 KB
testcase_49 AC 141 ms
6,940 KB
testcase_50 AC 141 ms
6,944 KB
testcase_51 AC 481 ms
6,940 KB
testcase_52 AC 482 ms
6,940 KB
testcase_53 AC 547 ms
6,940 KB
testcase_54 AC 480 ms
6,940 KB
testcase_55 AC 550 ms
6,944 KB
testcase_56 AC 482 ms
6,940 KB
testcase_57 AC 482 ms
6,940 KB
testcase_58 AC 550 ms
6,940 KB
testcase_59 AC 551 ms
6,940 KB
testcase_60 AC 483 ms
6,944 KB
testcase_61 AC 550 ms
6,944 KB
testcase_62 AC 550 ms
6,944 KB
testcase_63 AC 549 ms
6,944 KB
testcase_64 AC 549 ms
6,940 KB
testcase_65 AC 550 ms
6,940 KB
testcase_66 AC 551 ms
6,944 KB
testcase_67 AC 550 ms
6,940 KB
testcase_68 AC 553 ms
6,940 KB
testcase_69 AC 549 ms
6,944 KB
testcase_70 AC 550 ms
6,944 KB
testcase_71 AC 547 ms
6,940 KB
testcase_72 AC 554 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    // 入力
    int N, K;
    cin >> N >> K;
    vector<long long> A(N*2), C(N*2);
    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+N] = C[i]; }
    
    // 累積和
    vector<long long> S(N*2+1, 0);
    for (int i = 0; i < N*2; ++i) S[i+1] = S[i] + A[i];
    
    // dp
    long long res = 0;
    vector dp(N*2+1, vector(N*2+2, bitset<52>(false)));
    for (int l = 0; l < N*2; ++l) dp[l][l+1][C[l]] = true;
    for (int b = 2; b <= N; ++b) {
        for (int l = 0; l < N*2 && l+b <= N*2; ++l) {
            int r = l + b;
            for (int m = l+1; m < r; ++m) {
                for (int k = 0; k <= K; ++k) {
                    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];
                }
            }
            for (int c = 0; c <= 50; ++c) if (dp[l][r][c]) res = max(res, S[r] - S[l]);
        }
    }
    cout << res << endl;
}
0