답안 #977332

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977332 2024-05-07T18:28:42 Z alexdd Zalmoxis (BOI18_zalmoxis) C++17
30 / 100
295 ms 142940 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];
}
vector<int> aux;
void calc(int x)
{
    if(k==0 || x==0)
    {
        aux.push_back(x);
        return;
    }
    k--;
    calc(x-1);
    calc(x-1);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>k;
    int initn=n;
    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";*/
    }
    assert(n<=2000000);
    int cur=-1;
    for(int i=1;i<=n;i++)
        if(prec[i][1]==0)
            cur=i;
    assert(cur!=-1);
    assert(k==0);
    for(int i=1;i<=n;i++)
    {
        if(cur<=initn) aux.push_back(inita[cur]);
        else calc(inita[cur]);
        cur = nxt[cur][1];
    }
    assert(k==0);
    for(auto x:aux)
        cout<<x<<" ";
    return 0;
}
/**
5 1
29 27 25 25 28

1 5
29
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 286 ms 80316 KB Output is correct
2 Correct 263 ms 80436 KB Output is correct
3 Correct 262 ms 80168 KB Output is correct
4 Correct 267 ms 80236 KB Output is correct
5 Correct 254 ms 80440 KB Output is correct
6 Correct 258 ms 80988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 268 ms 137964 KB Execution killed with signal 6
2 Incorrect 258 ms 81408 KB not a zalsequence
3 Runtime error 260 ms 137828 KB Execution killed with signal 6
4 Runtime error 271 ms 139328 KB Execution killed with signal 6
5 Runtime error 275 ms 140760 KB Execution killed with signal 6
6 Runtime error 259 ms 142940 KB Execution killed with signal 6
7 Runtime error 295 ms 139532 KB Execution killed with signal 6
8 Runtime error 265 ms 139016 KB Execution killed with signal 6
9 Runtime error 222 ms 130028 KB Execution killed with signal 6
10 Runtime error 89 ms 67344 KB Execution killed with signal 6
11 Runtime error 145 ms 91020 KB Execution killed with signal 6
12 Runtime error 8 ms 13048 KB Execution killed with signal 6
13 Runtime error 9 ms 12892 KB Execution killed with signal 6
14 Runtime error 8 ms 13044 KB Execution killed with signal 6