Submission #745385

# Submission time Handle Problem Language Result Execution time Memory
745385 2023-05-19T23:40:55 Z Patrick Permutation (APIO22_perm) C++17
91.3333 / 100
2 ms 340 KB
#include "perm.h"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

std::vector<int> construct_permutation(long long k) {
    ll v = 1;
    ll a = 0;
    while (v * 2 <= k) {
        v *= 2;
        a++;
    }
    k -= v;
    vector<int> inc(a);
    while (k > 0) {
        ll s = 0;
        while ((1LL << (s + 1)) <= k) {
            s++;
        }
        inc[s] = a++;
        k -= (1LL << s);
    }
    vector<int> ans;
    for (int i = 0; i < inc.size(); i++) {
        if (inc[i] != 0) ans.push_back(inc[i]);
        ans.push_back(i);
    }
    return ans;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 0; i < inc.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Partially correct 1 ms 340 KB Partially correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Partially correct 2 ms 296 KB Partially correct
9 Correct 1 ms 340 KB Output is correct
10 Partially correct 2 ms 340 KB Partially correct
11 Partially correct 2 ms 340 KB Partially correct
12 Partially correct 1 ms 340 KB Partially correct
13 Partially correct 2 ms 340 KB Partially correct