結果

問題 No.1247 ブロック登り
ユーザー yukudoyukudo
提出日時 2020-10-07 00:56:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,250 bytes
コンパイル時間 1,618 ms
コンパイル使用メモリ 168,476 KB
実行使用メモリ 447,040 KB
最終ジャッジ日時 2023-09-27 09:02:55
合計ジャッジ時間 8,321 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
446,684 KB
testcase_01 AC 131 ms
446,664 KB
testcase_02 AC 132 ms
446,784 KB
testcase_03 AC 134 ms
446,660 KB
testcase_04 AC 134 ms
446,908 KB
testcase_05 AC 134 ms
446,788 KB
testcase_06 AC 134 ms
446,664 KB
testcase_07 AC 139 ms
446,740 KB
testcase_08 AC 139 ms
446,700 KB
testcase_09 AC 136 ms
446,660 KB
testcase_10 AC 135 ms
446,748 KB
testcase_11 AC 2,838 ms
447,040 KB
testcase_12 AC 2,630 ms
447,020 KB
testcase_13 AC 2,895 ms
446,744 KB
testcase_14 AC 2,830 ms
446,780 KB
testcase_15 AC 2,908 ms
446,784 KB
testcase_16 AC 2,823 ms
446,836 KB
testcase_17 TLE -
testcase_18 AC 2,548 ms
446,748 KB
testcase_19 AC 251 ms
446,852 KB
testcase_20 AC 175 ms
446,780 KB
testcase_21 AC 139 ms
446,752 KB
testcase_22 AC 151 ms
446,776 KB
testcase_23 AC 147 ms
447,032 KB
testcase_24 AC 134 ms
446,848 KB
testcase_25 AC 2,918 ms
446,912 KB
testcase_26 AC 2,845 ms
446,864 KB
testcase_27 AC 2,816 ms
446,768 KB
testcase_28 AC 2,848 ms
446,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0