# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
642545 | danikoynov | Permutation (APIO22_perm) | C++17 | 2 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |