Submission #83504

# Submission time Handle Problem Language Result Execution time Memory
83504 2018-11-08T14:10:27 Z nikolapesic2802 Take-out (POI13_usu) C++14
100 / 100
270 ms 39768 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back

/*
     - Find some c with k b's around add it to the answer and "delete" the c and b's.
*/
int main()
{
    int n,k;
    scanf("%i %i",&n,&k);
    char s[n];
    scanf("%s",s);
    vector<vector<int> > sol;
    vector<int> space;
    space.pb(0);
    int c=0;
    vector<int> index;
    for(int i=0;i<n;i++)
    {
        index.pb(i);
        if(s[i]=='c')
        {
            c++;
            space.pb(0);
        }
        else
        {
            space[c]++;
        }
        if(c&&space[c]+space[c-1]>=k)
        {
            vector<int> tr;
            for(int i=0;i<k+1;i++)
            {
                tr.pb(index.back());
                index.pop_back();
            }
            reverse(tr.begin(),tr.end());
            sol.pb(tr);
            int dif=space[c--];
            space.pop_back();
            space[c]-=k-dif;
        }
    }
    reverse(sol.begin(),sol.end());
    for(auto p:sol)
    {
        for(auto d:p)
        {
            printf("%i ",d+1);
        }
        printf("\n");
    }
    return 0;
}

Compilation message

usu.cpp: In function 'int main()':
usu.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %i",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~
usu.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",s);
     ~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 680 KB Output is correct
2 Correct 2 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 680 KB Output is correct
2 Correct 2 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 680 KB Output is correct
2 Correct 4 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2800 KB Output is correct
2 Correct 17 ms 2800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 4020 KB Output is correct
2 Correct 36 ms 4784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 8040 KB Output is correct
2 Correct 38 ms 8040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 11168 KB Output is correct
2 Correct 93 ms 12604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 270 ms 39768 KB Output is correct
2 Correct 123 ms 39768 KB Output is correct
3 Correct 119 ms 39768 KB Output is correct
4 Correct 139 ms 39768 KB Output is correct