結果
問題 | No.324 落ちてた閉路グラフ |
ユーザー |
![]() |
提出日時 | 2015-12-17 11:39:25 |
言語 | C++11 (gcc 13.3.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,094 bytes |
コンパイル時間 | 202 ms |
コンパイル使用メモリ | 37,188 KB |
最終ジャッジ日時 | 2024-11-14 19:31:20 |
合計ジャッジ時間 | 569 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:18:32: error: ‘accumulate’ was not declared in this scope 18 | printf("%d\n", accumulate(w.begin(), w.end(), 0)); | ^~~~~~~~~~ main.cpp:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%d%d", &n,&m); | ~~~~~^~~~~~~~~~~~~~~ main.cpp:11:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | for(int& x:w) scanf("%d", &x); | ~~~~~^~~~~~~~~~
ソースコード
#include <vector> #include <cstdio> #include <algorithm> using namespace std; constexpr int inf = 100000000; int main(){ int n,m; scanf("%d%d", &n,&m); vector<int> w(n); for(int& x:w) scanf("%d", &x); if(m<=1){ printf("%d\n", 0); return 0; } if(n==m){ printf("%d\n", accumulate(w.begin(), w.end(), 0)); return 0; } vector<vector<int>> dp(m+2, vector<int>(4, -inf)); vector<vector<int>> dp_(m+2, vector<int>(4, -inf)); dp[0][0] = 0; dp[1][3] = 0; for(int i=1; i<n; ++i){ for(int k=max(0,m-(n-i)); k<=min(i,m); ++k){ dp_[k][0] = max(dp_[k][0], max(dp[k][0], dp[k][1])); dp_[k+1][1] = max(dp_[k+1][1], max(dp[k][0], dp[k][1]+w[i-1])); dp_[k][2] = max(dp_[k][2], max(dp[k][2], dp[k][3])); dp_[k+1][3] = max(dp_[k+1][3], max(dp[k][2], dp[k][3]+w[i-1])); dp[k][0] = dp[k][1] = dp[k][2] = dp[k][3] = -inf; } swap(dp, dp_); } int ans = max(max(dp[m][0], dp[m][1]), max(dp[m][2], dp[m][3]+w[n-1])); printf("%d\n", ans); return 0; }