Submission #977316

# Submission time Handle Problem Language Result Execution time Memory
977316 2024-05-07T18:06:26 Z alexdd Zalmoxis (BOI18_zalmoxis) C++17
30 / 100
296 ms 72552 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k,cnt;
set<pair<int,int>> rez;
vector<int> pozs[31];
int a[2000005],inita[2000005];
int nxt[2000005][2],prec[2000005][2];
void baga_dupa(int p, int x, int c)
{
    int pnxt = nxt[p][c];
    nxt[p][c] = x;
    nxt[x][c] = pnxt;

    prec[x][c] = p;
    prec[pnxt][c] = x;
}
void scoate(int p, int c)
{
    nxt[prec[p][c]][c] = nxt[p][c];
    prec[nxt[p][c]][c] = prec[p][c];
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        inita[i]=a[i];
        prec[i][0]=prec[i][1]=i-1;
        nxt[i][0]=nxt[i][1]=i+1;
        pozs[a[i]].push_back(i);
    }
    nxt[n][0]=nxt[n][1]=0;
    for(int i=0;i<30;i++)
    {
        sort(pozs[i].begin(),pozs[i].end());
        for(int j=(int)pozs[i].size()-1;j>=0;j--)
        {
            if(j>0 && nxt[pozs[i][j-1]][0] == pozs[i][j])
            {
                //cout<<i<<" zzz\n";
                pozs[i+1].push_back(pozs[i][j]);

                a[pozs[i][j]]++;
                scoate(pozs[i][j-1],0);
                j--;
            }
            else
            {
                pozs[i+1].push_back(pozs[i][j]);

                k--;
                n++;
                a[n]=inita[n]=i;
                baga_dupa(pozs[i][j],n,1);
                a[pozs[i][j]]++;
            }
        }
        /*cout<<i<<"    ";
        int cur=1;
        while(cur!=0)
        {
            cout<<a[cur]<<" ";
            cur = nxt[cur][0];
        }
        cout<<"\n";*/
    }
    if(k==1)
    {
        n++;
        a[n] = 29;
        baga_dupa(pozs[30].back(),n,1);
    }
    int cur=1;
    for(int i=1;i<=n;i++)
    {
        cout<<inita[cur]<<" ";
        cur = nxt[cur][1];
    }
    return 0;
}
/**
5 1
29 27 25 25 28
*/
# Verdict Execution time Memory Grader output
1 Correct 252 ms 70480 KB Output is correct
2 Correct 296 ms 70780 KB Output is correct
3 Correct 259 ms 70592 KB Output is correct
4 Correct 264 ms 70724 KB Output is correct
5 Correct 254 ms 70864 KB Output is correct
6 Correct 251 ms 71216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 264 ms 70120 KB Unexpected end of file - int32 expected
2 Incorrect 250 ms 71604 KB not a zalsequence
3 Incorrect 258 ms 70172 KB Unexpected end of file - int32 expected
4 Incorrect 259 ms 70740 KB Unexpected end of file - int32 expected
5 Incorrect 257 ms 71660 KB Unexpected end of file - int32 expected
6 Incorrect 260 ms 72552 KB Unexpected end of file - int32 expected
7 Incorrect 267 ms 70996 KB Unexpected end of file - int32 expected
8 Incorrect 263 ms 70928 KB Unexpected end of file - int32 expected
9 Incorrect 218 ms 66068 KB Unexpected end of file - int32 expected
10 Incorrect 85 ms 34224 KB Unexpected end of file - int32 expected
11 Incorrect 151 ms 46228 KB Unexpected end of file - int32 expected
12 Incorrect 1 ms 6492 KB Unexpected end of file - int32 expected
13 Incorrect 1 ms 6492 KB Unexpected end of file - int32 expected
14 Incorrect 1 ms 6488 KB Unexpected end of file - int32 expected