結果

問題 No.1247 ブロック登り
ユーザー 👑 jupirojupiro
提出日時 2020-10-19 19:52:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,756 bytes
コンパイル時間 2,304 ms
コンパイル使用メモリ 142,004 KB
実行使用メモリ 649,576 KB
最終ジャッジ日時 2023-09-28 13:23:20
合計ジャッジ時間 27,011 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 8 ms
7,380 KB
testcase_08 AC 9 ms
7,760 KB
testcase_09 AC 3 ms
4,440 KB
testcase_10 AC 5 ms
4,932 KB
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 AC 137 ms
102,440 KB
testcase_20 AC 51 ms
42,292 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 23 ms
14,960 KB
testcase_23 AC 17 ms
12,516 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;
using ull = unsigned long long;

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; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 1100000;

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	ll n, K; cin >> n >> K;
	vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i];

	if (K == 1) {
		for (int i = 0; i < n; i++) {
			ll ans = -INF;
			if (i + 1 < n) chmax(ans, a[i + 1]);
			if (i > 0) chmax(ans, a[i - 1]);
			cout << ans << "\n";
		}
		return 0;
	}
	vector dp(2, vector(K + 1, vector(n, vector<ll>(n, -INF))));
	for (int i = 0; i < n; i++) {
		dp[0][K - 1][i][i] = dp[1][K - 1][i][i] = a[i] * K;
	}
	vector<ll> res(n, -INF);
	for (int i = K - 1; i > 0; i--) {
		for (int l = 0; l < n; l++) {
			for (int r = l; r < n; r++) {

				if (l > 0) {
					chmax(dp[0][i - 1][l - 1][r], dp[0][i][l][r] + a[l - 1] * i);
					if (i == 1) {
						chmax(res[l - 1], dp[0][i][l][r] + a[l - 1] * i);
					}
				}
				if (r + 1 < n) {
					chmax(dp[1][i - 1][l][r + 1], dp[1][i][l][r] + a[r + 1] * i);
					if (i == 1) {
						chmax(res[r + 1], dp[1][i][l][r] + a[r + 1] * i);
					}
				}
				if (l != r) {
					{
						int nxt = max(0, i - 2);
						for (int j = 0; j < 2; j++) chmax(dp[j][nxt][l][r], dp[j][i][l][r]);
						if (i == 2) {
							chmax(res[l], dp[0][i][l][r]);
							chmax(res[r], dp[1][i][l][r]);
						}
					}
					{
						int nxt = max(0, i - (r - l));
						for (int j = 0; j < 2; j++) chmax(dp[j ^ 1][nxt][l][r], dp[j][i][l][r]);
						if (r - l >= i) {
							chmax(res[l + i], dp[0][i][l][r]);
							chmax(res[r - i], dp[1][i][l][r]);
						}
					}
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		ll ans = -INF;
		if (i + 1 < n) chmax(ans, res[i + 1]);
		if (i > 0) chmax(ans, res[i - 1]);
		cout << ans << "\n";
	}
}
0