제출 #678894

#제출 시각아이디문제언어결과실행 시간메모리
678894Genius3435Detecting Molecules (IOI16_molecules)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
using u32 = uint32_t;

int[] find_subset(int l, int u, int[] _w) {
    int const n = sizeof(w)/sizeof(int);

    deque<pair<u32, int>> w, used;
    for (int i = 0; i < n; ++i) {
        w.emplace_back(_w[i], i);
    }
    sort(w.begin(), w.end());

    u32 s = 0;
    while (s < l && !w.empty()) {
        auto const [x, i] = w.front();
        if (s+x > u) break;
        w.pop_front();
        used.emplace_back(x, i);
        s += x;
    }

    while (s < l && !w.empty()) {
        auto const [x, i] = used.front();
        auto const [y, j] = w.back();
        s -= x, s += y;
        used.pop_front();
        w.pop_back();
        used.emplace_back(y, j);
    }

    if (l <= s && s <= u) {
        int *ans = new int[used.size()], j = 0;
        for (auto const &[x, i] : used) ans[j++] = i;
        return ans;
    }

    else {
        int *ans = new int[0];
        return ans;
    }
}

컴파일 시 표준 에러 (stderr) 메시지

molecules.cpp:5:4: error: structured binding declaration cannot have type 'int'
    5 | int[] find_subset(int l, int u, int[] _w) {
      |    ^~
molecules.cpp:5:4: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
molecules.cpp:5:4: error: empty structured binding declaration
molecules.cpp:5:7: error: expected initializer before 'find_subset'
    5 | int[] find_subset(int l, int u, int[] _w) {
      |       ^~~~~~~~~~~