Submission #915141

# Submission time Handle Problem Language Result Execution time Memory
915141 2024-01-23T11:53:19 Z Amirreza_Fakhri Permutation (APIO22_perm) C++17
100 / 100
2 ms 600 KB
// In the name of the God
#include <bits/stdc++.h>
#include "perm.h"
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;

const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 2e5+5;

vector <int> construct_permutation(ll k) {
    vector <int> res;
    if (k == 1) {
        return res;
    }
    if (k == 2) {
        res.pb(0); return res;
    }
    if (k == 3) {
        res.pb(1), res.pb(0); return res;
    }
    res = construct_permutation(k/4);
    int l = res.size();
    if ((k%4) == 0) {
        res.pb(l), res.pb(l+1);
    }
    else if ((k%4) == 1) {
        for (int &x : res) x++;
        res.pb(l+1), res.pb(l+2), res.pb(0);
    }
    else if ((k%4) == 2) {
        for (int &x : res) x++;
        res.pb(l+1), res.pb(0), res.pb(l+2);
    }
    else {
        bool flag;
        for (int x : res) {
            if (x <= 1) {
                flag = x; break;
            }
        }
        if (flag) {
            for (int &x : res) {
                if (x > 1) x++;
            }
            res.pb(l+1), res.pb(l+2), res.pb(2);
        }
        else {
            for (int &x : res) x += 2;
            res.pb(l+2), res.pb(1), res.pb(l+3), res.pb(0);
        }
    }
    return res;
}

// int32_t main() {
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//     return 0;
// }

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:51:9: warning: 'flag' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |         if (flag) {
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct