Submission #1108720

# Submission time Handle Problem Language Result Execution time Memory
1108720 2024-11-04T20:35:54 Z vicvic Zalmoxis (BOI18_zalmoxis) C++11
100 / 100
170 ms 14788 KB
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;
ifstream f ("zalmoxis.in");
ofstream g ("zalmoxis.out");
int n, k, v[2000005], poz, added[2000005], s[2000005], cnt;
void descp (int j)
{
    if (j<=1)
    {
        cout << j << " ";
    }
    else if (k>0)
    {
        k--;
        descp (j-1);
        descp (j-1);
    }
    else cout << j << " ";
}
int main()
{
    cin >> n >> k;
    int poz=0, adaugate=0;
    for (int i=1; i<=n; i++)
    {
        int x;
        cin >> x;
        while (cnt && s[cnt]<x)
        {
            v[++poz]=s[cnt];
            added[poz]=1;
            k--;
            int val=v[poz];
            while (cnt && val==s[cnt])
            {
                cnt--;
                val++;
            }
            s[++cnt]=val;
        }
        v[++poz]=x;
        while (cnt && x==s[cnt])
        {
            cnt--;
            x++;
        }
        s[++cnt]=x;
    }
    while (s[1]<30)
    {
        k--;
        v[++poz]=s[cnt];
        added[poz]=1;
        int val=v[poz];
        while (cnt && s[cnt]==val)
        {
            cnt--;
            val++;
        }
        s[++cnt]=val;
    }
    assert (k>=0);
    for (int i=1; i<=poz; i++)
    {
        if (added[i])
        {
            descp (v[i]);
        }
        else cout << v[i] << " ";
    }
    return 0;
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:25:16: warning: unused variable 'adaugate' [-Wunused-variable]
   25 |     int poz=0, adaugate=0;
      |                ^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 141 ms 10692 KB Output is correct
2 Correct 156 ms 10568 KB Output is correct
3 Correct 140 ms 10688 KB Output is correct
4 Correct 140 ms 10568 KB Output is correct
5 Correct 148 ms 10684 KB Output is correct
6 Correct 139 ms 10684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 12736 KB Output is correct
2 Correct 170 ms 14788 KB Output is correct
3 Correct 158 ms 14788 KB Output is correct
4 Correct 147 ms 12740 KB Output is correct
5 Correct 154 ms 14668 KB Output is correct
6 Correct 148 ms 12616 KB Output is correct
7 Correct 158 ms 12624 KB Output is correct
8 Correct 147 ms 12740 KB Output is correct
9 Correct 140 ms 14664 KB Output is correct
10 Correct 101 ms 10520 KB Output is correct
11 Correct 128 ms 10688 KB Output is correct
12 Correct 55 ms 6472 KB Output is correct
13 Correct 67 ms 6336 KB Output is correct
14 Correct 54 ms 6472 KB Output is correct