結果

問題 No.2423 Merge Stones
ユーザー houren
提出日時 2023-08-12 15:01:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,462 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 203,000 KB
最終ジャッジ日時 2025-02-16 05:37:00
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 54 WA * 18
権限があれば一括ダウンロードができます

ソースコード

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);
}

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