Submission #520952

# Submission time Handle Problem Language Result Execution time Memory
520952 2022-01-31T14:25:40 Z LucaIlie Treasure (info1cup19_treasure) C++17
100 / 100
17 ms 668 KB
#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 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 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 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 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 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 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 3 ms 304 KB Output is correct
18 Correct 3 ms 300 KB Output is correct
19 Correct 5 ms 332 KB Output is correct
20 Correct 4 ms 332 KB Output is correct
21 Correct 6 ms 332 KB Output is correct
22 Correct 8 ms 404 KB Output is correct
23 Correct 7 ms 460 KB Output is correct
24 Correct 10 ms 432 KB Output is correct
25 Correct 11 ms 468 KB Output is correct
26 Correct 14 ms 668 KB Output is correct
27 Correct 15 ms 548 KB Output is correct
28 Correct 13 ms 568 KB Output is correct
29 Correct 17 ms 648 KB Output is correct
30 Correct 13 ms 560 KB Output is correct
31 Correct 13 ms 556 KB Output is correct
32 Correct 14 ms 532 KB Output is correct
33 Correct 14 ms 460 KB Output is correct
34 Correct 14 ms 524 KB Output is correct
35 Correct 13 ms 460 KB Output is correct