#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 200010;
int n;
int x[maxn];
int edge[6][2];
void solve(int v) {
vector<int> idx = {v, 2*v, 2*v+1, 4*v, 4*v+1, 4*v+2, 4*v+3};
while (idx.back() > n) idx.pop_back();
vector<int> p0;
for (int i : idx) p0.push_back(x[i]);
// debug(idx, p0);
vector<int> p = p0;
for (int m = 1; m < (1 << (p0.size() - 1)); ++m) {
vector<int> q = p0;
for (int i = 0; i < int(p0.size() - 1); ++i) {
if (m & (1 << i)) {
swap(q[edge[i][0]], q[edge[i][1]]);
}
}
if (lexicographical_compare(q.begin(), q.end(), p.begin(), p.end())) {
p = q;
}
}
// debug(p);
for (int i = 0; i < (int)idx.size(); ++i) {
x[idx[i]] = p[i];
if (i > 1) solve(idx[i]);
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> x[i];
}
edge[0][0] = 0;
edge[0][1] = 1;
edge[1][0] = 0;
edge[1][1] = 2;
edge[2][0] = 1;
edge[2][1] = 3;
edge[3][0] = 1;
edge[3][1] = 4;
edge[4][0] = 2;
edge[4][1] = 5;
edge[5][0] = 2;
edge[5][1] = 6;
solve(1);
for (int i = 1; i <= n; ++i) {
cout << x[i] << ' ';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |