| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 587210 | M_W | Swap (BOI16_swap) | C++17 | 1 ms | 212 KiB |
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 ar array<int, 3>
using namespace std;
int a[200002];
ar find_min(int a, int b, int c){
vector<ar> tmp;
tmp.push_back({a, b, c});
tmp.push_back({b, a, c});
tmp.push_back({c, a, b});
tmp.push_back({c, b, a});
sort(tmp.begin(), tmp.end());
return tmp[0];
}
int main(){
int N;
scanf("%d", &N);
for(int i = 1; i <= N; i++) scanf("%d", &a[i]);
a[N + 1] = INT_MAX;
for(int i = 1; i * 2 <= N; i++){
ar tmp;
if(i * 2 + 1 > N) tmp = find_min(a[i], a[i * 2], max(a[i], a[i * 2]));
else tmp = find_min(a[i], a[i * 2], a[i * 2 + 1]);
int nxt1 = min(a[min(N + 1, (i * 2) * 2)], a[min(N + 1, (i * 2) * 2 + 1)]);
int nxt2 = min(a[min(N + 1, (i * 2 + 1) * 2)], a[min(N + 1, (i * 2 + 1) * 2 + 1)]);
if(tmp[0] == a[i * 2 + 1]){
if(nxt1 < tmp[1] && nxt2 >= tmp[1]) swap(tmp[1], tmp[2]);
}
a[i] = tmp[0]; a[i * 2] = tmp[1];
if(i * 2 + 1 <= N) a[i * 2 + 1] = tmp[2];
}
for(int i = 1; i <= N; i++) printf("%d ", a[i]);
}Compilation message (stderr)
| # | 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... | ||||
