답안 #74428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74428 2018-09-01T09:34:52 Z vex Zalmoxis (BOI18_zalmoxis) C++14
45 / 100
211 ms 11548 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.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());
        bio[sol.size()-1]=false;
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 10340 KB Output is correct
2 Correct 183 ms 10496 KB Output is correct
3 Correct 182 ms 10496 KB Output is correct
4 Correct 171 ms 10496 KB Output is correct
5 Correct 168 ms 10560 KB Output is correct
6 Correct 172 ms 10560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 173 ms 10560 KB doesn't contain S as a subsequence
2 Correct 173 ms 11548 KB Output is correct
3 Incorrect 211 ms 11548 KB doesn't contain S as a subsequence
4 Correct 182 ms 11548 KB Output is correct
5 Incorrect 179 ms 11548 KB doesn't contain S as a subsequence
6 Incorrect 166 ms 11548 KB doesn't contain S as a subsequence
7 Incorrect 176 ms 11548 KB doesn't contain S as a subsequence
8 Incorrect 169 ms 11548 KB doesn't contain S as a subsequence
9 Incorrect 145 ms 11548 KB doesn't contain S as a subsequence
10 Incorrect 84 ms 11548 KB doesn't contain S as a subsequence
11 Incorrect 118 ms 11548 KB doesn't contain S as a subsequence
12 Incorrect 54 ms 11548 KB doesn't contain S as a subsequence
13 Incorrect 54 ms 11548 KB doesn't contain S as a subsequence
14 Correct 53 ms 11548 KB Output is correct