結果
| 問題 | No.324 落ちてた閉路グラフ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-02-29 11:52:06 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,127 bytes |
| 記録 | |
| コンパイル時間 | 656 ms |
| コンパイル使用メモリ | 68,532 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-24 12:43:41 |
| 合計ジャッジ時間 | 5,841 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 RE * 5 |
ソースコード
#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
template <class T> bool setmax(T & l, T const & r) { if (not (l < r)) return false; l = r; return true; }
using namespace std;
const int INF = 1e9;
int main() {
int n, m; cin >> n >> m;
vector<int> w(n); repeat (i,n) cin >> w[i];
int ans = - INF;
repeat (p,2) {
vector<vector<int> > prv;
vector<vector<int> > cur(m+1, vector<int>(2, - INF));
auto fly = [&]() { cur.swap(prv); cur.clear(); cur.resize(m+1, vector<int>(2, - INF)); };
cur[p][p] = 0;
repeat (i,n-1) {
fly();
repeat (j,m+1) {
;;;;;;;;;;; cur[j][false] = max(prv[j ][false], prv[j ][true]);
if (j >= 1) cur[j][ true] = max(prv[j-1][false], prv[j-1][true] + w[i]);
}
}
fly();
repeat (j,m+1) {
cur[j][false] = max(prv[j][false], prv[j][true]);
cur[j][ true] = max(prv[j][false], prv[j][true] + (p ? w[n-1] : 0));
}
setmax(ans, cur[m][p]);
}
cout << ans << endl;
return 0;
}