Submission #644527

# Submission time Handle Problem Language Result Execution time Memory
644527 2022-09-24T20:20:17 Z Kripton Zalmoxis (BOI18_zalmoxis) C++14
45 / 100
1000 ms 67692 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;
    int rez=0;
    v[0]=-1;
    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;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[i];
    }
    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 134 ms 33672 KB Output is correct
2 Correct 137 ms 33656 KB Output is correct
3 Correct 131 ms 33740 KB Output is correct
4 Correct 132 ms 33748 KB Output is correct
5 Correct 130 ms 33704 KB Output is correct
6 Correct 131 ms 33668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 95 ms 63988 KB Execution killed with signal 6
2 Runtime error 97 ms 64296 KB Execution killed with signal 6
3 Execution timed out 1096 ms 31896 KB Time limit exceeded
4 Runtime error 102 ms 63960 KB Execution killed with signal 6
5 Execution timed out 1097 ms 31512 KB Time limit exceeded
6 Execution timed out 1101 ms 31576 KB Time limit exceeded
7 Runtime error 97 ms 63976 KB Execution killed with signal 6
8 Runtime error 102 ms 64032 KB Execution killed with signal 6
9 Incorrect 169 ms 38636 KB Expected EOF
10 Runtime error 76 ms 61168 KB Execution killed with signal 6
11 Runtime error 103 ms 67692 KB Execution killed with signal 6
12 Correct 51 ms 25760 KB Output is correct
13 Correct 50 ms 25804 KB Output is correct
14 Correct 49 ms 25820 KB Output is correct