제출 #209852

#제출 시각아이디문제언어결과실행 시간메모리
209852nicolaalexandraZalmoxis (BOI18_zalmoxis)C++14
35 / 100
349 ms39928 KiB
#include <bits/stdc++.h>
#define DIM 1000010
using namespace std;
int v[DIM];
vector <int> L[DIM];
pair <int,int> sol[DIM];
int n,i,j,poz,k,sol_poz,idx,el;

int solve (int val){

    if (v[idx] == val){ /// am deja valoarea pe care o caut
        idx++;
        return idx;
    }

    if (!val)
        return 0;

    /// stanga

    int poz = solve (val-1);

    if (poz > n || v[poz] > val-1){
        /// sunt obligata sa pun aici val
        L[poz-1].push_back(val-1);
        k--;
        /*sol = val-1;
        sol_poz = poz-1;*/

        return poz;
    }

    /// dreapta
    return solve (val-1);
}

int main (){

   // ifstream cin ("zalmoxis.in");
   // ofstream cout ("zalmoxis.out");

    cin>>n>>k;
    for (i=1;i<=n;i++)
        cin>>v[i];

    idx = 1;
    solve (30);

    for (i=1;i<=n;i++){
        sol[++el] = make_pair(v[i],0);
        //cout<<v[i]<<" ";
        for (int j=0;j<L[i].size();j++)
            sol[++el] = make_pair(L[i][j],1);

    }
    for (i=1;i<=el;i++){
        if (!k){
            cout<<sol[i].first<<" ";
            continue;
        }

        if (!sol[i].second)
            cout<<sol[i].first<<" ";
        else {
            /// inseamna ca pot sa il mai descompun

            int x = sol[i].first;

            if (x < k){
                k -= x;
                cout<<1<<" ";
                for (j=1;j<=x-1;j++)
                    cout<<j<<" ";
            } else {
                cout<<x-k<<" ";
                for (j=x-k;j<x;j++)
                    cout<<j<<" ";
            }
        }
    }


    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:52:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j=0;j<L[i].size();j++)
                      ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...