Submission #855782

# Submission time Handle Problem Language Result Execution time Memory
855782 2023-10-01T19:23:03 Z faruk Zalmoxis (BOI18_zalmoxis) C++17
35 / 100
256 ms 57780 KB
#include <bits/stdc++.h>
#define mp make_pair
#define all(a) a.begin(), a.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef set<pii>::iterator ite;

const int MX = 30;

void recur(int val, int left, vector<int> &arr) {
    if (left == 1)
    {
        arr.push_back(val);
        return;
    } else if (left == 2) {
        arr.push_back(val - 1);
        arr.push_back(val - 1);
        return;
    }
    int can_make_from_1 = 1 << (val - 1);
    if (can_make_from_1 >= left)
    {
        recur(val - 1, left - 1, arr);
        arr.push_back(val);
    }
    else
    {
        recur(val - 1, can_make_from_1, arr);
        recur(val - 1, left - can_make_from_1, arr);
    }
}

vector<int> make(int val, int needed) {
    vector<int> out;
    recur(val, needed, out);
    return out;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;
    int needed = 1 << 30, lowest = 30;
    vector<int> og(n);
    vector<pii> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i].second;
        og[i] = arr[i].second;
        arr[i].first = i;
        needed -= 1 << arr[i].second;
        lowest = min(lowest, arr[i].second);
    }
    needed = log2(needed);
    
    vector<vector<int> > to_insert(n);
    vector<pii> neww;
    for (; lowest < 30; lowest++) {
        for (int i = 0; i < arr.size(); i++) {
            if (arr[i].second == lowest) {
                int s = 0, j;
                for (j = i; j < arr.size() && arr[j].second == lowest; j++)
                {
                    s++;
                    if (s % 2)
                        neww.push_back({arr[j].first, lowest + 1});
                }
                i = j - 1;
                if (s % 2)
                {
                    to_insert[arr[i].first].push_back(lowest);
                    k--;
                }
            } else {
                neww.push_back(arr[i]);
            }
        }
        arr.clear();
        sort(all(neww));
        swap(neww, arr);
    }

    for (int i = 0; i < n; i++) {
        if (k == 0)
            break;
        //reverse(all(to_insert[i]));
        vector<int> neww;
        for (int a : to_insert[i]) {
            if (k == 0) {
                neww.push_back(a);
                continue;
            }
            int possible = (1 << a);
            int to_make = min(possible, k) + 1;
            vector<int> compose = make(a, to_make);
            neww.insert(neww.end(), all(compose));
            k++;
            k -= to_make;
        }
        to_insert[i] = neww;
    }

    vector<int> out;
    for (int i = 0; i < n; i++) {
        out.insert(out.end(), all(to_insert[i]));
        out.push_back(og[i]);
    }
    for (int a : out) 
        cout << a << " ";
    cout << "\n";
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:63:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for (int i = 0; i < arr.size(); i++) {
      |                         ~~^~~~~~~~~~~~
zalmoxis.cpp:66:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |                 for (j = i; j < arr.size() && arr[j].second == lowest; j++)
      |                             ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 214 ms 53692 KB Output is correct
2 Correct 210 ms 53012 KB Output is correct
3 Correct 229 ms 52792 KB Output is correct
4 Correct 209 ms 52916 KB Output is correct
5 Correct 214 ms 54012 KB Output is correct
6 Correct 192 ms 53024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 202 ms 53576 KB not a zalsequence
2 Correct 197 ms 53792 KB Output is correct
3 Incorrect 231 ms 53180 KB not a zalsequence
4 Incorrect 256 ms 55064 KB not a zalsequence
5 Incorrect 208 ms 56256 KB not a zalsequence
6 Incorrect 204 ms 57780 KB not a zalsequence
7 Incorrect 210 ms 56196 KB not a zalsequence
8 Incorrect 247 ms 52960 KB not a zalsequence
9 Incorrect 197 ms 52868 KB not a zalsequence
10 Incorrect 126 ms 26344 KB not a zalsequence
11 Incorrect 198 ms 34372 KB not a zalsequence
12 Incorrect 68 ms 15740 KB not a zalsequence
13 Incorrect 63 ms 14180 KB not a zalsequence
14 Incorrect 56 ms 15504 KB not a zalsequence