結果
| 問題 | No.324 落ちてた閉路グラフ |
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-12-17 11:03:35 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,456 bytes |
| 記録 | |
| コンパイル時間 | 550 ms |
| コンパイル使用メモリ | 72,652 KB |
| 最終ジャッジ日時 | 2024-11-14 19:31:13 |
| 合計ジャッジ時間 | 936 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:32: error: ‘accumulate’ was not declared in this scope
29 | printf("%d\n", accumulate(w.begin(), w.end(), 0));
| ^~~~~~~~~~
main.cpp: In function ‘std::istream& operator>>(std::istream&, std::vector<int>&)’:
main.cpp:13:79: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | istream& operator >> (istream& is, vector<int>& vec){ for(int& val: vec) scanf("%d", &val); return is;}
| ~~~~~^~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:19:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | scanf("%d%d", &n,&m);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:22:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
22 | for(int& x:w) scanf("%d", &x);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
istream& operator >> (istream& is, vector<int>& vec){ for(int& val: vec) scanf("%d", &val); return is;}
template<class T> istream& operator >> (istream& is, vector<T>& vec){ for(T& val: vec) is >> val; return is;}
int main(){
int n,m;
//cin >> n >> m;
scanf("%d%d", &n,&m);
vector<int> w(n);
//cin >> w;
for(int& x:w) scanf("%d", &x);
if(m<=1){
cout << 0 << endl;
return 0;
}
if(n==m){
printf("%d\n", accumulate(w.begin(), w.end(), 0));
return 0;
}
const int inf = 100000000;
vector<vector<vector<int>>> dp (2,vector<vector<int>>(2,vector<int>(m+1, -inf)));
vector<vector<vector<int>>> dp_(2,vector<vector<int>>(2,vector<int>(m+1, -inf)));
dp[0][0][0] = 0;
dp[1][1][1] = 0;
for(int i=1; i<n; i++){
for(int start=0; start<2; ++start)
for(int last=0; last<2; ++last)
for(int k=max(0,m-(n-i)); k<=min(i,m); ++k){
if(dp[start][last][k] <= -inf) continue;
dp_[start][0][k] = max(dp_[start][0][k], dp[start][last][k]);
if(k+1<=m){
dp_[start][1][k+1] = max(dp_[start][1][k+1], dp[start][last][k]+(last?w[i-1]:0) );
}
dp[start][last][k] = -inf;
}
swap(dp, dp_);
}
int ans = max({dp[0][0][m], dp[0][1][m], dp[1][0][m], dp[1][1][m]+w[n-1]});
printf("%d\n", ans);
//cout << ans << endl;
return 0;
}
koyumeishi