답안 #160313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
160313 2019-10-27T01:32:47 Z model_code Treasure (info1cup19_treasure) C++17
100 / 100
7 ms 684 KB
#include <bits/stdc++.h>

using namespace std;
stack < pair < char, int > > a;
int n,k,i,nr;
char s[200004],b[200004];
int main()
{
    scanf ("%d %d", &n, &k);
    assert ((1<=n) && (n<=200000));
    assert ((1<=k) && (k<=200000));
    scanf ("%s", &s);
    for (i=0;i<=(n-1);i++)
        assert (('a'<=s[i]) && (s[i]<='z'));
    for (i=0;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++)
        printf ("%c", b[i]);
    printf ("\n");
    return 0;
}

Compilation message

treasure.cpp: In function 'int main()':
treasure.cpp:12:20: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[200004]' [-Wformat=]
     scanf ("%s", &s);
                  ~~^
treasure.cpp:9:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d %d", &n, &k);
     ~~~~~~^~~~~~~~~~~~~~~~~
treasure.cpp:12:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%s", &s);
     ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 5 ms 632 KB Output is correct
25 Correct 4 ms 508 KB Output is correct
26 Correct 7 ms 632 KB Output is correct
27 Correct 6 ms 632 KB Output is correct
28 Correct 6 ms 632 KB Output is correct
29 Correct 6 ms 636 KB Output is correct
30 Correct 6 ms 684 KB Output is correct
31 Correct 5 ms 636 KB Output is correct
32 Correct 5 ms 632 KB Output is correct
33 Correct 5 ms 632 KB Output is correct
34 Correct 5 ms 632 KB Output is correct
35 Correct 5 ms 632 KB Output is correct