結果
問題 | No.1247 ブロック登り |
ユーザー | beet |
提出日時 | 2020-10-02 23:39:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 523 ms / 3,000 ms |
コード長 | 2,270 bytes |
コンパイル時間 | 2,027 ms |
コンパイル使用メモリ | 204,840 KB |
実行使用メモリ | 435,004 KB |
最終ジャッジ日時 | 2023-09-25 00:00:05 |
合計ジャッジ時間 | 9,270 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
9,572 KB |
testcase_01 | AC | 3 ms
11,768 KB |
testcase_02 | AC | 4 ms
15,780 KB |
testcase_03 | AC | 2 ms
5,480 KB |
testcase_04 | AC | 4 ms
17,876 KB |
testcase_05 | AC | 5 ms
21,948 KB |
testcase_06 | AC | 2 ms
5,500 KB |
testcase_07 | AC | 19 ms
75,460 KB |
testcase_08 | AC | 20 ms
83,680 KB |
testcase_09 | AC | 15 ms
67,080 KB |
testcase_10 | AC | 12 ms
54,888 KB |
testcase_11 | AC | 523 ms
434,732 KB |
testcase_12 | AC | 453 ms
414,896 KB |
testcase_13 | AC | 480 ms
434,888 KB |
testcase_14 | AC | 476 ms
434,708 KB |
testcase_15 | AC | 479 ms
435,004 KB |
testcase_16 | AC | 472 ms
434,840 KB |
testcase_17 | AC | 471 ms
434,756 KB |
testcase_18 | AC | 429 ms
408,904 KB |
testcase_19 | AC | 50 ms
70,944 KB |
testcase_20 | AC | 17 ms
30,252 KB |
testcase_21 | AC | 4 ms
7,472 KB |
testcase_22 | AC | 72 ms
199,068 KB |
testcase_23 | AC | 66 ms
194,548 KB |
testcase_24 | AC | 36 ms
165,664 KB |
testcase_25 | AC | 460 ms
434,952 KB |
testcase_26 | AC | 467 ms
434,708 KB |
testcase_27 | AC | 466 ms
434,716 KB |
testcase_28 | AC | 474 ms
434,768 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using Int = long long; const char newl = '\n'; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} template<typename T=Int> vector<T> read(size_t n){ vector<T> ts(n); for(size_t i=0;i<n;i++) cin>>ts[i]; return ts; } //INSERT ABOVE HERE const Int MAX = 303; const Int INF = 1e18; Int dp[MAX][2][MAX][MAX]; Int mx[MAX][MAX]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); Int n,k; cin>>n>>k; auto as=read(n); vector<Int> ans(n); // start from parity for(Int p=0;p<2;p++){ // init for(Int i=0;i<=k;i++) for(Int l=0;l<n;l++) for(Int r=0;r<n;r++) dp[i][0][l][r]=dp[i][1][l][r]=-INF; for(Int l=0;l<n;l++) for(Int r=0;r<n;r++) mx[l][r]=-INF; // [l, r] for(Int l=0;l+1<n;l++){ Int r=l+1; if((abs(r-k)&1)==p) chmax(dp[k-1][0][l][r],as[l]*(k-1)+as[r]*(k-0)); if((abs(l-k)&1)==p) chmax(dp[k-1][1][l][r],as[l]*(k-0)+as[r]*(k-1)); } for(Int i=k-1;i>=0;i--){ for(Int l=0;l<n;l++){ for(Int r=l+1;r<n;r++){ // [l, r] if(dp[i][0][l][r]!=-INF) chmax(mx[l][min(l+i,r)],dp[i][0][l][r]); if(dp[i][1][l][r]!=-INF) chmax(mx[max(l,r-i)][r],dp[i][1][l][r]); if(i==0) continue; if(dp[i][0][l][r]!=-INF){ Int res=dp[i][0][l][r]; if(l>=1) chmax(dp[i-1][0][l-1][r],res+as[l-1]*(i-1)); if(i>=2) chmax(dp[i-2][0][l][r],res); if((r-l)<=i) chmax(dp[i-(r-l)][1][l][r],res); } if(dp[i][1][l][r]!=-INF){ Int res=dp[i][1][l][r]; if(r+1<n) chmax(dp[i-1][1][l][r+1],res+as[r+1]*(i-1)); if(i>=2) chmax(dp[i-2][1][l][r],res); if((r-l)<=i) chmax(dp[i-(r-l)][0][l][r],res); } } } } for(Int w=n-1;w>=1;w--){ for(Int l=0;l+w<n;l++){ chmax(mx[l+1][l+w],mx[l][l+w]); chmax(mx[l][l+w-1],mx[l][l+w]); } } for(Int i=p;i<n;i+=2) ans[i]=mx[i][i]; } for(Int i=0;i<n;i++) cout<<ans[i]<<newl; return 0; }