# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
789743 | tvladm2009 | Permutation (APIO22_perm) | C++17 | 1 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 "perm.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 10000;
vector<int> norm(vector<int> v) {
vector<int> aux;
sort(aux.begin(), aux.end());
aux.resize(unique(aux.begin(), aux.end()) - aux.begin());
map<int, int> mp;
int cnt = 0;
for (auto &it : aux) {
mp[it] = ++cnt;
}
for (auto &it : v) {
it = mp[it];
}
return v;
}
vector<int> construct_permutation(ll n) {
if (n == 1) {
return norm({});
} else if (n == 2) {
return norm({0});
} else if (n == 3) {
return norm({1, 0});
}
vector<int> sol = construct_permutation(n / 4);
if (n % 4 == 0) {
sol.push_back(INF);
sol.push_back(INF + 1);
}
if (n % 4 == 1) {
sol.push_back(INF);
sol.push_back(INF + 1);
sol.push_back(-1);
}
if (n % 4 == 2) {
sol.push_back(INF);
sol.push_back(-1);
sol.push_back(INF + 1);
}
if (n % 4 == 3) {
bool one = 0, onezero = 0;
for (auto &it : sol) {
one |= (it == 1);
if (it == 0) {
onezero |= one;
}
}
if (onezero == true) {
for (auto &it : sol) {
it *= 2;
}
sol.push_back(INF);
sol.push_back(INF + 1);
sol.push_back(3);
} else {
sol.push_back(INF);
sol.push_back(-1);
sol.push_back(INF + 1);
sol.push_back(-2);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |