結果
問題 | No.1247 ブロック登り |
ユーザー | 👑 kmjp |
提出日時 | 2020-10-03 00:07:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 739 ms / 3,000 ms |
コード長 | 1,705 bytes |
コンパイル時間 | 2,094 ms |
コンパイル使用メモリ | 203,108 KB |
実行使用メモリ | 220,324 KB |
最終ジャッジ日時 | 2023-09-25 00:26:29 |
合計ジャッジ時間 | 12,313 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 62 ms
220,188 KB |
testcase_01 | AC | 62 ms
220,316 KB |
testcase_02 | AC | 61 ms
220,192 KB |
testcase_03 | AC | 60 ms
220,032 KB |
testcase_04 | AC | 61 ms
220,264 KB |
testcase_05 | AC | 61 ms
220,312 KB |
testcase_06 | AC | 59 ms
219,968 KB |
testcase_07 | AC | 63 ms
220,192 KB |
testcase_08 | AC | 62 ms
219,968 KB |
testcase_09 | AC | 60 ms
220,024 KB |
testcase_10 | AC | 61 ms
220,252 KB |
testcase_11 | AC | 603 ms
220,068 KB |
testcase_12 | AC | 598 ms
219,988 KB |
testcase_13 | AC | 662 ms
220,032 KB |
testcase_14 | AC | 735 ms
220,260 KB |
testcase_15 | AC | 739 ms
220,192 KB |
testcase_16 | AC | 701 ms
220,324 KB |
testcase_17 | AC | 667 ms
220,316 KB |
testcase_18 | AC | 534 ms
220,032 KB |
testcase_19 | AC | 133 ms
220,316 KB |
testcase_20 | AC | 88 ms
220,064 KB |
testcase_21 | AC | 61 ms
220,060 KB |
testcase_22 | AC | 63 ms
220,192 KB |
testcase_23 | AC | 62 ms
220,312 KB |
testcase_24 | AC | 59 ms
220,188 KB |
testcase_25 | AC | 642 ms
220,032 KB |
testcase_26 | AC | 621 ms
220,140 KB |
testcase_27 | AC | 679 ms
220,100 KB |
testcase_28 | AC | 689 ms
220,192 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N,K,A[303]; ll dp[303][303][303]; ll ret[303]; void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>K; FOR(i,N) { cin>>A[i]; ret[i]=-1LL<<60; } FOR(x,302) FOR(y,302) FOR(i,302) dp[x][y][i]=-1LL<<60; FOR(x,N-1) { dp[x][x+1][K-1]=A[x]*(K-1)+A[x+1]*K; dp[x+1][x][K-1]=A[x+1]*(K-1)+A[x]*K; } for(i=K-1;i>=0;i--) { for(x=0;x<N;x++) for(y=x+1;y<N;y++) { // stay if(i>=2) { dp[x][y][i-2]=max(dp[x][y][i-2],dp[x][y][i]); dp[y][x][i-2]=max(dp[y][x][i-2],dp[y][x][i]); } //left if(x&&i) dp[x-1][y][i-1]=max(dp[x-1][y][i-1],dp[x][y][i]+A[x-1]*(i-1)); //right if(y+1<N&&i) dp[y+1][x][i-1]=max(dp[y+1][x][i-1],dp[y][x][i]+A[y+1]*(i-1)); // go to the other side if(i>=y-x) { dp[x][y][i-(y-x)]=max(dp[x][y][i-(y-x)],dp[y][x][i]); dp[y][x][i-(y-x)]=max(dp[y][x][i-(y-x)],dp[x][y][i]); } else { ret[y-i]=max(ret[y-i],dp[y][x][i]); ret[x+i]=max(ret[x+i],dp[x][y][i]); } } } FOR(i,N) cout<<ret[i]<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }