Submission #1012797

# Submission time Handle Problem Language Result Execution time Memory
1012797 2024-07-02T15:43:42 Z codefox Permutation (APIO22_perm) C++17
0 / 100
1 ms 348 KB
#include<bits/stdc++.h>
#include "perm.h"

using namespace std;

std::vector<int> construct_permutation(long long k)
{
    int l = 0;
    for (int i = 62; i>= 0; i--)
    {
        if (k&(1LL<<i)) l =max(l,i);
    }
    vector<int> sol(l);
    iota(sol.begin(), sol.end(), 0);


    int d = l;
    for (int i = l-1; i >= 0; i--)
    {
        if (k&(1LL<<i))
        {
            if (i%2 && k&(1LL<<(i-1)) && d-l>=2)
            {
                i--;
                int h = 0;
                for (int j = sol.size()-1; j >= 0; j--)
                {
                    if (h <=2 && sol[j]>=l) 
                    {
                        sol[j]=d-1+h;
                        h++;
                    }
                    else if (h==2 && sol[j]>d-2) 
                    {
                        sol[j]-=2;
                    }
                }
                sol.push_back(0);
                for (int j = sol.size()-1; j > i; j--)
                {
                    sol[j] = sol[j-1];
                }
                sol[i] = d - 2;
                d++;
            }
            else
            {
                sol.push_back(0);
                for (int j = sol.size()-1; j >i; j--)
                {
                    sol[j] = sol[j-1];
                }
                sol[i] = d++;
            }
        }
    }
    return sol;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Integer 9 violates the range [0, 8]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Integer 9 violates the range [0, 8]
3 Halted 0 ms 0 KB -