結果

問題 No.2423 Merge Stones
ユーザー hourenhouren
提出日時 2023-08-12 15:02:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,465 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 211,212 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2024-04-30 07:52:06
合計ジャッジ時間 9,447 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 WA -
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 87 ms
8,832 KB
testcase_12 AC 88 ms
8,960 KB
testcase_13 AC 89 ms
8,960 KB
testcase_14 AC 88 ms
8,960 KB
testcase_15 AC 86 ms
8,832 KB
testcase_16 AC 87 ms
8,960 KB
testcase_17 AC 86 ms
8,960 KB
testcase_18 AC 86 ms
8,960 KB
testcase_19 AC 88 ms
8,960 KB
testcase_20 AC 87 ms
8,960 KB
testcase_21 AC 97 ms
8,960 KB
testcase_22 AC 91 ms
8,960 KB
testcase_23 AC 89 ms
8,832 KB
testcase_24 AC 90 ms
8,960 KB
testcase_25 AC 91 ms
8,960 KB
testcase_26 AC 90 ms
8,960 KB
testcase_27 AC 89 ms
8,960 KB
testcase_28 AC 89 ms
8,960 KB
testcase_29 WA -
testcase_30 AC 93 ms
8,960 KB
testcase_31 AC 90 ms
8,960 KB
testcase_32 AC 90 ms
8,832 KB
testcase_33 AC 90 ms
8,960 KB
testcase_34 AC 89 ms
8,960 KB
testcase_35 AC 89 ms
8,832 KB
testcase_36 AC 90 ms
8,960 KB
testcase_37 AC 94 ms
8,960 KB
testcase_38 AC 90 ms
8,960 KB
testcase_39 WA -
testcase_40 AC 94 ms
8,832 KB
testcase_41 AC 93 ms
8,832 KB
testcase_42 AC 93 ms
8,832 KB
testcase_43 AC 89 ms
8,960 KB
testcase_44 WA -
testcase_45 AC 87 ms
8,960 KB
testcase_46 AC 91 ms
8,960 KB
testcase_47 AC 89 ms
8,832 KB
testcase_48 AC 88 ms
8,960 KB
testcase_49 AC 89 ms
8,960 KB
testcase_50 AC 89 ms
8,832 KB
testcase_51 AC 89 ms
8,960 KB
testcase_52 AC 90 ms
8,960 KB
testcase_53 AC 98 ms
8,960 KB
testcase_54 AC 86 ms
8,960 KB
testcase_55 AC 88 ms
8,960 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 AC 88 ms
8,832 KB
testcase_62 AC 93 ms
8,960 KB
testcase_63 AC 88 ms
8,832 KB
testcase_64 AC 89 ms
8,960 KB
testcase_65 AC 90 ms
8,960 KB
testcase_66 AC 90 ms
8,960 KB
testcase_67 AC 88 ms
8,832 KB
testcase_68 AC 91 ms
8,960 KB
testcase_69 AC 90 ms
8,960 KB
testcase_70 AC 91 ms
8,832 KB
testcase_71 AC 90 ms
8,960 KB
testcase_72 AC 88 ms
8,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 60), MOD = 998244353;
constexpr int INF = (1 << 30);

int f(pair<int,int> a, pair<int,int> b){
    if(a.first>b.first) swap(a,b);
    return max(0, b.first-a.second+1);
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,d;
    cin >> n >> d;
    vector dp(2*n+1,vector<ll>(2*n+1, -INFLL));
    vector c(2*n+1,vector<pair<int,int>>(2*n+1));
    ll ans = 0;
    rep(i,n) cin >> dp[i][i+1], dp[n+i][n+i+1] = dp[i][i+1];
    rep(i,n){
        int x;
        cin >> x;
        c[i][i+1] = c[n+i][n+i+1] = {x,x+1};
    }
    for(int i=2;i<=n;i++){
        for(int j=0;j<=2*n-i;j++){
            for(int k=j+1;k<i+j;k++){
                if(f(c[j][k], c[k][i+j])<=d) chmax(dp[j][i+j], dp[j][k]+dp[k][i+j]);
                c[j][i+j] = {min(c[j][k].first, c[k][i+j].first), max(c[j][k].second, c[k][i+j].second)};
            }
        }
    }
    rep(i,2*n+1){
        rep(j,2*n+1){
            chmax(dp[i][j], 0LL);
            chmax(ans,dp[i][j]);
        }
    }
    cout << ans << '\n';
    return 0;
}
0