結果
| 問題 |
No.1247 ブロック登り
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2020-10-02 23:11:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,203 bytes |
| コンパイル時間 | 2,111 ms |
| コンパイル使用メモリ | 205,032 KB |
| 最終ジャッジ日時 | 2025-01-15 01:13:46 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 WA * 3 |
ソースコード
#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;
}
emthrm