結果

問題 No.2553 Holidays
ユーザー 👑 emthrmemthrm
提出日時 2023-11-25 14:16:31
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 3,425 bytes
コンパイル時間 3,588 ms
コンパイル使用メモリ 268,520 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-25 14:16:37
合計ジャッジ時間 5,227 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 4 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 4 ms
6,676 KB
testcase_11 AC 4 ms
6,676 KB
testcase_12 AC 8 ms
6,676 KB
testcase_13 AC 4 ms
6,676 KB
testcase_14 AC 4 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 3 ms
6,676 KB
testcase_21 AC 3 ms
6,676 KB
testcase_22 AC 3 ms
6,676 KB
testcase_23 AC 3 ms
6,676 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 3 ms
6,676 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 3 ms
6,676 KB
testcase_29 AC 3 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 1 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 1 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 2 ms
6,676 KB
testcase_43 AC 2 ms
6,676 KB
testcase_44 AC 2 ms
6,676 KB
testcase_45 AC 2 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 AC 2 ms
6,676 KB
testcase_51 AC 2 ms
6,676 KB
testcase_52 AC 2 ms
6,676 KB
testcase_53 AC 1 ms
6,676 KB
testcase_54 AC 2 ms
6,676 KB
testcase_55 AC 2 ms
6,676 KB
testcase_56 AC 2 ms
6,676 KB
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; string s; cin >> n >> m >> s;

  // int answer = 0;
  // m = min<int>(n - ranges::count(s, 'x'), m);
  // for (int subset = (1 << m) - 1; subset < (1 << n);) {
  //   bool is_valid = true;
  //   REP(i, n) is_valid &= !(subset >> i & 1) || s[i] != 'x';
  //   if (is_valid) {
  //     string t = s;
  //     REP(i, n) {
  //       if (subset >> i & 1) t[i] = 'o';
  //     }
  //     FOR(i, 2, n) {
  //       if (t[i - 2] == 'o' && t[i] == 'o' && t[i - 1] != 'x') t[i - 1] = 'o';
  //     }
  //     chmax(answer, ranges::count(t, 'o'));
  //   }
  //   const int tmp1 = subset & -subset, tmp2 = subset + tmp1;
  //   subset = (((subset & ~tmp2) / tmp1) >> 1) | tmp2;
  // }

  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());
      t.clear();
      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' && t.back() == '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();
  };
  REP(i, n) {
    if (s[i] == 'x') {
      process();
    } else {
      t += s[i];
    }
  }
  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';
  // assert(ans == answer);
  return 0;
}
0