結果

問題 No.1247 ブロック登り
ユーザー 沙耶花沙耶花
提出日時 2020-10-02 23:38:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,119 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 209,344 KB
実行使用メモリ 231,380 KB
最終ジャッジ日時 2023-09-24 23:58:57
合計ジャッジ時間 9,598 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 190 ms
231,092 KB
testcase_01 AC 193 ms
226,780 KB
testcase_02 AC 193 ms
226,668 KB
testcase_03 AC 187 ms
226,640 KB
testcase_04 AC 189 ms
226,592 KB
testcase_05 AC 188 ms
226,728 KB
testcase_06 AC 188 ms
226,636 KB
testcase_07 AC 198 ms
226,628 KB
testcase_08 AC 271 ms
226,700 KB
testcase_09 AC 192 ms
226,696 KB
testcase_10 AC 190 ms
226,928 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 <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000300

int N,K;
vector<int> A;

int get(int l,int r,int isL,int now){

	if(l<0||r>=N)return -Inf;
	if(now>K)return -Inf;
	static vector dp(301,vector(301,vector(2,vector(301,-Inf))));
	
	if(dp[l][r][isL][now]!=-Inf)return dp[l][r][isL][now];
	int ret = -Inf;
	if(l==r){
		if(now==K)ret = now * A[l];
		else ret = -Inf;
	}
	else{
		if(isL){
			ret = max(ret,get(l+1,r,isL,now+1) + A[l] * now);
		}
		else{
			ret = max(ret,get(l,r-1,isL,now+1) + A[r]*now);
		}
		
		ret = max(ret,get(l,r,isL,now+2));
		ret = max(ret,get(l,r,isL^1,now+(r-l)));
		
	}
	
	dp[l][r][isL][now] = ret;
	return ret;
}

int main(){	

	cin>>N>>K;
	
	A.resize(N);
	rep(i,N)cin>>A[i];
	
	vector<int> ans(N,-Inf);
	
	for(int i=0;i<N;i++){
		for(int j=i;j<N;j++){
			for(int k=0;k<=K;k++){
				int t = get(i,j,0,k);
				if(j-k>=i)ans[j-k] = max(ans[j-k],t);
				t = get(i,j,1,k);
				if(i+k<=j)ans[i+k] = max(ans[i+k],t);
			}
			
		}
	}
	//cout<<get(2,4,0,0)<<endl;
	rep(i,N){
		cout<<ans[i]<<endl;
	}
	
    return 0;
}
0