結果

問題 No.1247 ブロック登り
ユーザー yukudoyukudo
提出日時 2020-10-07 01:07:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,166 ms / 3,000 ms
コード長 2,086 bytes
コンパイル時間 1,622 ms
コンパイル使用メモリ 167,000 KB
実行使用メモリ 446,884 KB
最終ジャッジ日時 2023-09-27 09:05:22
合計ジャッジ時間 20,045 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 178 ms
446,600 KB
testcase_01 AC 178 ms
446,600 KB
testcase_02 AC 177 ms
446,612 KB
testcase_03 AC 179 ms
446,772 KB
testcase_04 AC 178 ms
446,756 KB
testcase_05 AC 179 ms
446,772 KB
testcase_06 AC 178 ms
446,704 KB
testcase_07 AC 181 ms
446,664 KB
testcase_08 AC 181 ms
446,748 KB
testcase_09 AC 179 ms
446,648 KB
testcase_10 AC 178 ms
446,612 KB
testcase_11 AC 1,166 ms
446,752 KB
testcase_12 AC 1,019 ms
446,660 KB
testcase_13 AC 1,053 ms
446,756 KB
testcase_14 AC 1,081 ms
446,660 KB
testcase_15 AC 1,073 ms
446,664 KB
testcase_16 AC 1,152 ms
446,880 KB
testcase_17 AC 1,095 ms
446,704 KB
testcase_18 AC 965 ms
446,756 KB
testcase_19 AC 256 ms
446,740 KB
testcase_20 AC 209 ms
446,752 KB
testcase_21 AC 181 ms
446,684 KB
testcase_22 AC 187 ms
446,760 KB
testcase_23 AC 182 ms
446,884 KB
testcase_24 AC 179 ms
446,880 KB
testcase_25 AC 982 ms
446,776 KB
testcase_26 AC 1,038 ms
446,880 KB
testcase_27 AC 1,004 ms
446,704 KB
testcase_28 AC 1,006 ms
446,700 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];
      if (val < -INF / 2) continue;
      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);
      }
    }
  }

  for (int k = 0; k < K; k++) 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 (side == 0) {
      if (L + k <= R) chmax(ans[L+k], val);
    }
    else if (side == 1) {
      if (R - k >= L) chmax(ans[R-k], val);
    }
  }

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

int main() {

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