Submission #595094

# Submission time Handle Problem Language Result Execution time Memory
595094 2022-07-13T11:08:10 Z Andyvanh1 Permutation (APIO22_perm) C++17
0 / 100
1 ms 212 KB
#include "perm.h"
#include <bits/stdc++.h>
using namespace std;


std::vector<int> construct_permutation(long long k){
    int Max = 0;
    int cur = 0;
    for(int i = 0; i < 60; i++){
        if((((long long)1)<<i)&k){
            Max = i;
            cur++;
        }
    }
    cur--;
    vector<int> ans(Max);

    for(int i = 0; i < Max; i++){
        ans[i] = i;
    }
    vector<int> proc;
    for(int i = Max-1; i>=0; i--){
        if((((long long)1)<<i)&k)proc.push_back(i);
    }
    vector<int> rlproc;
    if(proc.size()<=31){
        rlproc = proc;
    }else{
        vector<vector<int>> zz;
        int at = 2;
        vector<int> curvec;
        while(at<proc.size()-1){
            if(proc[at]-proc[at+1]==1){
                curvec.push_back(at);
                curvec.push_back(at+1);
                at+=2;
            }else{
                at+=1;
                if(!curvec.empty()){
                    at++;
                    zz.push_back(curvec);
                    curvec.clear();
                }
            }
        }
        int curat = 0;
        for(auto& e: zz){
            for(;curat<e[0]-2;curat++){
                rlproc.push_back(curat);
            }
            for(int i = 1; i < e.size(); i+=2){
                rlproc.push_back(e[i]);
            }
            rlproc.push_back(curat);
            rlproc.push_back(curat+1);
            curat = e[e.size()-1]+1;
        }
        for(;curat<proc.size();curat++){
            rlproc.push_back(curat);
        }
        for(int i = 0; i < rlproc.size(); i++){
            rlproc[i] = proc[rlproc[i]];
        }

    }
    for(int i = 0; i<rlproc.size(); i++){
        vector<int> copyans;
        int j = 0;
        if(rlproc[i]!=0) {
            for (;; j++) {
                copyans.push_back(ans[j]);
                if (ans[j] == rlproc[i]-1){
                    break;
                }
            }
        }
        copyans.push_back(Max);
        Max++;
        for(;j<ans.size();j++){
            copyans.push_back(ans[j]);
        }
        ans = copyans;
    }

    return ans;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:32:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         while(at<proc.size()-1){
      |               ~~^~~~~~~~~~~~~~
perm.cpp:51:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             for(int i = 1; i < e.size(); i+=2){
      |                            ~~^~~~~~~~~~
perm.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(;curat<proc.size();curat++){
      |              ~~~~~^~~~~~~~~~~~
perm.cpp:61:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for(int i = 0; i < rlproc.size(); i++){
      |                        ~~^~~~~~~~~~~~~~~
perm.cpp:66:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for(int i = 0; i<rlproc.size(); i++){
      |                    ~^~~~~~~~~~~~~~
perm.cpp:79:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for(;j<ans.size();j++){
      |              ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -