結果

問題 No.1247 ブロック登り
ユーザー LayCurseLayCurse
提出日時 2020-10-02 23:12:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,220 ms / 3,000 ms
コード長 3,659 bytes
コンパイル時間 2,726 ms
コンパイル使用メモリ 212,276 KB
実行使用メモリ 427,532 KB
最終ジャッジ日時 2023-09-24 23:13:10
合計ジャッジ時間 18,462 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,564 KB
testcase_01 AC 4 ms
15,684 KB
testcase_02 AC 4 ms
17,752 KB
testcase_03 AC 2 ms
7,496 KB
testcase_04 AC 5 ms
19,804 KB
testcase_05 AC 6 ms
24,008 KB
testcase_06 AC 3 ms
7,420 KB
testcase_07 AC 19 ms
74,160 KB
testcase_08 AC 21 ms
75,676 KB
testcase_09 AC 17 ms
69,092 KB
testcase_10 AC 13 ms
56,892 KB
testcase_11 AC 1,213 ms
427,200 KB
testcase_12 AC 1,063 ms
408,988 KB
testcase_13 AC 1,115 ms
427,296 KB
testcase_14 AC 1,121 ms
427,260 KB
testcase_15 AC 1,182 ms
427,532 KB
testcase_16 AC 1,220 ms
427,324 KB
testcase_17 AC 1,179 ms
427,444 KB
testcase_18 AC 1,067 ms
403,592 KB
testcase_19 AC 139 ms
72,928 KB
testcase_20 AC 67 ms
34,076 KB
testcase_21 AC 35 ms
10,924 KB
testcase_22 AC 68 ms
148,652 KB
testcase_23 AC 61 ms
141,352 KB
testcase_24 AC 24 ms
106,616 KB
testcase_25 AC 1,138 ms
427,264 KB
testcase_26 AC 1,139 ms
427,264 KB
testcase_27 AC 1,127 ms
427,268 KB
testcase_28 AC 1,080 ms
427,296 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(int x){
  int s=0;
  int m=0;
  char f[10];
  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 -1073709056;
  }
  long long&res = dp[f][r][a][b];
  if(res != 1073709056){
    return res;
  }
  res = -1073709056;
  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;
  int 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] = 1073709056;
        }
      }
    }
  }
  for(i=(0);i<(N);i++){
    int j;
    res = -1073709056;
    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 -int_inf;
// 
//   ll &res = dp[f][r][a][b];
//   if(res != int_inf) return res;
//   res = -int_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;
// }
// 
// {
//   int res;
//   rd(N,K,A(N));
//   rep(i,2) rep(j,K+1) rep(k,N) rep(l,N) dp[i][j][k][l] = int_inf;
// 
//   rep(i,N){
//     res = -int_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