Submission #1108714

#TimeUsernameProblemLanguageResultExecution timeMemory
1108714vicvicZalmoxis (BOI18_zalmoxis)C++11
0 / 100
25 ms24312 KiB
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;
ifstream f ("zalmoxis.in");
ofstream g ("zalmoxis.out");
int n, k, v[1000005], poz, added[1000005], s[1000005], cnt;
void descp (int j)
{
    if (j<=1)
    {
        g << j << " ";
    }
    else if (k>0)
    {
        k--;
        descp (j-1);
        descp (j-1);
    }
    else g << j << " ";
}
void propag ()
{
    while (cnt>=2)
    {
        int a=s[cnt], b=s[cnt-1];
        if (a==b)
        {
            cnt--;
            s[cnt]=a+1;
        }
        else
        {
            return;
        }
    }
}
int main()
{
    f >> n >> k;
    int poz=0, adaugate=0;
    for (int i=1; i<=n; i++)
    {
        int x;
        f >> x;
        while (cnt && s[cnt]<x)
        {
            v[++poz]=s[cnt];
            added[poz]=1;
            k--;
            s[++cnt]=s[cnt-1];
            propag ();
        }
        v[++poz]=x;
        s[++cnt]=x;
        propag ();
    }
    while (s[1]<30)
    {
        k--;
        v[++poz]=s[cnt];
        added[poz]=1;
        s[++cnt]=s[cnt-1];
        propag ();
    }
    for (int i=1; i<=poz; i++)
    {
        if (added[poz])
        {
            descp (v[i]);
        }
        else g << v[i] << " ";
    }
    return 0;
}

Compilation message (stderr)

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:51:15: warning: operation on 'cnt' may be undefined [-Wsequence-point]
   51 |             s[++cnt]=s[cnt-1];
      |               ^~~~~
zalmoxis.cpp:51:15: warning: operation on 'cnt' may be undefined [-Wsequence-point]
zalmoxis.cpp:63:11: warning: operation on 'cnt' may be undefined [-Wsequence-point]
   63 |         s[++cnt]=s[cnt-1];
      |           ^~~~~
zalmoxis.cpp:63:11: warning: operation on 'cnt' may be undefined [-Wsequence-point]
zalmoxis.cpp:41:16: warning: unused variable 'adaugate' [-Wunused-variable]
   41 |     int poz=0, adaugate=0;
      |                ^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...