Submission #850014

#TimeUsernameProblemLanguageResultExecution timeMemory
850014AndreyPermutation (APIO22_perm)C++17
10 / 100
1 ms600 KiB
#include "perm.h"
#include<bits/stdc++.h>
using namespace std;

vector<int> construct_permutation(long long k) {
    vector<int> ans(0);
    long long br = 2,y = 0;
    while(br <= k) {
        ans.push_back(y);
        y++;
        br*=2;
    }
    k-=br/2;
    for(long long i = y; i >= 0; i--) {
        if((1 << i) <= k) {
            k-=(1 << i);
            ans.push_back(i);
            for(int j = 0; j < ans.size()-1; j++) {
                if(ans[j] >= i) {
                    ans[j]++;
                }
            }
        }
    }
	return ans;
}

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:18:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |             for(int j = 0; j < ans.size()-1; j++) {
      |                            ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...