提出 #7576844


ソースコード 拡げる

#include <bits/stdc++.h>

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

string f(string s) {
  string res;
  res += s[0];
  for (int i=1; i<s.size(); i++) {
    if (res[res.size()-1] != s[i]) {
      res.push_back(s[i]);
    }
  }
  return res;
}

signed main() {
  ll N, K;
  string s;
  cin >> N >> K >> s;
  s = f(s);
  rep(i, K) {
    if (s.size() == 1) {
      continue;
    } else if (s.size() >= 3){
      auto it = s.begin();
      s.erase(it);
      it = s.begin();
      s.erase(it);
    } else {
      // s.size() == 2
      auto it = s.begin();
      s.erase(it);
    }
  }
  cout << N - s.size() << endl;
  return 0;
}

提出情報

提出日時
問題 D - Face Produces Unhappiness
ユーザ bobuhiro11
言語 C++14 (GCC 5.4.1)
得点 400
コード長 825 Byte
結果 AC
実行時間 170 ms
メモリ 640 KiB

ジャッジ結果

セット名 All Sample
得点 / 配点 400 / 400 0 / 0
結果
AC × 24
AC × 3
セット名 テストケース
All sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, 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
Sample sample_01, sample_02, sample_03
ケース名 結果 実行時間 メモリ
sample_01 AC 1 ms 256 KiB
sample_02 AC 1 ms 256 KiB
sample_03 AC 1 ms 256 KiB
testcase_01 AC 14 ms 384 KiB
testcase_02 AC 42 ms 640 KiB
testcase_03 AC 38 ms 512 KiB
testcase_04 AC 41 ms 512 KiB
testcase_05 AC 2 ms 256 KiB
testcase_06 AC 12 ms 512 KiB
testcase_07 AC 2 ms 256 KiB
testcase_08 AC 42 ms 640 KiB
testcase_09 AC 20 ms 512 KiB
testcase_10 AC 42 ms 640 KiB
testcase_11 AC 42 ms 512 KiB
testcase_12 AC 2 ms 256 KiB
testcase_13 AC 28 ms 640 KiB
testcase_14 AC 170 ms 640 KiB
testcase_15 AC 157 ms 640 KiB
testcase_16 AC 170 ms 640 KiB
testcase_17 AC 50 ms 640 KiB
testcase_18 AC 5 ms 512 KiB
testcase_19 AC 5 ms 512 KiB
testcase_20 AC 1 ms 256 KiB
testcase_21 AC 5 ms 512 KiB