Submission #74427

# Submission time Handle Problem Language Result Execution time Memory
74427 2018-09-01T09:29:23 Z vex Zalmoxis (BOI18_zalmoxis) C++14
40 / 100
174 ms 11564 KB
#include <bits/stdc++.h>
#define maxn 1000005
using namespace std;

int n,k;
int a[maxn];
vector<int>sol;
stack<int>s;
bool bio[maxn]={true};

void solve()
{
    s.push(a[0]);
    sol.push_back(a[0]);

    for(int i=1;i<n;i++)
    {
        while(!s.empty() && s.top()<a[i])
        {
            sol.push_back(s.top());
            bio[sol.size()-1]=false;

            int tt=s.top()+1;s.pop();
            while(!s.empty() && s.top()==tt)
            {
                s.pop();
                tt++;
            }
            s.push(tt);
        }

        if(s.empty())
        {
            sol.push_back(a[i]);
            s.push(a[i]);
        }
        else if(s.top()==a[i])
        {
            sol.push_back(a[i]);
            s.pop();

            int tt=a[i]+1;
            while(!s.empty() && s.top()==tt)
            {
                s.pop();
                tt++;
            }
            s.push(tt);
        }
        else{
            s.push(a[i]);
            sol.push_back(a[i]);
        }
    }

    while(s.top()!=30)
    {
        sol.push_back(s.top());
        int tt=s.top()+1;
        s.pop();

        while(!s.empty() && s.top()==tt)
        {
            s.pop();
            tt++;
        }
        s.push(tt);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];

    solve();
    //for(auto x:sol)cout<<x<<" ";

    int sz=sol.size();
    k-=(sz-n);
    int mmm=30;
    for(int i=0;i<sz;i++)
    {
        if(!bio[i] || k==0)cout<<sol[i]<<" ";
        else if((1<<sol[i])-1 >=k)
        {
            while((1<<mmm) > k)mmm--;
            int ost=k-(1<<mmm)+1;
            for(int j=0;j<2*ost;j++)cout<<sol[i]-mmm-1<<" ";
            for(int j=2*ost;j<=k;j++)cout<<sol[i]-mmm<<" ";
            k=0;
        }
        else
        {
            for(int j=0;j<(1<<sol[i]);j++)cout<<"0 ";
            k-=(1<<sol[i]);
            k++;
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 172 ms 10464 KB Output is correct
2 Correct 168 ms 10612 KB Output is correct
3 Correct 168 ms 10612 KB Output is correct
4 Correct 173 ms 10612 KB Output is correct
5 Correct 172 ms 10612 KB Output is correct
6 Correct 168 ms 10612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 166 ms 10612 KB doesn't contain S as a subsequence
2 Correct 166 ms 11560 KB Output is correct
3 Incorrect 166 ms 11564 KB doesn't contain S as a subsequence
4 Correct 169 ms 11564 KB Output is correct
5 Incorrect 168 ms 11564 KB doesn't contain S as a subsequence
6 Incorrect 174 ms 11564 KB doesn't contain S as a subsequence
7 Incorrect 167 ms 11564 KB doesn't contain S as a subsequence
8 Incorrect 168 ms 11564 KB doesn't contain S as a subsequence
9 Incorrect 148 ms 11564 KB Unexpected end of file - int32 expected
10 Incorrect 66 ms 11564 KB Unexpected end of file - int32 expected
11 Incorrect 105 ms 11564 KB Unexpected end of file - int32 expected
12 Incorrect 2 ms 11564 KB Unexpected end of file - int32 expected
13 Incorrect 2 ms 11564 KB Unexpected end of file - int32 expected
14 Incorrect 3 ms 11564 KB Unexpected end of file - int32 expected