結果

問題 No.2423 Merge Stones
ユーザー firiexpfiriexp
提出日時 2023-07-15 13:32:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 602 ms / 4,000 ms
コード長 1,745 bytes
コンパイル時間 1,016 ms
コンパイル使用メモリ 107,464 KB
実行使用メモリ 6,460 KB
最終ジャッジ日時 2023-10-17 05:20:37
合計ジャッジ時間 14,324 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 597 ms
6,460 KB
testcase_12 AC 43 ms
6,460 KB
testcase_13 AC 45 ms
6,460 KB
testcase_14 AC 44 ms
6,460 KB
testcase_15 AC 44 ms
6,460 KB
testcase_16 AC 44 ms
6,460 KB
testcase_17 AC 45 ms
6,460 KB
testcase_18 AC 44 ms
6,460 KB
testcase_19 AC 44 ms
6,460 KB
testcase_20 AC 45 ms
6,460 KB
testcase_21 AC 44 ms
6,460 KB
testcase_22 AC 44 ms
6,460 KB
testcase_23 AC 44 ms
6,460 KB
testcase_24 AC 43 ms
6,460 KB
testcase_25 AC 43 ms
6,460 KB
testcase_26 AC 44 ms
6,460 KB
testcase_27 AC 44 ms
6,460 KB
testcase_28 AC 44 ms
6,460 KB
testcase_29 AC 44 ms
6,460 KB
testcase_30 AC 43 ms
6,460 KB
testcase_31 AC 44 ms
6,460 KB
testcase_32 AC 44 ms
6,460 KB
testcase_33 AC 43 ms
6,460 KB
testcase_34 AC 44 ms
6,460 KB
testcase_35 AC 43 ms
6,460 KB
testcase_36 AC 43 ms
6,460 KB
testcase_37 AC 43 ms
6,460 KB
testcase_38 AC 44 ms
6,460 KB
testcase_39 AC 45 ms
6,460 KB
testcase_40 AC 44 ms
6,460 KB
testcase_41 AC 44 ms
6,460 KB
testcase_42 AC 45 ms
6,460 KB
testcase_43 AC 43 ms
6,460 KB
testcase_44 AC 44 ms
6,460 KB
testcase_45 AC 44 ms
6,460 KB
testcase_46 AC 44 ms
6,460 KB
testcase_47 AC 44 ms
6,460 KB
testcase_48 AC 43 ms
6,460 KB
testcase_49 AC 44 ms
6,460 KB
testcase_50 AC 44 ms
6,460 KB
testcase_51 AC 496 ms
6,460 KB
testcase_52 AC 488 ms
6,460 KB
testcase_53 AC 602 ms
6,460 KB
testcase_54 AC 505 ms
6,460 KB
testcase_55 AC 596 ms
6,460 KB
testcase_56 AC 45 ms
6,460 KB
testcase_57 AC 45 ms
6,460 KB
testcase_58 AC 49 ms
6,460 KB
testcase_59 AC 47 ms
6,460 KB
testcase_60 AC 46 ms
6,460 KB
testcase_61 AC 599 ms
6,460 KB
testcase_62 AC 595 ms
6,460 KB
testcase_63 AC 583 ms
6,460 KB
testcase_64 AC 597 ms
6,460 KB
testcase_65 AC 599 ms
6,460 KB
testcase_66 AC 594 ms
6,460 KB
testcase_67 AC 593 ms
6,460 KB
testcase_68 AC 597 ms
6,460 KB
testcase_69 AC 595 ms
6,460 KB
testcase_70 AC 540 ms
6,460 KB
testcase_71 AC 187 ms
6,460 KB
testcase_72 AC 185 ms
6,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

ll dp[600][601];
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> A(2*n), C(2*n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &A[i]);
        A[i+n] = A[i];
    }
    vector<ll> S(2*n+1);
    for (int i = 0; i < 2*n; ++i) {
        S[i+1] = S[i] + A[i];
    }
    for (int i = 0; i < n; ++i) {
        scanf("%d", &C[i]);
        C[i+n] = C[i];
    }
    n *= 2;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j <= n; ++j) {
            dp[i][j] = 0;
        }
        dp[i][i+1] = (1LL << C[i]);
    }

    for (int len = 2; len <= n; ++len) {
        for (int l = 0; l+len <= n; ++l) {

            int r = l+len;
            for (int mid = l+1; mid < r; ++mid) {
                ll lval = dp[l][mid], rval = dp[mid][r];
                if(lval == 0 || rval == 0) continue;
                dp[l][r] |= lval & rval;
                for (int i = 1; i <= k; ++i) {
                    dp[l][r] |= lval & (rval << i);
                    dp[l][r] |= lval & (rval >> i);
                    dp[l][r] |= lval << i & rval;
                    dp[l][r] |= lval >> i & rval;
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j <= n && j-i <= n/2; ++j) {
            if(dp[i][j] > 0) ans = max(ans, S[j]-S[i]);
        }
    }
    cout << ans << "\n";
    return 0;
}
0