結果

問題 No.2553 Holidays
ユーザー 👑 emthrmemthrm
提出日時 2023-11-25 13:56:46
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,717 bytes
コンパイル時間 3,455 ms
コンパイル使用メモリ 268,256 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-25 13:56:53
合計ジャッジ時間 6,769 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 5 ms
6,676 KB
testcase_05 WA -
testcase_06 AC 3 ms
6,676 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 4 ms
6,676 KB
testcase_21 AC 3 ms
6,676 KB
testcase_22 AC 4 ms
6,676 KB
testcase_23 AC 4 ms
6,676 KB
testcase_24 AC 4 ms
6,676 KB
testcase_25 AC 4 ms
6,676 KB
testcase_26 AC 4 ms
6,676 KB
testcase_27 AC 4 ms
6,676 KB
testcase_28 AC 4 ms
6,676 KB
testcase_29 AC 4 ms
6,676 KB
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
testcase_33 AC 1 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 1 ms
6,676 KB
testcase_40 AC 1 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 1 ms
6,676 KB
testcase_46 AC 2 ms
6,676 KB
testcase_47 AC 2 ms
6,676 KB
testcase_48 AC 2 ms
6,676 KB
testcase_49 AC 2 ms
6,676 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, m; cin >> n >> m;
  string t = "";
  vector<int> odd, mid, end, bad;
  int ans = 0;
  const auto process = [&]() -> void {
    if (t.empty()) return;
    if (ranges::count(t, 'o') == 0) {
      bad.emplace_back(t.length());
      return;
    }
    {
      int bck = 0;
      for (; t.back() == '-'; t.pop_back()) {
        ++bck;
      }
      if (bck > 0) end.emplace_back(bck);
    }
    ranges::reverse(t);
    {
      int bck = 0;
      for (; t.back() == '-'; t.pop_back()) {
        ++bck;
      }
      if (bck > 0) end.emplace_back(bck);
    }
    assert(t.front() == 'o');
    for (int i = 0; i + 1 < t.length();) {
      const int j = t.find('o', i + 1);
      if (j - i == 2) {
        ++ans;
      } else {
        ((j - i) % 2 == 0 ? odd : mid).emplace_back(j - i - 1);
      }
      i = j;
    }
    ans += ranges::count(t, 'o');
    t.clear();
  };
  while (n--) {
    char s; cin >> s;
    if (s == 'x') {
      process();
    } else {
      t += s;
    }
  }
  process();
  ranges::sort(odd);
  for (const int len : odd) {
    if (len / 2 <= m) {
      m -= len / 2;
      ans += len;
    } else {
      ans += m * 2;
      m = 0;
    }
  }
  for (const int len : mid) {
    if (len / 2 <= m) {
      m -= len / 2;
      ans += len;
    } else {
      ans += m * 2;
      m = 0;
    }
  }
  for (int len : end) {
    if (len % 2 == 1) {
      bad.emplace_back(1);
      --len;
    }
    if (len / 2 <= m) {
      m -= len / 2;
      ans += len;
    } else {
      ans += m * 2;
      m = 0;
    }
  }
  ranges::sort(bad, greater<int>());
  int rem = 0;
  for (int len : bad) {
    if (m > 0) {
      ++ans;
      --len;
      --m;
      if (len % 2 == 1) {
        ++rem;
        --len;
      }
      const int tmp = min(len / 2, m);
      m -= tmp;
      ans += tmp * 2;
    }
  }
  ans += min(rem, m);
  cout << ans << '\n';
  return 0;
}
0