結果
| 問題 |
No.2423 Merge Stones
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-12 15:44:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,262 bytes |
| コンパイル時間 | 1,037 ms |
| コンパイル使用メモリ | 95,760 KB |
| 最終ジャッジ日時 | 2025-02-16 06:50:01 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 10 TLE * 1 -- * 61 |
ソースコード
#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;
}