이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "perm.h"
using namespace std;
vector<int> construct_permutation(long long m)
{
long long k = m;
if (k == 2) return {0};
if (k == 3) return {1, 0};
stack<int> ops; //0 -> *2, 1 -> +1, 2 -> +2, 3 -> +3
while (((k>>4)&1) || k >= (1<<5)-1)
{
if ((k&3) == 3) ops.push(3), ops.push(0), ops.push(0), k>>=2;
else if ((k&1) == 1) ops.push(1), ops.push(0), ops.push(0), k>>=2;
else ops.push(0), k>>=1;
}
if (k == 0b0100) ops.push(1);
if (k == 0b0101) ops.push(2);
if (k == 0b0110) ops.push(3);
if (k == 0b0111) ops.push(3), ops.push(1);
if (k == 0b1000) ops.push(0), ops.push(1);
if (k == 0b1001) ops.push(1), ops.push(0), ops.push(1);
if (k == 0b1010) ops.push(0), ops.push(2);
if (k == 0b1011) ops.push(3), ops.push(0), ops.push(1);
if (k == 0b1100) ops.push(0), ops.push(0);
if (k == 0b1101) ops.push(1), ops.push(0), ops.push(0);
if (k == 0b1110) ops.push(0), ops.push(1), ops.push(0);
if (k == 0b1111) ops.push(3), ops.push(0), ops.push(0);
// long long sum = 3;
// while (ops.size()) sum = sum*(ops.top() == 0? 2 : 1) + ops.top(), ops.pop();
// return sum;
vector<int> a = {1, 0};
while (ops.size())
{
int op = ops.top(); ops.pop();
if (op == 0) a.push_back(a.size());
if (op == 1)
{
vector<int> temp = a;
a.clear(), a.push_back(temp.size());
for (auto i : temp) a.push_back(i);
}
if (op == 2)
{
vector<int> temp = a;
a.clear(), a.push_back(temp[0]), a.push_back(temp.size());
for (auto i : temp) if (i != temp[0]) a.push_back(i);
}
if (op == 3)
{
for (auto &i : a) if (i >= 2) i++;
a.push_back(2);
}
}
return a;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |