Submission #1140460

#TimeUsernameProblemLanguageResultExecution timeMemory
1140460SangPermutation (APIO22_perm)C++17
0 / 100
0 ms320 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)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:32:20: warning: iteration 59 invokes undefined behavior [-Waggressive-loop-optimizations]
   32 |             bit[i] += x / 2;
      |             ~~~~~~~^~~~~~~~
perm.cpp:4:52: note: within this loop
    4 | #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
      |                                                    ^
perm.cpp:27:9: note: in expansion of macro 'FOR'
   27 |         FOR (i, 1, 60){
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...