# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1140460 | Sang | Permutation (APIO22_perm) | C++17 | 0 ms | 320 KiB |
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
#define task "kbsiudthw"
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 2277;
int bit[60];
vector<int> construct_permutation(long long k){
--k;
bit[0] = k;
while (true){
int ok = 0;
FOR (i, 1, 60){
int x = 2 * (bit[i-1] - bit[i]) / 3;
if (x & 1) --x;
x = max(x, 0);
if (x) ok = 1;
bit[i] += x / 2;
bit[i-1] -= x;
}
if (ok == 0) break;
}
vi b;
FORD(i, 60, 1){
if (bit[i] == 0) continue;
bit[i] -= bit[i+1];
FOR (j, 1, bit[i]) b.pb(i + 1);
}
vi ans;
int s = 0;
for (int &x : b) s += x;
--s;
for (int &x : b){
FOR (i, s - x + 1, s) ans.pb(i);
s -= x;
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |