답안 #855759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855759 2023-10-01T18:08:27 Z faruk Zalmoxis (BOI18_zalmoxis) C++17
30 / 100
184 ms 18768 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;

struct sequence {
    vector<vector<int>> idxs;
    sequence() {
        idxs.resize(MX+1);
    }

    sequence(vector<int> arr) {
        idxs.resize(MX+1);
        for (int i = 0; i < arr.size(); i++)
            idxs[arr[i]].push_back(i);
    }
};

void merge_lowest(int lowest, sequence &seq) {
    sort(all(seq.idxs[lowest]));
    for (int i = 0; i < seq.idxs[lowest].size(); i += 2)
        seq.idxs[lowest + 1].push_back(seq.idxs[lowest][i]);
    seq.idxs[lowest].clear();
}

vector<pii> reconstruct(sequence seq) {
    vector<pii> out;
    for (int i = 0; i <= MX; i++) {
        for (int a : seq.idxs[i])
            out.push_back({a, i});
    }

    sort(all(out));
    return out;
}

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

    int n, k;
    cin >> n >> k;
    int needed = 1 << 30;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        needed -= 1 << arr[i];
    }
    needed = log2(needed);
    int lowest = *min_element(all(arr));
    sequence seq(arr);
    for (;lowest < needed; lowest++)
        merge_lowest(lowest, seq);
    
    vector<pii> new_arr = reconstruct(seq);
    int s = 0, b = -1; int where_to_insert;
    for (int i = 0; i <= new_arr.size(); i++) {
        if (i == new_arr.size() || new_arr[i].second != needed) {
            if (s % 2 == 1)
            {
                where_to_insert = b;
                break;
            }
            s = 0, b = -1;
        }
        else if (new_arr[i].second == needed) {
            if (s == 0)
                b = new_arr[i].first;
            s++;
        }
    }
    arr.insert(arr.begin() + where_to_insert, needed);
    for (int a : arr)
        cout << a << " ";
    cout << "\n";
}

Compilation message

zalmoxis.cpp: In constructor 'sequence::sequence(std::vector<int>)':
zalmoxis.cpp:21:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for (int i = 0; i < arr.size(); i++)
      |                         ~~^~~~~~~~~~~~
zalmoxis.cpp: In function 'void merge_lowest(int, sequence&)':
zalmoxis.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i = 0; i < seq.idxs[lowest].size(); i += 2)
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:64:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for (int i = 0; i <= new_arr.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~~
zalmoxis.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         if (i == new_arr.size() || new_arr[i].second != needed) {
      |             ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 170 ms 18152 KB Output is correct
2 Correct 178 ms 17628 KB Output is correct
3 Correct 181 ms 16944 KB Output is correct
4 Correct 168 ms 18644 KB Output is correct
5 Correct 169 ms 17472 KB Output is correct
6 Correct 170 ms 18768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 167 ms 17928 KB Unexpected end of file - int32 expected
2 Incorrect 177 ms 17176 KB Unexpected end of file - int32 expected
3 Incorrect 179 ms 16876 KB Unexpected end of file - int32 expected
4 Incorrect 172 ms 18488 KB Unexpected end of file - int32 expected
5 Incorrect 169 ms 16748 KB Unexpected end of file - int32 expected
6 Incorrect 180 ms 18096 KB Unexpected end of file - int32 expected
7 Incorrect 184 ms 18012 KB Unexpected end of file - int32 expected
8 Incorrect 176 ms 16808 KB Unexpected end of file - int32 expected
9 Incorrect 139 ms 13844 KB Unexpected end of file - int32 expected
10 Incorrect 57 ms 5788 KB Unexpected end of file - int32 expected
11 Incorrect 87 ms 10176 KB Unexpected end of file - int32 expected
12 Incorrect 0 ms 344 KB Unexpected end of file - int32 expected
13 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
14 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected