답안 #855796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855796 2023-10-01T20:00:25 Z faruk Zalmoxis (BOI18_zalmoxis) C++17
50 / 100
204 ms 56852 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 - 1);
    }
    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+1);
    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});
                }
                if (s % 2)
                {
                    to_insert[arr[i].first].push_back(lowest);
                    k--;
                }
                i = j - 1;
            } 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++)
      |                             ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 53432 KB Output is correct
2 Correct 188 ms 52920 KB Output is correct
3 Correct 191 ms 52924 KB Output is correct
4 Correct 187 ms 52920 KB Output is correct
5 Correct 188 ms 53432 KB Output is correct
6 Correct 179 ms 53020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 185 ms 53696 KB not a zalsequence
2 Incorrect 185 ms 52740 KB not a zalsequence
3 Incorrect 192 ms 52964 KB not a zalsequence
4 Incorrect 193 ms 54544 KB not a zalsequence
5 Correct 195 ms 56600 KB Output is correct
6 Correct 185 ms 56852 KB Output is correct
7 Correct 193 ms 55824 KB Output is correct
8 Incorrect 194 ms 54676 KB not a zalsequence
9 Incorrect 187 ms 50104 KB not a zalsequence
10 Incorrect 106 ms 27196 KB not a zalsequence
11 Incorrect 134 ms 36804 KB not a zalsequence
12 Incorrect 56 ms 14716 KB not a zalsequence
13 Incorrect 55 ms 15868 KB not a zalsequence
14 Correct 54 ms 14204 KB Output is correct