답안 #912489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
912489 2024-01-19T14:36:42 Z linvg 순열 (APIO22_perm) C++17
컴파일 오류
0 ms 0 KB
int[] construct_permutation(int64_t x)
{
    int64_t sum = 1;

    int64_t mn = 1e9 - 1;

    vector<int64_t> res;

    while (sum < x) {
        int64_t cnt = 0;
        for (int64_t i = 1; i <= 62; ++i) {
            if (sum + (1ll << i) - 1 > x) {
                sum += (1ll << (i-1)) - 1;
                cnt = i - 1;
                break;
            }
        }
        // dbg(sum, cnt);
        for (int64_t i = mn - cnt; i < mn; ++i) {
            // cout << i << " ";
            res.pb(i);
        }
        mn -= cnt;

        for (int64_t i = 62; i >= 1; --i) {
            if (sum + (1ll << (i - 1)) <= x) {
                sum += (1ll << (i - 1));
                cnt = i - 1;
                res.pb(mn + cnt);
            }
        }
    }
    // dbg(sum);
    // dbg(sz(res));
    int64_t ans[sz(res)] = {0}; 
    for (int64_t i = 0; i < sz(res); ++i) {
        ans[i] = res[i];
    }
    return ans;
}

Compilation message

perm.cpp:1:4: error: structured binding declaration cannot have type 'int'
    1 | int[] construct_permutation(int64_t x)
      |    ^~
perm.cpp:1:4: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
perm.cpp:1:4: error: empty structured binding declaration
perm.cpp:1:7: error: expected initializer before 'construct_permutation'
    1 | int[] construct_permutation(int64_t x)
      |       ^~~~~~~~~~~~~~~~~~~~~