답안 #855788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855788 2023-10-01T19:27:47 Z faruk Zalmoxis (BOI18_zalmoxis) C++17
50 / 100
243 ms 57912 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);
    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++)
      |                             ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 52924 KB Output is correct
2 Correct 229 ms 53004 KB Output is correct
3 Correct 217 ms 53436 KB Output is correct
4 Correct 239 ms 53164 KB Output is correct
5 Correct 229 ms 53020 KB Output is correct
6 Correct 199 ms 52664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 223 ms 53048 KB not a zalsequence
2 Correct 206 ms 52664 KB Output is correct
3 Incorrect 231 ms 53012 KB not a zalsequence
4 Incorrect 220 ms 54400 KB not a zalsequence
5 Correct 233 ms 57912 KB Output is correct
6 Correct 212 ms 56860 KB Output is correct
7 Incorrect 224 ms 56324 KB not a zalsequence
8 Incorrect 243 ms 53096 KB not a zalsequence
9 Incorrect 208 ms 53244 KB not a zalsequence
10 Incorrect 136 ms 26504 KB not a zalsequence
11 Incorrect 163 ms 34748 KB not a zalsequence
12 Incorrect 54 ms 18020 KB not a zalsequence
13 Incorrect 56 ms 14808 KB not a zalsequence
14 Correct 62 ms 15868 KB Output is correct