結果

問題 No.2423 Merge Stones
ユーザー takumi152takumi152
提出日時 2023-08-12 15:44:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,262 bytes
コンパイル時間 1,099 ms
コンパイル使用メモリ 92,972 KB
実行使用メモリ 48,928 KB
最終ジャッジ日時 2024-04-30 10:05:23
合計ジャッジ時間 6,798 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,888 KB
testcase_01 AC 9 ms
6,944 KB
testcase_02 AC 6 ms
6,944 KB
testcase_03 AC 5 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 6 ms
6,944 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 6 ms
6,944 KB
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 <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 998244353;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;
  vector<int> c(n);
  for (auto &x: c) cin >> x;

  vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(n, vector<ll>(51, -1000000000)));
  for (int i = 0; i < n; i++) dp[i][i][c[i]] = a[i];
  for (int l = 1; l <= n; l++) {
    for (int i = 0; i < n; i++) {
      int j = i + l;
      for (int p = i + 1; p < j; p++) {
        for (int x = 1; x <= 50; x++) {
          for (int y = max(1, x - k); y <= min(50, x + k); y++) {
            dp[i][(j-1)%n][x] = max(dp[i][(j-1)%n][x], dp[i][(p-1)%n][x] + dp[p%n][(j-1)%n][y]);
            dp[i][(j-1)%n][y] = max(dp[i][(j-1)%n][y], dp[i][(p-1)%n][x] + dp[p%n][(j-1)%n][y]);
          }
        }
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int x = 1; x <= 50; x++) {
        ans = max(ans, dp[i][j][x]);
      }
    }
  }

  cout << ans << endl;

  return 0;
}
0