結果

問題 No.324 落ちてた閉路グラフ
ユーザー roiti46roiti46
提出日時 2015-12-17 00:10:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 940 bytes
コンパイル時間 2,888 ms
コンパイル使用メモリ 143,596 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-10-14 11:39:03
合計ジャッジ時間 2,799 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 34 ms
4,348 KB
testcase_05 AC 3 ms
4,372 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 37 ms
4,352 KB
testcase_09 AC 40 ms
4,348 KB
testcase_10 AC 37 ms
4,348 KB
testcase_11 AC 45 ms
4,348 KB
testcase_12 AC 50 ms
4,352 KB
testcase_13 AC 18 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 1 ms
4,368 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 1 ms
4,356 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,356 KB
testcase_25 WA -
testcase_26 AC 2 ms
4,348 KB
testcase_27 WA -
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 1 ms
4,352 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
bool removed[3005];

int main(void) {
  cin >> n >> m;
  rep(i, n) cin >> w[i];
  int ans = 0, rem = n;
  rep(i, n) ans += w[i];

  while (rem-- > m) {
    int pos = -1, 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 = i;
        decrease = tmp;
      }
    }
    removed[pos] = true;
    ans -= decrease;
  }
  cout << ans << endl;

  return 0;
}
0