結果
問題 |
No.2423 Merge Stones
|
ユーザー |
![]() |
提出日時 | 2023-08-12 15:24:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,164 bytes |
コンパイル時間 | 1,739 ms |
コンパイル使用メモリ | 193,028 KB |
最終ジャッジ日時 | 2025-02-16 06:19:07 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 WA * 7 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; } } ll n,k; ll a[300],c[300]; ll dp[51][300][300]; ll f(ll x,ll l,ll r){ if(dp[x][l][r]!=0) return dp[x][l][r]; if(l==r){ if(x==c[l]) return dp[x][l][r]=a[l]; else return dp[x][l][r]=-INF; } dp[x][l][r]=-INF; for(ll y=max(0ll,x-k);y<=min(50ll,x+k);y+=2){ for(ll k=l;k!=r;k=(k+1)%n){ chmax(dp[x][l][r],f(x,l,k)+f(y,(k+1)%n,r)); chmax(dp[x][l][r],f(y,l,k)+f(x,(k+1)%n,r)); } } return dp[x][l][r]; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; rep(i,n) cin >> a[i]; rep(i,n) cin >> c[i]; ll ans=0; rep(i,51){ rep(j,n){ rep(k,n){ chmax(ans,f(i,j,k)); } } } cout << ans << '\n'; }