結果
問題 | No.1247 ブロック登り |
ユーザー | snow39 |
提出日時 | 2020-10-03 00:06:34 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,902 bytes |
コンパイル時間 | 824 ms |
コンパイル使用メモリ | 95,792 KB |
実行使用メモリ | 432,800 KB |
最終ジャッジ日時 | 2023-09-25 00:24:53 |
合計ジャッジ時間 | 7,350 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
7,504 KB |
testcase_01 | AC | 3 ms
9,580 KB |
testcase_02 | AC | 3 ms
11,756 KB |
testcase_03 | WA | - |
testcase_04 | AC | 4 ms
15,764 KB |
testcase_05 | AC | 5 ms
18,120 KB |
testcase_06 | WA | - |
testcase_07 | AC | 17 ms
73,540 KB |
testcase_08 | AC | 18 ms
81,796 KB |
testcase_09 | AC | 14 ms
65,172 KB |
testcase_10 | AC | 11 ms
50,880 KB |
testcase_11 | AC | 475 ms
432,188 KB |
testcase_12 | AC | 365 ms
412,012 KB |
testcase_13 | AC | 395 ms
432,628 KB |
testcase_14 | AC | 392 ms
432,592 KB |
testcase_15 | AC | 393 ms
432,584 KB |
testcase_16 | AC | 391 ms
432,800 KB |
testcase_17 | AC | 400 ms
432,720 KB |
testcase_18 | AC | 372 ms
409,260 KB |
testcase_19 | AC | 39 ms
68,888 KB |
testcase_20 | AC | 15 ms
27,968 KB |
testcase_21 | WA | - |
testcase_22 | AC | 76 ms
282,904 KB |
testcase_23 | AC | 71 ms
279,956 KB |
testcase_24 | AC | 53 ms
262,660 KB |
testcase_25 | AC | 398 ms
432,576 KB |
testcase_26 | AC | 391 ms
432,508 KB |
testcase_27 | AC | 396 ms
432,516 KB |
testcase_28 | AC | 416 ms
432,520 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; } 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; }