結果

問題 No.1247 ブロック登り
ユーザー mugen_1337mugen_1337
提出日時 2020-10-03 01:50:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 578 ms / 3,000 ms
コード長 2,415 bytes
コンパイル時間 2,059 ms
コンパイル使用メモリ 204,148 KB
実行使用メモリ 469,048 KB
最終ジャッジ日時 2023-09-25 03:33:37
合計ジャッジ時間 12,505 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 162 ms
468,880 KB
testcase_01 AC 168 ms
468,816 KB
testcase_02 AC 158 ms
468,892 KB
testcase_03 AC 157 ms
468,968 KB
testcase_04 AC 202 ms
468,968 KB
testcase_05 AC 125 ms
468,900 KB
testcase_06 AC 125 ms
468,956 KB
testcase_07 AC 129 ms
468,848 KB
testcase_08 AC 129 ms
468,896 KB
testcase_09 AC 127 ms
468,960 KB
testcase_10 AC 128 ms
468,800 KB
testcase_11 AC 548 ms
468,808 KB
testcase_12 AC 528 ms
469,048 KB
testcase_13 AC 563 ms
468,852 KB
testcase_14 AC 564 ms
468,800 KB
testcase_15 AC 578 ms
468,868 KB
testcase_16 AC 553 ms
468,860 KB
testcase_17 AC 551 ms
468,832 KB
testcase_18 AC 507 ms
468,844 KB
testcase_19 AC 165 ms
468,976 KB
testcase_20 AC 138 ms
468,832 KB
testcase_21 AC 127 ms
468,856 KB
testcase_22 AC 200 ms
468,796 KB
testcase_23 AC 134 ms
468,864 KB
testcase_24 AC 126 ms
468,904 KB
testcase_25 AC 572 ms
468,840 KB
testcase_26 AC 541 ms
468,844 KB
testcase_27 AC 533 ms
468,912 KB
testcase_28 AC 543 ms
468,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}


ll dp[310][310][310][2];
/*
dp[i][l][r][t]:
    i回移動した,[l,r)決定済み,
    t = 0 => 今,左端にいます
    t = 1 =>     右端 (r-1)にいます
*/

signed main(){
    rep(i,310)rep(j,310)rep(k,310)rep(t,2)dp[i][j][k][t]=-LINF;
    rep(i,310) dp[0][i][i][0]=0,dp[0][i][i][1]=0;
    

    int n,k;cin>>n>>k;
    vector<ll> a(n);
    cin>>a;

    if(k==1){
        rep(i,n){
            ll res=-LINF;
            if(i) chmax(res,a[i-1]);
            if(i<n-1) chmax(res,a[i+1]);
            cout<<res<<endl;
        }
        return 0;
    }

    rep(i,k+1)rep(l,n+1)for(int r=l;r<=n;r++)rep(t,2){
        int w=r-l;// width
        ll mul=k-i;
        // stay
        if(i+2<=k+1 and w>1) chmax(dp[i+2][l][r][t],dp[i][l][r][t]);
        // left to right
        if(t==0 and i+w-1<=k+1 and w>0) chmax(dp[i+w-1][l][r][1],dp[i][l][r][t]);
        // right to left
        if(t==1 and i+w-1<=k+1 and w>0) chmax(dp[i+w-1][l][r][0],dp[i][l][r][t]);
        // left -> left-1
        if(t==0 and l>0) chmax(dp[i+1][l-1][r][t],dp[i][l][r][t]+a[l-1]*mul);
        // right -> right+1
        if(t==1 and r<n) chmax(dp[i+1][l][r+1][t],dp[i][l][r][t]+a[r]*mul);
    }

    vector<ll> res(n,-LINF);
    rep(i,k+2)rep(l,n+1)for(int r=l;r<=n;r++){
        int rem=k+1-i;
        if(l+rem<r)    chmax(res[l+rem],dp[i][l][r][0]);
        if(l<=r-1-rem) chmax(res[r-1-rem],dp[i][l][r][1]);
    }
    for(auto &x:res) cout<<x<<endl;
    return 0;
}
0