結果

問題 No.1117 数列分割
ユーザー fastmathfastmath
提出日時 2020-07-17 22:23:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,327 bytes
コンパイル時間 1,712 ms
コンパイル使用メモリ 166,576 KB
実行使用メモリ 80,688 KB
最終ジャッジ日時 2024-05-07 11:23:04
合計ジャッジ時間 10,552 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
73,984 KB
testcase_01 AC 41 ms
73,984 KB
testcase_02 AC 41 ms
73,984 KB
testcase_03 AC 98 ms
73,980 KB
testcase_04 AC 533 ms
73,984 KB
testcase_05 AC 41 ms
73,984 KB
testcase_06 AC 42 ms
73,972 KB
testcase_07 AC 42 ms
73,984 KB
testcase_08 AC 1,243 ms
73,988 KB
testcase_09 AC 110 ms
73,984 KB
testcase_10 AC 1,629 ms
74,024 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 3007, INF = 1e18+7;

int a[N], pref[N];
int dp[N][N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n, m, k;
    cin >> n >> k >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        pref[i + 1] = pref[i] + a[i];
    }   

    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            dp[i][j] = -INF;

    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= k; ++j) {
            for (int add = 1; add <= i && add <= m; ++add) {
                if (dp[i - add][j - 1] != -INF) {
                    dp[i][j] = max(dp[i][j], dp[i - add][j - 1] + pref[i] - pref[i - add]);
                    dp[i][j] = max(dp[i][j], dp[i - add][j - 1] + pref[i - add] - pref[i]);                    
                }   
            }   
        }   
    }   

    cout << dp[n][k] << endl;
}
0