結果

問題 No.1247 ブロック登り
ユーザー 👑 emthrmemthrm
提出日時 2020-10-02 23:11:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,203 bytes
コンパイル時間 2,923 ms
コンパイル使用メモリ 209,260 KB
実行使用メモリ 330,472 KB
最終ジャッジ日時 2023-09-24 23:09:59
合計ジャッジ時間 18,459 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 6 ms
5,168 KB
testcase_08 AC 6 ms
5,652 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 1,284 ms
330,368 KB
testcase_12 AC 1,027 ms
313,472 KB
testcase_13 AC 1,139 ms
330,348 KB
testcase_14 AC 1,264 ms
330,400 KB
testcase_15 AC 1,199 ms
330,344 KB
testcase_16 AC 1,071 ms
330,364 KB
testcase_17 AC 1,106 ms
330,452 KB
testcase_18 AC 1,062 ms
299,248 KB
testcase_19 AC 150 ms
60,056 KB
testcase_20 AC 56 ms
30,944 KB
testcase_21 WA -
testcase_22 AC 10 ms
8,596 KB
testcase_23 AC 8 ms
7,280 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1,123 ms
330,392 KB
testcase_26 AC 1,256 ms
330,472 KB
testcase_27 AC 1,153 ms
330,472 KB
testcase_28 AC 1,044 ms
330,420 KB
権限があれば一括ダウンロードができます

ソースコード

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, -INF))));
  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<int> score(n, -INF);
  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) {
    int ans = -INF;
    if (i > 0) chmax(ans, score[i - 1]);
    if (i + 1 < n) chmax(ans, score[i + 1]);
    cout << ans << '\n';
  }
  return 0;
}
0