結果
| 問題 |
No.1247 ブロック登り
|
| ユーザー |
|
| 提出日時 | 2020-10-07 00:56:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,250 bytes |
| コンパイル時間 | 1,738 ms |
| コンパイル使用メモリ | 171,036 KB |
| 実行使用メモリ | 453,656 KB |
| 最終ジャッジ日時 | 2024-07-20 03:09:37 |
| 合計ジャッジ時間 | 10,710 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 TLE * 8 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
#ifdef LOCAL
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cerr<<(*i)<<" ";cerr<<endl;}
#else
template<class T>void pv(T a,T b){}
#endif
ll nextLong() { ll x; scanf("%lld", &x); return x;}
const ll INF = 1LL << 61;
const int MAX_N = 305;
ll A[MAX_N];
ll dp[MAX_N][MAX_N][2][MAX_N];
ll ans[MAX_N];
int main2() {
int N = nextLong();
int K = nextLong();
REP(i, N) A[i] = nextLong();
REP(i, N) ans[i] = -INF;
REP(L, MAX_N) REP(R, MAX_N) REP(side, 2) REP(k, MAX_N) dp[L][R][side][k] = -INF;
REP(i, N) {
dp[i][i][0][K] = K * A[i];
dp[i][i][1][K] = K * A[i];
}
for (int k = K; k >= 0; k--) {
REP(L, N) for (int R = L; R < N; R++) REP(side, 2) {
const ll val = dp[L][R][side][k];
const int D = R - L;
if (side == 0 && L - 1 >= 0 && k-1 >= 0) {
chmax(dp[L-1][R][side][k-1], val + (k-1) * A[L-1]);
}
if (side == 1 && R + 1 <= N-1 && k-1 >= 0) {
chmax(dp[L][R+1][side][k-1], val + (k-1) * A[R+1]);
}
if (D >= 1 && k - D >= 0) {
chmax(dp[L][R][1-side][k-D], val);
}
if (D >= 1 && k - 2 >= 0) {
chmax(dp[L][R][side][k-2], val);
}
}
}
REP(k, K+1) REP(L, N) for (int R = L; R < N; R++) REP(side, 2) {
const ll val = dp[L][R][side][k];
if (val < -INF / 2) continue;
if (L == R) {
if (k == 0) chmax(ans[L], val);
} else {
if (side == 0) {
for (int i = L; i-L <= k && i <= R; i++) {
if ((i-L-k) % 2 == 0) chmax(ans[i], val);
}
}
if (side == 1) {
for (int i = R; R-i <= k && i >= L; i--) {
if ((R-i-k) % 2 == 0) chmax(ans[i], val);
}
}
}
}
REP(i, N)
cout << ans[i] << endl;
return 0;
}
int main() {
#ifdef LOCAL
for (;!cin.eof();cin>>ws)
#endif
main2();
return 0;
}