Submission #722113

#TimeUsernameProblemLanguageResultExecution timeMemory
722113yeysoPermutation (APIO22_perm)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h>
using namespace std;
#include "perm.h"

vector<int> construct_permutation(long long k)
{
	k -= 1;
	int x = 1;
	vector<int> sub = {0};
	vector<int> res;
	while(sub[sub.size()-1] < k * 2){
		sub.push_back(pow(2, x)-1);
		x += 1;
	}
	while(k > 0){
		for(int i = 0; i < sub.size(); i ++){
			if(sub[i] > k){
				k -= sub[i-1];
				res.push_back(i-1);
                break;
			}
		}
	}
    vector<vector<int>> inc;
    int res0;
    for(int i = 0; i < res.size(); i ++){
        inc.push_back({});
        for(int j = 0; j < res[i]; j ++){
            inc[i].push_back(j+res0);
        }
        res0 += res[i];
    }
    vector<int> res2;
    reverse(inc.begin(), inc.end());
    for(int i = 0; i < inc.size(); i ++){
        for(int j = 0; j < inc[i].size(); j ++){
            res2.push_back(inc[i][j]);
        }

    }
	return res2;
}

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   for(int i = 0; i < sub.size(); i ++){
      |                  ~~^~~~~~~~~~~~
perm.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i = 0; i < res.size(); i ++){
      |                    ~~^~~~~~~~~~~~
perm.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i = 0; i < inc.size(); i ++){
      |                    ~~^~~~~~~~~~~~
perm.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int j = 0; j < inc[i].size(); j ++){
      |                        ~~^~~~~~~~~~~~~~~
perm.cpp:25:9: warning: 'res0' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |     int res0;
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...