結果
問題 | No.324 落ちてた閉路グラフ |
ユーザー | imulan |
提出日時 | 2016-09-21 03:26:43 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,191 bytes |
コンパイル時間 | 1,576 ms |
コンパイル使用メモリ | 166,488 KB |
実行使用メモリ | 149,888 KB |
最終ジャッジ日時 | 2024-04-28 16:40:53 |
合計ジャッジ時間 | 8,748 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 93 ms
144,256 KB |
testcase_01 | AC | 94 ms
144,384 KB |
testcase_02 | AC | 93 ms
144,452 KB |
testcase_03 | AC | 93 ms
144,384 KB |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
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 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr) #define all(x) (x).begin(),(x).end() #define pb push_back #define fi first #define se second const int INF=12345678; const int N=3000; int n,m; int w[N]; int dp[3001][3001][2][2]; int dfs(int now, int used, int before, int one) { if(dp[now][used][before][one] > -INF) return dp[now][used][before][one]; if(now==n) { if(used==m) return 0; return -INF; } int ret=-INF; // nowを選ぶ if(used<m) { int add=0; if(before) add+=w[now-1]; if(now==n-1 && one) add+=w[n-1]; ret=max(ret,dfs(now+1,used+1,1,one)+add); } // nowを選ばない ret=max(ret,dfs(now+1,used,0,one)); return dp[now][used][before][one] = max(-INF,ret); } int main() { scanf(" %d %d", &n, &m); rep(i,n) scanf(" %d", &w[i]); if(m==0) printf("0\n"); else { rep(i,3001)rep(j,3001)rep(k,2)rep(l,2) dp[i][j][k][l]=-INF; printf("%d\n", max(dfs(1,0,0,0),dfs(1,1,1,1))); } return 0; }