結果

問題 No.2423 Merge Stones
ユーザー 👑 emthrmemthrm
提出日時 2023-08-12 14:26:53
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,798 bytes
コンパイル時間 2,965 ms
コンパイル使用メモリ 253,328 KB
実行使用メモリ 12,832 KB
最終ジャッジ日時 2024-04-30 06:07:24
合計ジャッジ時間 8,397 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  constexpr int C = 50;
  int n, k; cin >> n >> k;
  vector<int> a(n), c(n);
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> c[i], --c[i];
  vector dp(n * 2 - 1, vector(n * 2 - 1, 0LL));
  REP(r, n * 2 - 1) {
    dp[r][r] = 1LL << c[r % n];
    for (int l = r - 1; l >= 0 && r - l + 1 <= n; --l) {
      FOR(m, l, r) {
        if (dp[m + 1][r] == 0) continue;
        for (ll index = dp[l][m]; index > 0;) {
          const uint64_t lsb = index & -index;
          const int i = countr_zero(lsb);
          for (int j = max(i - k, 0); j <= i + k && j < C; ++j) {
            if (dp[m + 1][r] >> j & 1) dp[l][r] |= (1LL << i) | (1LL << j);
          }
          index ^= lsb;
        }
      }
    }
  }
  ll ans = 0;
  REP(i, n * 2 - 1) {
    ll magic = 0;
    for (int j = i; j - i + 1 <= n; ++j) {
      magic += a[j % n];
      if (dp[i][j] > 0) chmax(ans, magic);
    }
  }
  cout << ans << '\n';
  return 0;
}
0