Submission #229094

#TimeUsernameProblemLanguageResultExecution timeMemory
229094filiptudose7Treasure (info1cup19_treasure)C++11
100 / 100
7 ms1024 KiB
#include <bits/stdc++.h> using namespace std; stack<pair<char,int>>a; int n,k,i,nr; char s[200004],b[200004]; int main() { //freopen("input","r",stdin); cin.sync_with_stdio(false); cin.tie(0); cin>>n>>k; cin>>(s+1); for(i=1; i<=n; ++i) { if(a.empty()) a.push({s[i],1}); else if(s[i]==a.top().first) { a.top().second++; if(a.top().second==k) a.pop(); } else a.push({s[i],1}); } nr=0; while(!a.empty()) { for(i=1; i<=a.top().second; i++) b[++nr]=a.top().first; a.pop(); } reverse(b+1,b+nr+1); for(i=1; i<=nr; i++) cout<<b[i]; cout<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...