結果

問題 No.324 落ちてた閉路グラフ
ユーザー roiti46roiti46
提出日時 2015-12-17 00:38:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,685 bytes
コンパイル時間 1,747 ms
コンパイル使用メモリ 170,784 KB
実行使用メモリ 814,752 KB
最終ジャッジ日時 2023-10-14 11:49:44
合計ジャッジ時間 4,617 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 MLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0