Submission #851302

# Submission time Handle Problem Language Result Execution time Memory
851302 2023-09-19T13:30:40 Z jmyszka2007 Permutation (APIO22_perm) C++17
91.3333 / 100
3 ms 432 KB
#include "perm.h"
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {return o << '(' << p.first << ", " << p.second << ')';}
template<size_t Index = 0, typename... Types>
ostream& printTupleElements(ostream& o, const tuple<Types...>& t) {if constexpr (Index < sizeof...(Types)){if(Index > 0){o << ", ";}o << get<Index>(t);printTupleElements<Index + 1>(o, t);}return o;}
template<typename... Types>
ostream& operator<<(ostream& o, const tuple<Types...>& t){o << "(";printTupleElements(o, t);return o << ")";}
template<class T>
auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o){o << '{';bool first = true;for (const auto& e : x){if (!first){o << ", ";}o << e;first = false;} return o << '}';}
#define DEBUG
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#define check(x) if (!(x)) { cerr << "Check failed: " << #x << " in line " << __LINE__ << endl; exit(1); }
#else
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0);
#define debug(...)
#define check(x) 
#endif
typedef long long ll;
#define pi pair<int, int>
#define pl pair<ll, ll>
#define st first
#define nd second
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
vi construct_permutation(ll k) {
	vi res;
	ll pot = 1;
	int i = 0;
	while(pot * 2 <= k) {
		res.eb(i++);
		pot *= 2;
	}
	i--;
	vi dod;
	for(ll j = i; j >= 0; j--) {
		if(k & (1ll << j)) {
			int kt = res[i - j];
			for(auto &x : dod) {
				if(x >= kt + 1) {
					x++;
				}
			}
			for(auto &x : res) {
				if(x >= kt + 1) {
					x++;
				}
			}
			dod.eb(kt + 1);
		}
	}
	reverse(all(dod));
	dod.insert(dod.end(), all(res));
	return dod;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Partially correct 1 ms 348 KB Partially correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Partially correct 1 ms 348 KB Partially correct
9 Correct 1 ms 348 KB Output is correct
10 Partially correct 3 ms 348 KB Partially correct
11 Partially correct 2 ms 344 KB Partially correct
12 Partially correct 1 ms 348 KB Partially correct
13 Partially correct 2 ms 348 KB Partially correct