結果
| 問題 |
No.1247 ブロック登り
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-05-20 22:36:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,458 bytes |
| コンパイル時間 | 1,350 ms |
| コンパイル使用メモリ | 117,568 KB |
| 最終ジャッジ日時 | 2025-01-21 14:00:38 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 2 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
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; }
using namespace std;
typedef long long ll;
const ll INF = 1e18;
ll dp[305][305][305][2];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int n, k; cin >> n >> k;
vector<ll> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
for(int j = k; j >= 0; j--){
for(int l = 0; l < n; l++){
for(int r = l+1; r <= n; r++){
dp[l][r][j][0] = -INF;
dp[l][r][j][1] = -INF;
}
}
}
for(int l = 0; l < n; l++){
dp[l][l+1][k][0] = a[l]*k;
dp[l][l+1][k][1] = a[l]*k;
}
for(int j = k; j > 0; j--){
// cout << j << endl;
for(int l = 0; l < n; l++){
for(int r = l+1; r <= n; r++){
for(int p = 0; p < 2; p++){
// cout << "dp[" << l << "][" << r << "][" << j << "][" << p << "] = " << dp[l][r][j][p] << endl;
int cur = (p == 0 ? l : r-1);
// とどまる
if(j >= 2 && r-l >= 2) chmax(dp[l][r][j-2][p], dp[l][r][j][p]);
// l-1に行く
int dist = cur-(l-1);
if(l > 0 && dist <= j) chmax(dp[l-1][r][j-dist][0], dp[l][r][j][p]+a[l-1]*(j-dist));
// rに行く
dist = r-cur;
if(r < n && dist <= j) chmax(dp[l][r+1][j-dist][1], dp[l][r][j][p]+a[r]*(j-dist));
}
}
}
}
for(int i = 0; i < n; i++){
ll ans = -INF;
for(int l = 0; l <= i; l++){
for(int r = max(i+1, l+1); r <= n; r++){
// lから来る
chmax(ans, dp[l][r][i-l][0]);
// r-1から来る
chmax(ans, dp[l][r][(r-1)-i][1]);
}
}
cout << ans << endl;
}
}
milanis48663220