Submission #839183

# Submission time Handle Problem Language Result Execution time Memory
839183 2023-08-29T02:41:13 Z anha3k25cvp Zalmoxis (BOI18_zalmoxis) C++14
35 / 100
491 ms 71012 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define dl double
#define st first
#define nd second
#define II pair <int, int>

using namespace std;

const int N = 5 + 1e5;
const int inf = 7 + 1e9;

int main() {
#define TASKNAME ""
    ios_base :: sync_with_stdio (0);
    cin.tie (0);
    if ( fopen( TASKNAME".inp", "r" ) ) {
        freopen (TASKNAME".inp", "r", stdin);
        freopen (TASKNAME".out", "w", stdout);
    }
    int n, k;
    cin >> n >> k;
    vector <int> a(n + k + 1, 0), nex(n + 1, 0), last(n + 1, 0);
    set <II> q;
    int mi = inf;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        mi = min(mi, a[i]);
        q.insert({a[i], i});
        last[i] = i;
        if (i < n)
            nex[i] = i + 1;
    }
    int cnt = n;
    vector <int> c(n + k + 1, 0), b = a;
    while (!q.empty()) {
        int val = q.begin() -> st, u = q.begin() -> nd;
        q.erase(q.begin());
        if (val == 30)
            break;
        int v = nex[u];
        if (v && b[v] == b[u]) {
            q.erase(q.begin());
            c[last[u]] = v;
            last[u] = last[v];
            nex[u] = nex[v];
            q.insert({b[u] = val + 1, u});
        }
        else {
            a[++ cnt] = val;
            c[last[u]] = cnt;
            last[u] = cnt;
            q.insert({b[u] = val + 1, u});
        }
    }
    int pos = 1;
    n += k;
    for (int i = 1; i <= cnt; i ++) {
        if (a[pos] == mi) {
            int x = n - cnt + 1, k = 0;
            for (; (1 << k) < x; k ++);
            a[pos] -= k;
            if ((1 << k) <= x) {
                n -= (1 << k) - 1;
                for (int j = 1; j <= (1 << k); j ++)
                    cout << a[pos] << ' ';
            }
            else {
                int y = (1 << k) - cnt;
                for (int j = 1; j <= x; j ++)
                    if (j <= y)
                        cout << a[pos] + 1 << ' ';
                    else
                        cout << a[pos] << ' ';
                n = cnt;
            }
        }
        else
            cout << a[pos] << ' ';
        pos = c[pos];
    }
    return 0;
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:19:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen (TASKNAME".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
zalmoxis.cpp:20:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen (TASKNAME".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 464 ms 70920 KB Output is correct
2 Correct 472 ms 70888 KB Output is correct
3 Correct 458 ms 71012 KB Output is correct
4 Correct 463 ms 70944 KB Output is correct
5 Correct 460 ms 70968 KB Output is correct
6 Correct 465 ms 70940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 468 ms 70940 KB doesn't contain S as a subsequence
2 Correct 450 ms 70892 KB Output is correct
3 Incorrect 491 ms 70896 KB doesn't contain S as a subsequence
4 Incorrect 477 ms 71004 KB doesn't contain S as a subsequence
5 Incorrect 458 ms 70960 KB doesn't contain S as a subsequence
6 Incorrect 472 ms 70920 KB doesn't contain S as a subsequence
7 Incorrect 479 ms 70948 KB doesn't contain S as a subsequence
8 Incorrect 484 ms 71008 KB doesn't contain S as a subsequence
9 Incorrect 402 ms 59660 KB not a zalsequence
10 Incorrect 192 ms 32288 KB doesn't contain S as a subsequence
11 Incorrect 275 ms 43164 KB doesn't contain S as a subsequence
12 Incorrect 52 ms 16084 KB not a zalsequence
13 Incorrect 75 ms 15992 KB not a zalsequence
14 Incorrect 52 ms 15976 KB not a zalsequence