#include <bits/stdc++.h>
#define int long long
#define float double
#define pb push_back
#define F first
#define S second
#define T int t; cin >> t; while(t--)
#define IOS ios::sync_with_stdio(); cin.tie(0); cout.tie(0);
using namespace std;
const int inf = 8e18;
const int N = 1e6 + 6;
const int M = 1e3 + 3;
const int mod = 1e9 + 7;
const float pi = atan(1) * 4;
int a[N];
int n, m;
string s;
vector<pair<char, int>> v;
main()
{
cin >> n >> m >> s;
v.pb({s[0], 1});
for(int i = 1; i < n; i++)
{
if (s[i] == v.back().F)
{
v.back().S++;
if (v.back().S == m)
v.pop_back();
}
else
v.pb({s[i], 1});
}
for(auto x: v)
{
for(int i = 0; i < x.S; i++)
cout << x.F;
}
}
Compilation message
treasure.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
22 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
368 KB |
Output is correct |
18 |
Correct |
3 ms |
460 KB |
Output is correct |
19 |
Correct |
3 ms |
536 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
21 |
Correct |
3 ms |
536 KB |
Output is correct |
22 |
Correct |
4 ms |
692 KB |
Output is correct |
23 |
Correct |
3 ms |
572 KB |
Output is correct |
24 |
Correct |
5 ms |
832 KB |
Output is correct |
25 |
Correct |
4 ms |
820 KB |
Output is correct |
26 |
Correct |
7 ms |
860 KB |
Output is correct |
27 |
Correct |
7 ms |
860 KB |
Output is correct |
28 |
Correct |
7 ms |
964 KB |
Output is correct |
29 |
Correct |
9 ms |
888 KB |
Output is correct |
30 |
Correct |
7 ms |
968 KB |
Output is correct |
31 |
Correct |
7 ms |
1084 KB |
Output is correct |
32 |
Correct |
6 ms |
1000 KB |
Output is correct |
33 |
Correct |
9 ms |
988 KB |
Output is correct |
34 |
Correct |
7 ms |
844 KB |
Output is correct |
35 |
Correct |
6 ms |
852 KB |
Output is correct |