結果

問題 No.1247 ブロック登り
ユーザー yukudoyukudo
提出日時 2020-10-07 00:44:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,104 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 168,056 KB
実行使用メモリ 450,744 KB
最終ジャッジ日時 2023-09-27 09:01:29
合計ジャッジ時間 9,923 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 228 ms
446,688 KB
testcase_01 AC 214 ms
446,572 KB
testcase_02 AC 214 ms
446,664 KB
testcase_03 AC 213 ms
446,612 KB
testcase_04 AC 214 ms
446,600 KB
testcase_05 AC 211 ms
446,744 KB
testcase_06 AC 211 ms
446,820 KB
testcase_07 AC 220 ms
446,604 KB
testcase_08 AC 236 ms
446,880 KB
testcase_09 AC 186 ms
446,668 KB
testcase_10 AC 159 ms
446,832 KB
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 <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) {
    if (L == R) {
      if (k == 0) chmax(ans[L], dp[L][R][side][k]);
    } else {
      const int P = (side == 0 ? L : R);
      for (int i = L; i <= R; i++) {
        if (abs(P - i) <= k && (k - abs(P - i)) % 2 == 0) {
          chmax(ans[i], dp[L][R][side][k]);
        }
      }
    }
  }

  REP(i, N)
    cout << ans[i] << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}
0