Submission #7576844


Source Code Expand

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

Submission Info

Submission Time
Task D - Face Produces Unhappiness
User bobuhiro11
Language C++14 (GCC 5.4.1)
Score 400
Code Size 825 Byte
Status
Exec Time 170 ms
Memory 640 KB

Test Cases

Set Name Score / Max Score Test Cases
All 400 / 400 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 0 / 0 sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 1 ms 256 KB
sample_02 1 ms 256 KB
sample_03 1 ms 256 KB
testcase_01 14 ms 384 KB
testcase_02 42 ms 640 KB
testcase_03 38 ms 512 KB
testcase_04 41 ms 512 KB
testcase_05 2 ms 256 KB
testcase_06 12 ms 512 KB
testcase_07 2 ms 256 KB
testcase_08 42 ms 640 KB
testcase_09 20 ms 512 KB
testcase_10 42 ms 640 KB
testcase_11 42 ms 512 KB
testcase_12 2 ms 256 KB
testcase_13 28 ms 640 KB
testcase_14 170 ms 640 KB
testcase_15 157 ms 640 KB
testcase_16 170 ms 640 KB
testcase_17 50 ms 640 KB
testcase_18 5 ms 512 KB
testcase_19 5 ms 512 KB
testcase_20 1 ms 256 KB
testcase_21 5 ms 512 KB