제출 #520952

#제출 시각아이디문제언어결과실행 시간메모리
520952LucaIlieTreasure (info1cup19_treasure)C++17
100 / 100
17 ms668 KiB
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

struct aaa {
    char val;
    int rep;
};

stack <aaa> s;
vector <char> v;

int main() {
    char a;
    int n, k, i;

    cin >> n >> k;

    for ( i = 0; i < n; i++ ) {
        cin >> a;

        if ( !s.empty() && s.top().val == a ) {
            s.top().rep++;
            if ( s.top().rep == k )
                s.pop();
        } else
            s.push( { a, 1 } );
    }

    while ( !s.empty() ) {
        for ( i = 0; i < s.top().rep; i++ )
            v.push_back( s.top().val );
        s.pop();
    }

    for ( i = v.size() - 1; i >= 0; i-- )
        cout << v[i];

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...