Submission #742338

# Submission time Handle Problem Language Result Execution time Memory
742338 2023-05-16T06:28:36 Z khshg Permutation (APIO22_perm) C++17
93.6667 / 100
3 ms 340 KB
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using str = string;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<ld, ld>;
#define mp make_pair
#define ff first
#define ss second

template<class T> using V = vector<T>;
#define arr array
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<ld>;
using vs = V<str>;
using vpi = V<pi>;
using vpl = V<pl>;
using vpd = V<pd>;

#define sz(x) (int)((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()

#define lb lower_bound
#define ub upper_bound

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define rep(a) F0R(_, a)
#define trav(a, x) for(auto& a : x)

template<class T> bool ckmin(T& a, const T& b) { return (b < a ? a = b, 1 : 0); }
template<class T> bool ckmax(T& a, const T& b) { return (b > a ? a = b, 1 : 0); }

vi construct_permutation(ll k) {
	V<char> bits;
	F0R(i, 62) {
		bits.eb(k % 3LL);
		k /= 3LL;
	}
	deque<char> ans;
	int mn = 0, mx = 1;
	while(!bits.bk) bits.pop_back();
	if(bits.bk == 2) {
		ans.eb(0);
		mn = -1;
		mx = 1;
	}
	bits.pop_back();
	reverse(all(bits));
	F0R(i, sz(bits)) {
		char cur = bits[i];
		if(!cur) {
			ans.eb(mx + 1);
			ans.eb(mx);
			mx += 2;
		} else if(cur == 1) {
			ans.eb(mx + 1);
			ans.eb(mx);
			mx += 2;
			ans.eb(mn);
			--mn;
		} else {
			ans.emplace_front(mx + 1);
			ans.eb(mx + 2);
			ans.eb(mx);
			mx += 3;
		}
	}
	vi rans(all(ans));
	mn = 0x3f3f3f3f;
	trav(u, rans) ckmin(mn, u);
	trav(u, rans) u -= mn;
	return rans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Partially correct 1 ms 340 KB Partially correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Partially correct 2 ms 340 KB Partially correct
9 Partially correct 2 ms 340 KB Partially correct
10 Partially correct 2 ms 340 KB Partially correct
11 Partially correct 2 ms 300 KB Partially correct
12 Partially correct 3 ms 340 KB Partially correct
13 Partially correct 2 ms 340 KB Partially correct