結果

問題 No.1117 数列分割
ユーザー snrnsidysnrnsidy
提出日時 2021-06-10 03:33:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 713 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 201,080 KB
実行使用メモリ 7,856 KB
最終ジャッジ日時 2023-08-19 13:44:51
合計ジャッジ時間 17,964 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,856 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 159 ms
4,380 KB
testcase_04 AC 154 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 225 ms
4,376 KB
testcase_09 AC 46 ms
4,380 KB
testcase_10 AC 281 ms
4,380 KB
testcase_11 AC 1,540 ms
4,376 KB
testcase_12 AC 1,383 ms
4,380 KB
testcase_13 AC 1,137 ms
4,380 KB
testcase_14 AC 2,343 ms
4,376 KB
testcase_15 AC 1,772 ms
4,380 KB
testcase_16 TLE -
testcase_17 AC 697 ms
4,376 KB
testcase_18 TLE -
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;

long long int dp[2][3001];
vector <long long int> v;
int N, K, M;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> K >> M;
	for (int i = 0; i < N; i++)
	{
		int t;
		cin >> t;
		v.push_back(t);
	}

	for (int i = 1; i <= N; i++)
	{
		dp[1][i] = -1e18;
	}
	dp[1][0] = 0;
	for (int i = 1; i <= K; i++)
	{
		memcpy(dp[0], dp[1], sizeof(dp[1]));
		fill(dp[1], dp[1] + 3001, -1e18);
		for (int j = 0; j < N; j++)
		{
			if (dp[0][j] <= -1e18) continue;
			long long int sum = 0;
			for (int k = j; k < N; k++)
			{
				sum += v[k];
				dp[1][k + 1] = max(dp[1][k + 1], dp[0][j] + abs(sum));
			}
		}
	}

	cout << dp[1][N] << '\n';

	return 0;
}
0