結果

問題 No.1247 ブロック登り
ユーザー 👑 emthrmemthrm
提出日時 2020-10-02 23:12:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,204 bytes
コンパイル時間 2,499 ms
コンパイル使用メモリ 211,760 KB
実行使用メモリ 647,420 KB
最終ジャッジ日時 2023-09-24 23:14:14
合計ジャッジ時間 22,567 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 7 ms
7,272 KB
testcase_08 AC 7 ms
7,816 KB
testcase_09 AC 3 ms
4,580 KB
testcase_10 AC 4 ms
4,804 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 219 ms
106,744 KB
testcase_20 AC 73 ms
47,384 KB
testcase_21 WA -
testcase_22 AC 16 ms
14,136 KB
testcase_23 AC 11 ms
11,548 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, k; cin >> n >> k;
  vector<int> a(n); REP(i, n) cin >> a[i];
  if (k == 1) {
    cout << *max_element(ALL(a)) << '\n';
    return 0;
  }
  vector dp(2, vector(n, vector(n, vector(k, -LINF))));
  REP(i, n - 1) {
    dp[false][i][i + 1][k - 1] = a[i] * (k - 1) + a[i + 1] * k;
    dp[true][i][i + 1][k - 1] = a[i] * k + a[i + 1] * (k - 1);
  }
  for (int h = k - 1; h > 1; --h) {
    REP(l, n) FOR(r, l + 1, n) {
      if (l > 0) chmax(dp[false][l - 1][r][h - 1], dp[false][l][r][h] + a[l - 1] * (h - 1));
      if (r + 1 < n) chmax(dp[true][l][r + 1][h - 1], dp[true][l][r][h] + a[r + 1] * (h - 1));
      if (h - (r - l) >= 1) {
        chmax(dp[true][l][r][h - (r - l)], dp[false][l][r][h]);
        chmax(dp[false][l][r][h - (r - l)], dp[true][l][r][h]);
      }
      if (h >= 3) {
        chmax(dp[false][l][r][h - 2], dp[false][l][r][h]);
        chmax(dp[true][l][r][h - 2], dp[true][l][r][h]);
      }
    }
  }
  vector<ll> score(n, -LINF);
  REP(i, n) {
    REP(l, i + 1) FOR(r, i, n) {
      if (i - l + 1 < k) chmax(score[i], dp[false][l][r][i - l + 1]);
      if (r - i + 1 < k) chmax(score[i], dp[true][l][r][r - i + 1]);
    }
  }
  REP(i, n) {
    ll ans = -LINF;
    if (i > 0) chmax(ans, score[i - 1]);
    if (i + 1 < n) chmax(ans, score[i + 1]);
    cout << ans << '\n';
  }
  return 0;
}
0