結果

問題 No.1117 数列分割
ユーザー 👑 jupirojupiro
提出日時 2020-07-17 23:10:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,841 bytes
コンパイル時間 1,342 ms
コンパイル使用メモリ 132,048 KB
実行使用メモリ 73,984 KB
最終ジャッジ日時 2023-08-20 04:05:32
合計ジャッジ時間 3,575 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 8 ms
8,872 KB
testcase_04 AC 7 ms
8,252 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 7 ms
7,564 KB
testcase_09 AC 3 ms
4,548 KB
testcase_10 AC 7 ms
7,780 KB
testcase_11 AC 23 ms
21,856 KB
testcase_12 AC 25 ms
23,124 KB
testcase_13 AC 34 ms
30,984 KB
testcase_14 AC 36 ms
32,324 KB
testcase_15 AC 44 ms
39,228 KB
testcase_16 AC 49 ms
43,796 KB
testcase_17 AC 7 ms
7,664 KB
testcase_18 AC 87 ms
73,960 KB
testcase_19 AC 86 ms
73,984 KB
testcase_20 AC 42 ms
37,416 KB
testcase_21 AC 86 ms
73,904 KB
testcase_22 AC 86 ms
72,960 KB
testcase_23 AC 85 ms
72,992 KB
testcase_24 AC 84 ms
71,940 KB
testcase_25 AC 84 ms
71,804 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;


int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */

    ll n, k, m; scanf("%lld %lld %lld", &n, &k, &m);
    vector<ll> a(n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
    vector<ll> sum(n + 1); for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i];
    vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, -INF));
    vector<ll> mx1(k + 1, -INF), mx2(k + 1, -INF);
    dp[0][0] = 0;
    mx1[0] = 0;
    mx2[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            chmax(dp[i + 1][j], mx1[j - 1] - sum[i + 1]);
            chmax(dp[i + 1][j], mx2[j - 1] + sum[i + 1]);
        }
        for (int j = 0; j <= k; j++) {
            chmax(mx1[j], dp[i + 1][j] + sum[i + 1]);
            chmax(mx2[j], dp[i + 1][j] - sum[i + 1]);
        }
    }
    cout << dp[n][k] << endl;
    return 0;
}
0