This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define MAX 200002
using namespace std;
int n,vf,k;
pair<char, int> st[MAX];
char ch;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> ch;
pair<char, int> add = {ch, 1};
while(vf >= 1 && st[vf].first == add.first){
add.second += st[vf].second;
vf--;
}
st[++vf] = add;
if(st[vf].second >= k){
if(st[vf].second%k == 0){
vf--;
}else{
st[vf].second %= k;
}
}
}
for(int i = 1; i <= vf; i++){
for(int j = 1; j <= st[i].second; j++){
cout << st[i].first;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |