結果

問題 No.1247 ブロック登り
ユーザー 👑 jupirojupiro
提出日時 2020-10-19 19:53:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,774 bytes
コンパイル時間 2,722 ms
コンパイル使用メモリ 140,704 KB
実行使用メモリ 331,564 KB
最終ジャッジ日時 2023-09-28 13:23:45
合計ジャッジ時間 20,941 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 3 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1,528 ms
331,424 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:57:34: 警告: overflow in conversion from ‘long long int’ to ‘ll’ {aka ‘int’} changes value from ‘-1152921504606846976’ to ‘0’ [-Woverflow]
   57 |                         ll ans = -INF;
      |                                  ^~~~
main.cpp:64:60: 警告: overflow in conversion from ‘long long int’ to ‘std::vector<int>::value_type’ {aka ‘int’} changes value from ‘-1152921504606846976’ to ‘0’ [-Woverflow]
   64 |         vector dp(2, vector(K + 1, vector(n, vector<ll>(n, -INF))));
      |                                                            ^~~~
main.cpp:68:27: 警告: overflow in conversion from ‘long long int’ to ‘std::vector<int>::value_type’ {aka ‘int’} changes value from ‘-1152921504606846976’ to ‘0’ [-Woverflow]
   68 |         vector<ll> res(n, -INF);
      |                           ^~~~
main.cpp:107:26: 警告: overflow in conversion from ‘long long int’ to ‘ll’ {aka ‘int’} changes value from ‘-1152921504606846976’ to ‘0’ [-Woverflow]
  107 |                 ll ans = -INF;
      |                          ^~~~

ソースコード

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;

using ll = int;
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