結果

問題 No.2423 Merge Stones
ユーザー SSRSSSRS
提出日時 2023-08-12 13:59:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 356 ms / 4,000 ms
コード長 1,285 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 174,040 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-30 04:40:29
合計ジャッジ時間 18,667 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 340 ms
5,376 KB
testcase_12 AC 49 ms
5,376 KB
testcase_13 AC 343 ms
5,376 KB
testcase_14 AC 175 ms
5,376 KB
testcase_15 AC 117 ms
5,376 KB
testcase_16 AC 313 ms
5,376 KB
testcase_17 AC 172 ms
5,376 KB
testcase_18 AC 309 ms
5,376 KB
testcase_19 AC 50 ms
5,376 KB
testcase_20 AC 172 ms
5,376 KB
testcase_21 AC 334 ms
5,376 KB
testcase_22 AC 176 ms
5,376 KB
testcase_23 AC 115 ms
5,376 KB
testcase_24 AC 117 ms
5,376 KB
testcase_25 AC 114 ms
5,376 KB
testcase_26 AC 114 ms
5,376 KB
testcase_27 AC 231 ms
5,376 KB
testcase_28 AC 336 ms
5,376 KB
testcase_29 AC 305 ms
5,376 KB
testcase_30 AC 169 ms
5,376 KB
testcase_31 AC 170 ms
5,376 KB
testcase_32 AC 351 ms
5,376 KB
testcase_33 AC 116 ms
5,376 KB
testcase_34 AC 239 ms
5,376 KB
testcase_35 AC 173 ms
5,376 KB
testcase_36 AC 174 ms
5,376 KB
testcase_37 AC 113 ms
5,376 KB
testcase_38 AC 127 ms
5,376 KB
testcase_39 AC 347 ms
5,376 KB
testcase_40 AC 307 ms
5,376 KB
testcase_41 AC 231 ms
5,376 KB
testcase_42 AC 339 ms
5,376 KB
testcase_43 AC 49 ms
5,376 KB
testcase_44 AC 336 ms
5,376 KB
testcase_45 AC 113 ms
5,376 KB
testcase_46 AC 232 ms
5,376 KB
testcase_47 AC 114 ms
5,376 KB
testcase_48 AC 116 ms
5,376 KB
testcase_49 AC 55 ms
5,376 KB
testcase_50 AC 50 ms
5,376 KB
testcase_51 AC 306 ms
5,376 KB
testcase_52 AC 305 ms
5,376 KB
testcase_53 AC 336 ms
5,376 KB
testcase_54 AC 314 ms
5,376 KB
testcase_55 AC 338 ms
5,376 KB
testcase_56 AC 307 ms
5,376 KB
testcase_57 AC 301 ms
5,376 KB
testcase_58 AC 345 ms
5,376 KB
testcase_59 AC 352 ms
5,376 KB
testcase_60 AC 316 ms
5,376 KB
testcase_61 AC 340 ms
5,376 KB
testcase_62 AC 356 ms
5,376 KB
testcase_63 AC 340 ms
5,376 KB
testcase_64 AC 342 ms
5,376 KB
testcase_65 AC 337 ms
5,376 KB
testcase_66 AC 353 ms
5,376 KB
testcase_67 AC 345 ms
5,376 KB
testcase_68 AC 344 ms
5,376 KB
testcase_69 AC 340 ms
5,376 KB
testcase_70 AC 347 ms
5,376 KB
testcase_71 AC 340 ms
5,376 KB
testcase_72 AC 347 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<int> C(N);
  for (int i = 0; i < N; i++){
    cin >> C[i];
  }
  vector<long long> S(N + 1);
  S[0] = 0;
  for (int i = 0; i < N; i++){
    S[i + 1] = S[i] + A[i];
  }
  auto sum = [&](int L, int R){
    if (L < R){
      return S[R] - S[L];
    } else {
      return (S[N] - S[L]) + S[R];
    }
  };
  auto match = [&](long long a, long long b){
    long long ans = a & b;
    for (int i = 1; i <= K; i++){
      ans |= a & (b << i);
      ans |= a & (b >> i);
      ans |= (a << i) & b;
      ans |= (a >> i) & b;
    }
    return ans;
  };
  vector<vector<long long>> dp(N, vector<long long>(N, 0));
  for (int i = 0; i < N - 1; i++){
    dp[i][i + 1] = (long long) 1 << C[i];
  }
  dp[N - 1][0] = (long long) 1 << C[N - 1];
  for (int i = 2; i <= N; i++){
    for (int j = 0; j < N; j++){
      for (int k = j + 1; k < j + i; k++){
        dp[j][(j + i) % N] |= match(dp[j][k % N], dp[k % N][(j + i) % N]);
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      if (dp[i][j] != 0){
        ans = max(ans, sum(i, j));
      }
    }
  }
  cout << ans << endl;
}
0