結果
問題 | No.2423 Merge Stones |
ユーザー |
![]() |
提出日時 | 2023-08-12 15:29:55 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,477 bytes |
コンパイル時間 | 1,841 ms |
コンパイル使用メモリ | 201,596 KB |
実行使用メモリ | 39,424 KB |
最終ジャッジ日時 | 2024-04-30 09:46:41 |
合計ジャッジ時間 | 171,400 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | WA | - |
testcase_02 | AC | 11 ms
6,944 KB |
testcase_03 | WA | - |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | WA | - |
testcase_11 | AC | 3,972 ms
39,424 KB |
testcase_12 | AC | 430 ms
38,528 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 441 ms
37,888 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 1,256 ms
39,424 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 1,283 ms
39,424 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | AC | 1,347 ms
39,296 KB |
testcase_48 | WA | - |
testcase_49 | AC | 433 ms
38,656 KB |
testcase_50 | WA | - |
testcase_51 | AC | 3,258 ms
39,296 KB |
testcase_52 | AC | 3,237 ms
39,424 KB |
testcase_53 | AC | 3,819 ms
39,296 KB |
testcase_54 | AC | 3,217 ms
39,296 KB |
testcase_55 | AC | 3,827 ms
39,296 KB |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | AC | 3,853 ms
39,296 KB |
testcase_62 | AC | 3,899 ms
39,424 KB |
testcase_63 | AC | 3,894 ms
39,424 KB |
testcase_64 | AC | 3,830 ms
39,296 KB |
testcase_65 | AC | 3,873 ms
39,296 KB |
testcase_66 | AC | 3,862 ms
39,296 KB |
testcase_67 | AC | 3,891 ms
39,424 KB |
testcase_68 | AC | 3,900 ms
39,296 KB |
testcase_69 | AC | 3,896 ms
39,424 KB |
testcase_70 | AC | 3,883 ms
39,296 KB |
testcase_71 | AC | 3,919 ms
39,424 KB |
testcase_72 | AC | 3,821 ms
39,296 KB |
ソースコード
#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)); if(2<=r-l){ chmax(dp[x][l][r],f(x,l,l)+f(y,(l+2)%n,r)); chmax(dp[x][l][r],f(x,l,(r-2+n)%n)+f(y,r,r)); chmax(dp[x][l][r],f(y,l,l)+f(x,(l+2)%n,r)); chmax(dp[x][l][r],f(y,l,(r-2+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'; }