結果

問題 No.1117 数列分割
ユーザー re_re0101re_re0101
提出日時 2021-04-16 17:39:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,949 bytes
コンパイル時間 4,197 ms
コンパイル使用メモリ 232,760 KB
実行使用メモリ 462,656 KB
最終ジャッジ日時 2023-09-15 15:18:09
合計ジャッジ時間 28,736 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 181 ms
48,500 KB
testcase_04 AC 169 ms
46,180 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 3 ms
6,100 KB
testcase_07 AC 3 ms
6,108 KB
testcase_08 AC 152 ms
59,968 KB
testcase_09 AC 27 ms
28,356 KB
testcase_10 AC 143 ms
61,924 KB
testcase_11 AC 965 ms
189,548 KB
testcase_12 AC 1,112 ms
206,696 KB
testcase_13 AC 1,232 ms
166,328 KB
testcase_14 AC 1,584 ms
251,716 KB
testcase_15 MLE -
testcase_16 MLE -
testcase_17 AC 147 ms
95,752 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define eb emplace_back
#define endl '\n'
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define PI 3.14159265359
const double eps = 1e-12;
const long long INF= (long long)1e18+20;
const int inf= 1010101010;
typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> Point;  // Point
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl>vvl;
typedef vector<vvl>vvvl;
typedef vector<vvvl>vvvvl;
typedef vector<vvvvl>vvvvvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
template<class T> using minpq=priority_queue<T,vector<T>,greater<T>>;
// const ll MOD=1000000007LL;
const ll MOD=998244353LL;
const ll mod=MOD;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={0,0,1,-1,1,1,-1,-1};
vl dy={1,-1,0,0,-1,1,-1,1};

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}


using mint=modint998244353;
// using mint=modint;
typedef vector<mint>vm;
typedef vector<vm>vvm;
typedef vector<vvm>vvvm;
ll modpow(ll a, ll n,ll mod=MOD) {

    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll op(ll a, ll b) {
    return max(a, b);
}

ll e() {
    return 0;
}

ll dp[3001][3001];

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(12);
    /*--------------------------------*/

    int n,k,m;cin>>n>>k>>m;
    vl a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)dp[i][j]=-INF;
    // vvl dp(n+1,vl(k+1,-INF));
    dp[0][0]=0;
    vl sum(n+1);
    rep(i,n)sum[i+1]=sum[i]+a[i];
    vector<segtree<ll,op,e>>plus(k+1,segtree<ll,op,e>(n+1));
    vector<segtree<ll,op,e>>minus(k+1,segtree<ll,op,e>(n+1));
    //dp[i][j]:=i番目まで見てj個に分けてる
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            chmax(dp[i+1][j],minus[j-1].prod(max(0,i-m+1),i+1)+sum[i+1]);
            chmax(dp[i+1][j],plus[j-1].prod(max(0,i-m+1),i+1)-sum[i+1]);
            minus[j].set(i+1,dp[i+1][j]-sum[i+1]);
            plus[j].set(i+1,dp[i+1][j]+sum[i+1]);
        }
    }
    cout<<dp[n][k]<<endl;
}
0