結果

問題 No.1247 ブロック登り
ユーザー simansiman
提出日時 2023-06-22 03:24:24
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,956 bytes
コンパイル時間 5,038 ms
コンパイル使用メモリ 108,460 KB
実行使用メモリ 44,972 KB
最終ジャッジ日時 2023-09-11 22:06:55
合計ジャッジ時間 12,153 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,596 KB
testcase_01 AC 3 ms
7,572 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 4 ms
11,680 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int h_dp[310][310][2][310];
int N, K;
int A[310];

int solver(int start_idx) {
  vector<vector<int>> dp(N, vector<int>(2, INT_MIN));
  dp[start_idx][0] = 0;
  dp[start_idx][1] = 0;
  memset(h_dp[0][start_idx], 0, sizeof(h_dp[0][start_idx]));

  for (int i = 1; i <= K; ++i) {
    vector<vector<int>> temp(N, vector<int>(2, INT_MIN));

    for (int j = 0; j < N; ++j) {
      for (int d = 0; d < 2; ++d) {
        if (dp[j][d] == INT_MIN) continue;

        int cur_score = dp[j][d];

        if (j - 1 >= 0) {
          int before_score = A[j - 1] * h_dp[i - 1][j][d][j - 1];
          int after_score = A[j - 1] * i;
          int new_score = cur_score + (after_score - before_score);

          if (temp[j - 1][0] < new_score) {
            temp[j - 1][0] = new_score;
            memcpy(h_dp[i][j - 1][0], h_dp[i - 1][j][d], sizeof(h_dp[i - 1][j][d]));
            h_dp[i][j - 1][0][j - 1] = i;
          }
        }

        if (j + 1 < N) {
          int before_score = A[j + 1] * h_dp[i - 1][j][d][j + 1];
          int after_score = A[j + 1] * i;
          int new_score = cur_score + (after_score - before_score);

          if (temp[j + 1][1] < new_score) {
            temp[j + 1][1] = new_score;
            memcpy(h_dp[i][j + 1][1], h_dp[i - 1][j][d], sizeof(h_dp[i - 1][j][d]));
            h_dp[i][j + 1][1][j + 1] = i;
          }
        }
      }
    }

    dp = temp;
  }

  int res = INT_MIN;

  for (int i = 0; i < N; ++i) {
    res = max(res, dp[i][0]);
    res = max(res, dp[i][1]);
  }

  return res;
}

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  for (int i = 0; i < N; ++i) {
    int res = solver(i);
    cout << res << endl;
  }

  return 0;
}
0