Submission #638545

# Submission time Handle Problem Language Result Execution time Memory
638545 2022-09-06T11:00:51 Z Tuanlinh123 Permutation (APIO22_perm) C++17
98 / 100
3 ms 340 KB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
#define LOCALIO "C:/Users/admin/Documents/Code/freopen/"

vector <int> construct_permutation (ll k)
{
    vector <ll> action;
    ll cnt=0;
    while (k>1)
    {

        bool added=0;
        for (ll i=2; i<=5; i++)
            if (k%i==0)
            {
                added=1;
                if (i==5)
                {
                    cnt++;
                    if (cnt%i==0)
                    {
                        action.pb(1);
                        k--;
                        break;
                    }
                }
                action.pb(i);
                k/=i;
                break;
            }
        if (!added)
        {
            k--;
            action.pb(1);
        }
    }
    reverse(action.begin(), action.end());
    // cout << action.size() << "\n";
    // for (ll i=0; i<action.size(); i++)
    //     cout << action[i] << " ";
    // cout << "\n";
    deque <int> q;
    ll num=0;
    for (ll i=0; i<action.size(); i++)
    {
        if (action[i]==1)
        {
            q.push_back(num);
            num++;
        }
        else
        {
            for (ll j=num+action[i]-2; j>=num; j--)
                q.push_front(j);
            num+=action[i]-1;
        }
    }
    // cout << "bruh" << flush;
    vector <int> res;
    while (!q.empty())
    {
        res.pb(q.back());
        q.pop_back();
    }
    return res;
}

// int main()
// {
//     #ifdef LOCAL
//         freopen( LOCALIO "input.txt","r",stdin) ;
//         freopen( LOCALIO "output.txt","w",stdout) ;
//     #endif

//     ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
// //	freopen("FIBONACCI.inp","r",stdin);
// //	freopen("FIBONACCI.out","w",stdout);
//     ll k; cin >> k;
//     vector <int> ans=construct_permutation(k);
//     cout << ans.size() << "\n";
//     for (ll i=0; i<ans.size(); i++)
//         cout << ans[i] << " ";
// }

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:52:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (ll i=0; i<action.size(); i++)
      |                  ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Partially correct 2 ms 296 KB Partially correct
9 Partially correct 2 ms 296 KB Partially correct
10 Partially correct 3 ms 340 KB Partially correct
11 Partially correct 2 ms 340 KB Partially correct
12 Partially correct 2 ms 304 KB Partially correct
13 Partially correct 3 ms 296 KB Partially correct