結果
問題 |
No.2423 Merge Stones
|
ユーザー |
![]() |
提出日時 | 2023-08-12 15:15:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,226 bytes |
コンパイル時間 | 2,207 ms |
コンパイル使用メモリ | 200,532 KB |
最終ジャッジ日時 | 2025-02-16 05:59:13 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 6 WA * 4 TLE * 1 -- * 61 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define all(v) v.begin(),v.end() template<class T> void chmin(T &a,T b){ if(a>b){ a=b; } } template<class T> void chmax(T &a,T b){ if(a<b){ a=b; } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n,k; cin >> n >> k; vector<ll> a(n),c(n); rep(i,n) cin >> a[i]; rep(i,n) cin >> c[i]; vector<vector<vector<ll>>> dp(n,vector<vector<ll>>(n,vector<ll>(51,-INF))); rep(i,n) dp[i][i][c[i]]=a[i]; rep(l,n){ rep(r,n){ rep(x,51){ for(ll y=max(0ll,x-k);y<=min(50ll,x+k);y++){ for(ll z=l;z!=r;z=(z+1)%n){ chmax(dp[l][r][x],dp[l][z][x]+dp[(z+1)%n][r][y]); chmax(dp[l][r][x],dp[l][z][y]+dp[(z+1)%n][r][x]); } } } } } ll ans=0; rep(i,n){ rep(j,n){ rep(kk,51){ chmax(ans,dp[i][j][kk]); } } } cout << ans << '\n'; }