Submission #689530

# Submission time Handle Problem Language Result Execution time Memory
689530 2023-01-28T17:19:12 Z tvladm2009 Treasure (info1cup19_treasure) C++17
100 / 100
4 ms 1256 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n, k;
  string s;
  cin >> n >> k >> s;
  stack<pair<int, int>> st;
  for (int i = 1; i <= n; i++) {
    if (!st.empty()) {
      if (st.top().first == s[i - 1]) {
        st.push({s[i - 1], st.top().second + 1});
      } else {
        st.push({s[i - 1], 1});
      }
    } else {
      st.push({s[i - 1], 1});
    }
    if (st.top().second == k) {
      int cnt = 0;
      while (cnt < k) {
        st.pop();
        cnt++;
      }
    }
  }
  string ret = "";
  while (!st.empty()) {
    ret += st.top().first;
    st.pop();
  }
  reverse(ret.begin(), ret.end());
  cout << ret;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 456 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 3 ms 864 KB Output is correct
25 Correct 3 ms 824 KB Output is correct
26 Correct 4 ms 1256 KB Output is correct
27 Correct 4 ms 1220 KB Output is correct
28 Correct 4 ms 984 KB Output is correct
29 Correct 4 ms 1120 KB Output is correct
30 Correct 4 ms 832 KB Output is correct
31 Correct 3 ms 836 KB Output is correct
32 Correct 4 ms 860 KB Output is correct
33 Correct 3 ms 852 KB Output is correct
34 Correct 4 ms 852 KB Output is correct
35 Correct 3 ms 868 KB Output is correct