Submission #240288

# Submission time Handle Problem Language Result Execution time Memory
240288 2020-06-19T06:37:33 Z karma Swap (BOI16_swap) C++14
0 / 100
5 ms 384 KB
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
//#define int         int64_t

using namespace std;

const int N = int(2e5) + 7;
const int logN = 18;
typedef pair<int, int> pii;

int n, a[N];

int Min(int x, int y) {
    int res = n + 1;
    if(x <= n) res = min(res, a[x]);
    if(y <= n) res = min(res, a[y]);
    return res;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    a[n + 1] = n + 1;
    for(int x, y, i = 1; i * 2 <= n; ++i) {
        x = i << 1, y = i << 1 | 1;
        if(a[i] < a[x] && a[i] < a[y]) continue;
        if(a[i] > a[x] && a[i] < a[y]) swap(a[i], a[x]);
        else if(a[i] < a[x] && a[y] < a[i]) {
            if(Min(x << 1, x << 1 | 1) > a[i] ||
              (Min(x << 1, x << 1 | 1) < a[i] && Min(y << 1, y << 1 | 1) < a[x])) swap(a[x], a[i]);
            swap(a[y], a[i]);
        } else if(a[i] > a[y] && a[y] > a[x]) swap(a[x], a[i]);
        else if(a[y] < a[x] && a[x] < a[i]) {
            if(Min(x << 1, x << 1 | 1) < a[x] && Min(y << 1, y << 1 | 1) > a[x]) swap(a[x], a[i]);
            swap(a[y], a[i]);
        }
    }
    for(int i = 1; i <= n; ++i) cout << a[i] << ' ';
}

Compilation message

swap.cpp: In function 'int32_t main()':
swap.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
swap.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -