Submission #644524

# Submission time Handle Problem Language Result Execution time Memory
644524 2022-09-24T20:10:35 Z Kripton Zalmoxis (BOI18_zalmoxis) C++14
35 / 100
137 ms 68144 KB
#include <bits/stdc++.h>
using namespace std;
int steve[1000001],vf;
int steve1[1000001],vf1;
int v[1000001],v1[1000001];
vector <int> addie[1000001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k,i,j;
    cin>>n>>k;
    v[0]=-1;
    int rez=0;
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
        rez+=(1<<v[i]);
        v1[i]=v[i];
        while(v[i]==v[steve[vf]])
        {
            v[i]++;
            vf--;
        }
        steve[++vf]=i;
    }
    for(j=1;j<=40&&v[steve[vf]]!=30;j++)
    {
        int min1=40;
        for(i=1;i<=vf;i++)
            min1=min(min1,v[steve[i]]);
        vf1=0;
        for(i=1;i<=vf;i++)
        {
            if(v[steve[i]]==min1)
            {
                k--;
                v[steve[i]]++;
                addie[steve[i]].push_back(min1);
                rez+=(1<<min1);
            }
            while(v[steve[i]]==v[steve1[vf1]])
            {
                v[steve[i]]++;
                vf1--;
            }
            steve1[++vf1]=steve[i];
        }
        vf=vf1;
        for(i=1;i<=vf;i++)
            steve[i]=steve1[vf1];
    }
    assert(rez==(1<<30));
    for(i=1;i<=n;i++)
    {
        cout<<v1[i]<<" ";
        rez+=(1<<v1[i]);
        for(auto it:addie[i])
        {
            if(k>=((1<<it)-1))
            {
                k-=((1<<it)-1);
                for(j=1;j<=(1<<it);j++)
                    cout<<"0 ";
                rez+=(1<<it);
                continue;
            }
            else if(k)
            {
                int a=(int)log2(k)+1;
                int newit=it-a;
                //daca fac (1<<a) newit-uri, k-=((1<<a)-1)
                k=((1<<a)-1)-k;
                for(j=1;j<=(1<<a)-2*k;j++)
                    cout<<newit<<" ";
                rez+=(1<<newit)*((1<<a)-2*k);
                for(j=1;j<=k;j++)
                    cout<<newit+1<<" ";
                rez+=(1<<(newit+1))*k;
                k=0;
            }
            else
            {
                cout<<it<<" ";
                rez+=(1<<it);
            }
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 135 ms 35660 KB Output is correct
2 Correct 137 ms 35752 KB Output is correct
3 Correct 137 ms 35788 KB Output is correct
4 Correct 136 ms 35828 KB Output is correct
5 Correct 137 ms 35764 KB Output is correct
6 Correct 136 ms 35716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 98 ms 66008 KB Execution killed with signal 6
2 Runtime error 106 ms 66304 KB Execution killed with signal 6
3 Runtime error 97 ms 66316 KB Execution killed with signal 6
4 Runtime error 98 ms 66000 KB Execution killed with signal 6
5 Runtime error 103 ms 66048 KB Execution killed with signal 6
6 Runtime error 98 ms 66016 KB Execution killed with signal 6
7 Runtime error 96 ms 66028 KB Execution killed with signal 6
8 Runtime error 97 ms 66044 KB Execution killed with signal 6
9 Runtime error 90 ms 68144 KB Execution killed with signal 6
10 Runtime error 52 ms 57168 KB Execution killed with signal 6
11 Runtime error 70 ms 62412 KB Execution killed with signal 6
12 Runtime error 36 ms 48072 KB Execution killed with signal 6
13 Runtime error 31 ms 48072 KB Execution killed with signal 6
14 Correct 53 ms 25744 KB Output is correct