結果
問題 | No.1247 ブロック登り |
ユーザー | snow39 |
提出日時 | 2020-10-03 00:07:51 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 551 ms / 3,000 ms |
コード長 | 2,066 bytes |
コンパイル時間 | 2,566 ms |
コンパイル使用メモリ | 95,112 KB |
実行使用メモリ | 431,516 KB |
最終ジャッジ日時 | 2023-09-25 00:26:11 |
合計ジャッジ時間 | 8,607 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
7,564 KB |
testcase_01 | AC | 3 ms
9,720 KB |
testcase_02 | AC | 3 ms
11,768 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 4 ms
16,040 KB |
testcase_05 | AC | 5 ms
17,852 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 17 ms
58,760 KB |
testcase_08 | AC | 18 ms
60,144 KB |
testcase_09 | AC | 15 ms
57,716 KB |
testcase_10 | AC | 12 ms
50,884 KB |
testcase_11 | AC | 551 ms
431,188 KB |
testcase_12 | AC | 501 ms
411,384 KB |
testcase_13 | AC | 551 ms
431,220 KB |
testcase_14 | AC | 534 ms
431,220 KB |
testcase_15 | AC | 533 ms
431,280 KB |
testcase_16 | AC | 535 ms
431,364 KB |
testcase_17 | AC | 541 ms
431,516 KB |
testcase_18 | AC | 480 ms
403,816 KB |
testcase_19 | AC | 41 ms
68,912 KB |
testcase_20 | AC | 15 ms
28,016 KB |
testcase_21 | AC | 3 ms
4,788 KB |
testcase_22 | AC | 52 ms
110,916 KB |
testcase_23 | AC | 48 ms
119,036 KB |
testcase_24 | AC | 18 ms
81,408 KB |
testcase_25 | AC | 527 ms
431,344 KB |
testcase_26 | AC | 529 ms
431,404 KB |
testcase_27 | AC | 540 ms
431,404 KB |
testcase_28 | AC | 540 ms
431,220 KB |
ソースコード
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; 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;} const ll INF=1e18; ll dp[303][303][303][2]; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,K; cin>>N>>K; vector<ll> A(N); rep(i,N) cin>>A[i]; //vector<vector<vector<ll>>> dp(N,vector<vector<ll>> (N,vector<ll> (2,-INF))); rep(i,K) rep(j,N) rep(k,N) rep(m,2) dp[i][j][k][m]=-INF; rep(i,N){ dp[K-1][i][i][0]=A[i]*K; dp[K-1][i][i][1]=A[i]*K; } if(K==1){ rep(i,N){ ll ans=-INF; if(i-1>=0) chmax(ans,A[i-1]); if(i+1<N) chmax(ans,A[i+1]); cout<<ans<<"\n"; } return 0; } for(int i=K-1;i>=1;i--){ for(int j=0;j<N;j++) for(int k=j;k<N;k++) for(int m=0;m<2;m++){ if(dp[i][j][k][m]==-INF) continue; ll val=dp[i][j][k][m]; if(m==0){ if(j-1>=0) chmax(dp[i-1][j-1][k][0],val+i*A[j-1]); if(i-(k-j)>=0)chmax(dp[i-(k-j)][j][k][1],val); if(i-2>=0&&j<k) chmax(dp[i-2][j][k][m],val); }else{ if(k+1<N) chmax(dp[i-1][j][k+1][1],val+i*A[k+1]); if(i-(k-j)>=0)chmax(dp[i-(k-j)][j][k][0],val); if(i-2>=0&&j<k) chmax(dp[i-2][j][k][m],val); } } } vector<ll> ans(N,-INF); for(int i=0;i<=K-2;i++) for(int j=0;j<N;j++) for(int k=j;k<N;k++) for(int m=0;m<2;m++){ ll val=dp[i][j][k][m]; if(val==-INF) continue; if(m==1){ if(k-i>=j){ if(k-i+1<N) chmax(ans[k-i+1],val); if(k-i-1>=0) chmax(ans[k-i-1],val); } }else{ if(j+i<=k){ if(j+i+1<N) chmax(ans[j+i+1],val); if(j+i-1>=0) chmax(ans[j+i-1],val); } } } rep(i,N) cout<<ans[i]<<"\n"; return 0; }