# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
228015 |
2020-04-29T13:59:58 Z |
farmerboy |
Swap (BOI16_swap) |
C++14 |
|
5 ms |
1920 KB |
/*
Author: Nguyen Tan Bao
Status:
Idea:
*/
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
const ll MODBASE = 1000000007LL;
const int MAXN = 400010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;
int x[MAXN], n;
int getMin(int u) {
return min(x[u], min(x[u*2], x[u*2+1]));
}
II check(int u, int v) {
return II(getMin(u), getMin(v));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
FOR(i,1,400001) x[i] = 1000000000;
cin >> n;
FOR(i,1,n) cin >> x[i];
FOR(i,1,n) {
int a = x[i], b = x[2*i], c = x[2*i+1];
int Min = min(a, min(b, c));
if (a == Min) continue;
if (b == Min) {
swap(x[i], x[2*i]);
continue;
}
// c == Min
swap(x[i], x[2*i+1]);
II u = check(2*i, 2*i+1);
swap(x[2*i], x[2*i+1]);
II v = check(2*i, 2*i+1);
if (u < v) swap(x[2*i], x[2*i+1]);
}
FOR(i,1,n) cout << x[i] << ' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1920 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1920 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1920 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1920 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1920 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1920 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1920 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1920 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1920 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1920 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |