結果

問題 No.1117 数列分割
ユーザー snrnsidysnrnsidy
提出日時 2021-06-10 03:28:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,182 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 202,496 KB
実行使用メモリ 73,528 KB
最終ジャッジ日時 2023-08-19 13:39:36
合計ジャッジ時間 5,796 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 11 ms
27,044 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 3 ms
6,000 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 107 ms
50,076 KB
testcase_14 AC 170 ms
63,064 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 61 ms
73,272 KB
testcase_19 AC 60 ms
73,240 KB
testcase_20 WA -
testcase_21 AC 290 ms
73,188 KB
testcase_22 AC 289 ms
73,260 KB
testcase_23 AC 292 ms
73,456 KB
testcase_24 AC 289 ms
73,164 KB
testcase_25 AC 284 ms
73,456 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

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

void solve(int t, int l, int r, int s, int e)
{
	if (l > r)
	{
		return;
	}
	int m = (l + r) / 2;
	dp[1][m] = dp[0][s - 1] + C[s][m];
	int opt = s;
	int end = min(e, m);
	for (int k = s + 1; k <= end; k++)
	{
		if (m - k + 1 > M)
		{
			break;
		}
		long long int val = dp[0][k - 1] + C[k][m];
		if (dp[1][m] < val)
		{
			dp[1][m] = val;
			opt = k;
		}
	}
	if (l != r)
	{
		solve(t, l, m - 1, s, opt);
		solve(t, m + 1, r, opt, e);
	}
}
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++)
	{
		long long int sum = 0;
		for (int j = i; j <= N; j++)
		{
			sum += v[j - 1];
			//cout << i << ' ' << j << ' ' << sum << '\n';
			C[i][j] = abs(sum);
		}
	}

	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);
		solve(i, i, N, i, N);
	}

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

	return 0;
}
0