結果

問題 No.1247 ブロック登り
ユーザー LayCurseLayCurse
提出日時 2020-10-02 23:11:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,436 ms / 3,000 ms
コード長 3,720 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 211,164 KB
実行使用メモリ 427,532 KB
最終ジャッジ日時 2023-09-24 23:09:07
合計ジャッジ時間 22,567 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,592 KB
testcase_01 AC 4 ms
15,672 KB
testcase_02 AC 4 ms
17,740 KB
testcase_03 AC 2 ms
7,448 KB
testcase_04 AC 5 ms
19,904 KB
testcase_05 AC 6 ms
24,048 KB
testcase_06 AC 2 ms
7,456 KB
testcase_07 AC 19 ms
77,544 KB
testcase_08 AC 21 ms
85,916 KB
testcase_09 AC 15 ms
69,352 KB
testcase_10 AC 13 ms
57,140 KB
testcase_11 AC 1,375 ms
427,308 KB
testcase_12 AC 2,045 ms
409,256 KB
testcase_13 AC 2,436 ms
427,420 KB
testcase_14 AC 1,336 ms
427,356 KB
testcase_15 AC 1,311 ms
427,532 KB
testcase_16 AC 1,355 ms
427,352 KB
testcase_17 AC 1,277 ms
427,360 KB
testcase_18 AC 1,252 ms
404,528 KB
testcase_19 AC 141 ms
73,040 KB
testcase_20 AC 68 ms
34,196 KB
testcase_21 AC 36 ms
11,168 KB
testcase_22 AC 79 ms
189,236 KB
testcase_23 AC 71 ms
184,712 KB
testcase_24 AC 35 ms
155,308 KB
testcase_25 AC 1,371 ms
427,356 KB
testcase_26 AC 1,362 ms
427,300 KB
testcase_27 AC 1,411 ms
427,376 KB
testcase_28 AC 1,302 ms
427,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int K;
int A[300];
long long dp[2][301][300][300];
long long solve(int f, int r, int a, int b){
  if(r > K){
    return -4611686016279904256LL;
  }
  long long&res = dp[f][r][a][b];
  if(res != 4611686016279904256LL){
    return res;
  }
  res = -4611686016279904256LL;
  if(r==K && a==b){
    chmax(res, A[a] * K);
  }
  if(a != b){
    chmax(res, solve(f, r+2, a, b));
  }
  if(a != b){
    chmax(res, solve(f^1, r+(b-a), a, b));
  }
  if(f==0 && a != b){
    chmax(res, solve(f, r+1, a+1, b) + A[a] * r);
  }
  if(f==1 && a != b){
    chmax(res, solve(f, r+1, a, b-1) + A[b] * r);
  }
  return res;
}
int main(){
  int i;
  long long res;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(2);i++){
    int j;
    for(j=(0);j<(K+1);j++){
      int k;
      for(k=(0);k<(N);k++){
        int l;
        for(l=(0);l<(N);l++){
          dp[i][j][k][l] = 4611686016279904256LL;
        }
      }
    }
  }
  for(i=(0);i<(N);i++){
    int j;
    res = -4611686016279904256LL;
    for(j=(0);j<(N);j++){
      int k;
      for(k=(j);k<(N);k++){
        if(j <= i  &&  i <= k){
          chmax(res, solve(0, i-j, j, k));
          chmax(res, solve(1, k-i, j, k));
        }
      }
    }
    wt_L(res);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200926-1

// --- original code ---
// int N, K, A[300];
// ll dp[2][301][300][300];
// 
// ll solve(int f, int r, int a, int b){
//   if(r > K) return -ll_inf;
// 
//   ll &res = dp[f][r][a][b];
//   if(res != ll_inf) return res;
//   res = -ll_inf;
// 
//   if(r==K && a==b) res >?= A[a] * K;
// 
//   if(a != b) res >?= solve(f, r+2, a, b);
//   if(a != b) res >?= solve(f^1, r+(b-a), a, b);
// 
//   if(f==0 && a != b) res >?= solve(f, r+1, a+1, b) + A[a] * r;
//   if(f==1 && a != b) res >?= solve(f, r+1, a, b-1) + A[b] * r;
// 
//   return res;
// }
// 
// {
//   ll res;
//   rd(N,K,A(N));
//   rep(i,2) rep(j,K+1) rep(k,N) rep(l,N) dp[i][j][k][l] = ll_inf;
// 
//   rep(i,N){
//     res = -ll_inf;
//     rep(j,N) rep(k,j,N) if(j <= i <= k){
//       res >?= solve(0, i-j, j, k);
//       res >?= solve(1, k-i, j, k);
//     }
//     wt(res);
//   }
// }
0