結果

問題 No.2423 Merge Stones
ユーザー FplusFplusFFplusFplusF
提出日時 2023-08-12 15:27:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,219 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 201,648 KB
実行使用メモリ 39,424 KB
最終ジャッジ日時 2024-04-30 09:34:10
合計ジャッジ時間 145,112 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 WA -
testcase_02 AC 10 ms
6,940 KB
testcase_03 WA -
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 9 ms
6,940 KB
testcase_07 AC 8 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 9 ms
6,940 KB
testcase_11 AC 3,248 ms
39,424 KB
testcase_12 AC 373 ms
38,656 KB
testcase_13 AC 3,220 ms
39,296 KB
testcase_14 AC 1,643 ms
39,296 KB
testcase_15 AC 1,047 ms
39,296 KB
testcase_16 AC 2,761 ms
39,296 KB
testcase_17 AC 1,612 ms
39,424 KB
testcase_18 AC 2,759 ms
39,296 KB
testcase_19 AC 361 ms
38,016 KB
testcase_20 AC 1,605 ms
39,424 KB
testcase_21 AC 3,233 ms
39,424 KB
testcase_22 AC 1,643 ms
39,296 KB
testcase_23 AC 1,066 ms
39,296 KB
testcase_24 AC 1,058 ms
39,296 KB
testcase_25 AC 1,113 ms
39,424 KB
testcase_26 AC 1,093 ms
39,296 KB
testcase_27 AC 2,222 ms
39,296 KB
testcase_28 AC 3,237 ms
39,296 KB
testcase_29 AC 2,725 ms
39,296 KB
testcase_30 AC 1,622 ms
39,424 KB
testcase_31 AC 1,636 ms
39,296 KB
testcase_32 AC 3,222 ms
39,296 KB
testcase_33 AC 1,087 ms
39,424 KB
testcase_34 AC 2,292 ms
39,296 KB
testcase_35 AC 1,669 ms
39,296 KB
testcase_36 AC 1,618 ms
39,296 KB
testcase_37 AC 1,066 ms
39,296 KB
testcase_38 AC 1,080 ms
39,424 KB
testcase_39 AC 3,218 ms
39,424 KB
testcase_40 AC 2,814 ms
39,424 KB
testcase_41 AC 2,283 ms
39,424 KB
testcase_42 AC 3,234 ms
39,296 KB
testcase_43 AC 366 ms
38,656 KB
testcase_44 AC 3,248 ms
39,296 KB
testcase_45 AC 1,100 ms
39,296 KB
testcase_46 AC 2,235 ms
39,296 KB
testcase_47 AC 1,088 ms
39,296 KB
testcase_48 AC 1,083 ms
39,296 KB
testcase_49 AC 365 ms
38,528 KB
testcase_50 AC 366 ms
38,528 KB
testcase_51 AC 2,703 ms
39,296 KB
testcase_52 AC 2,727 ms
39,424 KB
testcase_53 AC 3,224 ms
39,296 KB
testcase_54 AC 2,705 ms
39,424 KB
testcase_55 AC 3,186 ms
39,424 KB
testcase_56 AC 2,739 ms
39,296 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 AC 3,278 ms
39,296 KB
testcase_62 AC 3,266 ms
39,296 KB
testcase_63 AC 3,245 ms
39,296 KB
testcase_64 AC 3,241 ms
39,296 KB
testcase_65 AC 3,242 ms
39,296 KB
testcase_66 AC 3,220 ms
39,296 KB
testcase_67 AC 3,265 ms
39,424 KB
testcase_68 AC 3,249 ms
39,296 KB
testcase_69 AC 3,253 ms
39,296 KB
testcase_70 AC 3,243 ms
39,424 KB
testcase_71 AC 3,259 ms
39,424 KB
testcase_72 AC 3,265 ms
39,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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++){
        chmax(dp[x][l][r],f(x,l,l)+f(y,(l+1)%n,r));
        chmax(dp[x][l][r],f(x,l,(r-1+n)%n)+f(y,r,r));
        chmax(dp[x][l][r],f(y,l,l)+f(x,(l+1)%n,r));
        chmax(dp[x][l][r],f(y,l,(r-1+n)%n)+f(x,r,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,n){
        rep(j,n){
            rep(k,n){
                chmax(ans,f(c[i],j,k));
            }
        }
    }
    cout << ans << '\n';
}
0