Submission #1344524

#TimeUsernameProblemLanguageResultExecution timeMemory
1344524omarrrrPermutation (APIO22_perm)C++20
Compilation error
0 ms0 KiB
#include "perm.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> construct_permutation(long long k) {
    if (k == 1) return {};

    // 1. Find the highest bit to build the 'main' increasing sequence
    int max_bit = 0;
    while ((1LL << (max_bit + 1)) <= k) {
        max_bit++;
    }

    vector<int> res;
    // Build the backbone: 0, 1, 2, ..., max_bit-1
    // This gives us 2^max_bit subsequences
    for (int i = 0; i < max_bit; i++) {
        res.push_back(i);
    }

    // 2. Add the remainder k - 2^max_bit
    long long remainder = k - (1LL << max_bit);

    // We iterate from the highest possible bit down to 0
    // To add 2^i, we insert a value that is 'larger' than the first i elements
    // but 'smaller' than the rest.
    for (int i = max_bit - 1; i >= 0; i--) {
        if ((remainder >> i) & 1) {
            res.push_back(i);
        }
    }

    return res;
}#include "perm.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> construct_permutation(long long k) {
    if (k == 1) return {};

    // 1. Find the highest bit to build the 'main' increasing sequence
    int max_bit = 0;
    while ((1LL << (max_bit + 1)) <= k) {
        max_bit++;
    }

    vector<int> res;
    // Build the backbone: 0, 1, 2, ..., max_bit-1
    // This gives us 2^max_bit subsequences
    for (int i = 0; i < max_bit; i++) {
        res.push_back(i);
    }

    // 2. Add the remainder k - 2^max_bit
    long long remainder = k - (1LL << max_bit);

    // We iterate from the highest possible bit down to 0
    // To add 2^i, we insert a value that is 'larger' than the first i elements
    // but 'smaller' than the rest.
    for (int i = max_bit - 1; i >= 0; i--) {
        if ((remainder >> i) & 1) {
            res.push_back(i);
        }
    }

    return res;
}

Compilation message (stderr)

perm.cpp:34:2: error: stray '#' in program
   34 | }#include "perm.h"
      |  ^
perm.cpp:34:3: error: 'include' does not name a type
   34 | }#include "perm.h"
      |   ^~~~~~~
perm.cpp:38:13: error: redefinition of 'std::vector<int> construct_permutation(long long int)'
   38 | vector<int> construct_permutation(long long k) {
      |             ^~~~~~~~~~~~~~~~~~~~~
perm.cpp:5:13: note: 'std::vector<int> construct_permutation(long long int)' previously defined here
    5 | vector<int> construct_permutation(long long k) {
      |             ^~~~~~~~~~~~~~~~~~~~~