結果
| 問題 | No.324 落ちてた閉路グラフ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-12-17 00:38:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,685 bytes |
| 記録 | |
| コンパイル時間 | 2,417 ms |
| コンパイル使用メモリ | 182,508 KB |
| 実行使用メモリ | 818,208 KB |
| 最終ジャッジ日時 | 2024-09-16 06:39:13 |
| 合計ジャッジ時間 | 4,728 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | MLE * 1 -- * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'
int n, m;
int w[3005];
int main(void) {
cin >> n >> m;
rep(i, n) cin >> w[i];
int rem = n;
int ans = -1e8, cur = 0;
rep(i, n) cur += w[i];
queue<pair<int, vector<bool>>> que;
que.push(make_pair(cur, vector<bool>(n, false)));
while (rem-- > m) {
queue<pair<int, vector<bool>>> nque;
while (que.size()) {
auto ele = que.front(); que.pop();
int cur = ele.first;
auto removed = ele.second;
vector<int> pos;
int decrease = 1e8;
rep(i, n) {
if (removed[i]) continue;
int l = (i - 1 + n) % n, r = (i + 1) % n;
int tmp = 0;
if (!removed[l]) tmp += w[l];
if (!removed[r]) tmp += w[i];
if (tmp < decrease) {
pos.clear();
pos.push_back(i);
decrease = tmp;
}
else if (tmp == decrease) {
pos.push_back(i);
}
}
ans = max(ans, cur - decrease);
for (auto i: pos) {
auto nremoved = removed;
nremoved[i] = true;
nque.push(make_pair(cur - decrease, nremoved));
}
}
queue<pair<int, vector<bool>>> nnque;
while (nque.size()) {
auto ele = nque.front(); nque.pop();
if (ele.first < ans) continue;
nnque.push(ele);
}
que = nnque;
}
cout << ans << endl;
return 0;
}