Submission #984155

# Submission time Handle Problem Language Result Execution time Memory
984155 2024-05-16T10:49:01 Z vjudge1 Permutation (APIO22_perm) C++17
0 / 100
4 ms 344 KB
//#include "perm.h"
#include<bits/stdc++.h>
#define sz size()
#define ll long long
using namespace std;
mt19937_64 rnd(990910211394901);
vector<int> construct_permutation(ll k)
{
    ll z = 1, sum = 0, d;
    vector<ll> x;

    for(ll j = 59; j > 0; --j)
    {
        if((z << j) > k) continue;
        d = j;
        x.push_back(j);
        k -= (z << j);
        break;
    }


    ll _k = k;
    for(ll t = 1; t <= 1000; ++t)
        for(ll j = 59; j > 0; --j)
        {
            if((z << j) - 1 > _k) continue;
            x.push_back(j);
            _k -= (z << j) - 1;
            sum += j;
        }

    for(ll i = 1; i <= 90; ++i)
    {
        ll t = k - i;
        if(t < 2) break;
        ll cnt = d;
        vector<ll> _x(1, d);
        for(ll j = 59; j > 0; --j)
        {
            if((z << j) > t) continue;
            _x.push_back(j);
            cnt += j;
            t -= (z << j);
        }
        sort(_x.begin(), _x.end());
        while(_x.sz && _x.sz < i && _x.back() > 1)
        {
            sort(_x.begin(), _x.end());
            ll val = _x.back();
            _x.pop_back();
            _x.push_back(val - 1);
            _x.push_back(val - 1);
        }
        if(cnt < sum && i == (ll)_x.sz)
            sum = cnt, x = _x;
    }

    ll cur = 0;
    vector<int> ans;
    for(ll t : x)
    {
        for(ll i = cur + t; i > cur; --i)
            ans.push_back(i - 1);
        cur += t;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

//signed main()
//{
//    ios_base::sync_with_stdio(0);
//    cin.tie(0), cout.tie(0);
//    ll n;
//    cin >> n;
//    for(auto i : construct_permutation(n))
//        cout << i << ' ';
//}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:46:30: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   46 |         while(_x.sz && _x.sz < i && _x.back() > 1)
      |                        ~~~~~~^~~
perm.cpp:42:17: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |             cnt += j;
      |             ~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 4 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 4 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -