Submission #642545

# Submission time Handle Problem Language Result Execution time Memory
642545 2022-09-19T21:43:17 Z danikoynov Permutation (APIO22_perm) C++17
100 / 100
2 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector < int > construct_permutation(ll k)
{
    vector < ll > dig;
    while(k > 0)
    {
        dig.push_back(k % 4);
        k /= 4;
    }

    reverse(dig.begin(), dig.end());
    vector < int > v;
    if (dig[0] == 2)
        v.push_back(0);
    else
    if (dig[0] == 3)
    {
        v.push_back(1);
        v.push_back(0);
    }
    /**for (int i = 0; i < dig.size(); i ++)
        cout << dig[i] << " ";
    cout << endl;*/
    for (int i = 1; i < dig.size(); i ++)
    {

        if (dig[i] == 0)
        {
            int mx = v.size();
            v.push_back(mx);
            mx ++;
            v.push_back(mx);
        }
        else
        if (dig[i] == 1)
        {
            int mx = v.size();
            for (int j = 0; j < v.size(); j ++)
                v[j] ++;
            mx ++;
            v.push_back(mx);
            mx ++;
            v.push_back(mx);
            v.push_back(0);
        }
        else
        if (dig[i] == 2)
        {
                       int mx = v.size();
            for (int j = 0; j < v.size(); j ++)
                v[j] ++;
            mx ++;
            v.push_back(mx);
            v.push_back(0);
            mx ++;
            v.push_back(mx);
        }
        else
        if (dig[i] == 3)
        {
            bool fd = false, tf = false;
            for (int j = 0; j < v.size(); j ++)
            {
                if (v[j] == 1)
                    fd = true;
                if (v[j] == 0)
                {
                    if (fd)
                        tf = true;
                    break;
                }
            }

            if (tf)
            {

                int mx = v.size();
                for (int j = 0; j < v.size(); j ++)
                    if (v[j] > 1)
                    v[j] ++;
                mx ++;
                v.push_back(mx);
                mx ++;
                v.push_back(mx);
                v.push_back(2);
            }
            else
            {
                int mx = v.size();
                for (int j = 0; j < v.size(); j ++)
                    v[j] += 2;

                mx += 2;
                v.push_back(mx);
                mx ++;
                v.push_back(1);
                v.push_back(mx);
                v.push_back(0);
            }
        }

    } /**for (int i = 0; i < v.size(); i ++)
        cout << v[i] << " ";
    cout << endl;*/

    return v;

}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(ll)':
perm.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i = 1; i < dig.size(); i ++)
      |                     ~~^~~~~~~~~~~~
perm.cpp:40:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             for (int j = 0; j < v.size(); j ++)
      |                             ~~^~~~~~~~~~
perm.cpp:52:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             for (int j = 0; j < v.size(); j ++)
      |                             ~~^~~~~~~~~~
perm.cpp:64:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |             for (int j = 0; j < v.size(); j ++)
      |                             ~~^~~~~~~~~~
perm.cpp:80:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |                 for (int j = 0; j < v.size(); j ++)
      |                                 ~~^~~~~~~~~~
perm.cpp:92:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |                 for (int j = 0; j < v.size(); j ++)
      |                                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 260 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 260 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct