結果

問題 No.2423 Merge Stones
ユーザー InTheBloomInTheBloom
提出日時 2024-03-06 09:10:34
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,607 bytes
コンパイル時間 1,209 ms
コンパイル使用メモリ 92,808 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-06 09:11:19
合計ジャッジ時間 44,634 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 1,801 ms
6,676 KB
testcase_12 AC 143 ms
6,676 KB
testcase_13 WA -
testcase_14 AC 349 ms
6,676 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 140 ms
6,676 KB
testcase_20 AC 354 ms
6,676 KB
testcase_21 WA -
testcase_22 AC 351 ms
6,676 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 209 ms
6,676 KB
testcase_27 AC 413 ms
6,676 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 348 ms
6,676 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 209 ms
6,676 KB
testcase_46 WA -
testcase_47 AC 224 ms
6,676 KB
testcase_48 WA -
testcase_49 AC 139 ms
6,676 KB
testcase_50 WA -
testcase_51 AC 2,563 ms
6,676 KB
testcase_52 AC 2,539 ms
6,676 KB
testcase_53 AC 2,577 ms
6,676 KB
testcase_54 AC 2,547 ms
6,676 KB
testcase_55 AC 2,606 ms
6,676 KB
testcase_56 AC 425 ms
6,676 KB
testcase_57 AC 422 ms
6,676 KB
testcase_58 AC 487 ms
6,676 KB
testcase_59 AC 461 ms
6,676 KB
testcase_60 AC 424 ms
6,676 KB
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 AC 2,462 ms
6,676 KB
testcase_69 WA -
testcase_70 AC 2,439 ms
6,676 KB
testcase_71 WA -
testcase_72 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

int main () {
    // 色と場所を持って区間dpできそう -> 間に合わないが、真偽値によるdpであることを考えるとワードサイズ分の高速化が効く

    int N, K; cin >> N >> K;
    vector<int> A(N), C(N);

    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> C[i];
    for (int i = 0; i < N; i++) C[i]--;

    vector<vector<ull>> dp(N, vector<ull>(N+1, 0));
    // dp[i][j] := iから右回りにj個の区間を全統合したとき、作成可能な色のセット

    for (int i = 0; i < N; i++) dp[i][1] = 1<<C[i];

    ull mask = (1ull<<50) - 1;

    for (int j = 2; j <= N; j++) {
        for (int i = 0; i < N; i++) {
            for (int mid = 1; mid < j; mid++) {
                // 右シフト or 左シフト
                for (int k = 0; k <= K; k++) {
                    dp[i][j] |= dp[i][mid] & (dp[(i+mid) % N][j-mid] >> k);
                    dp[i][j] |= (dp[i][mid] >> k) & dp[(i+mid) % N][j-mid];

                    dp[i][j] |= dp[i][mid] & (dp[(i+mid) % N][j-mid] << k);
                    dp[i][j] |= (dp[i][mid] << k) & dp[(i+mid) % N][j-mid];
                }
            }

            dp[i][j] &= mask;
        }
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) for (int j = 1; j <= N; j++) for (int c = 0; c < 50; c++) if (0 < dp[i][j]) {
        ll sum = 0;
        for (int k = 0; k < j; k++) sum += A[(i + k) % N];
        ans = max(ans, sum);
    }

    cout << ans << "\n";
}
0