This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << '\n';
#define kill(x) {cout << x << '\n'; return 0;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 1e18, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 450, P = 6065621;
using namespace std;
const ll N = 1e5 + 10, LG = 22;
int a[N], ans[N], b[N];
int main() {
fast_io;
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = a[i];
ans[i] = a[i];
}
for (int mask = 1; mask < (1 << n); mask++) {
for (int i = 1; i <= n; i++) a[i] = b[i];
for (int i = 1; i < n; i++) {
if (mask & (1 << i))
swap(a[i + 1], a[(i + 1) / 2]);
}
int pt = 1;
while (pt <= n && a[pt] == ans[pt]) pt++;
if (pt == n + 1) continue;
if (a[pt] < ans[pt]) {
for (int i = 1; i <= n; i++)
ans[i] = a[i];
}
}
for (int i = 1; i <= n; i++)
cout << ans[i] << ' ';
cout << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |