Submission #537727

# Submission time Handle Problem Language Result Execution time Memory
537727 2022-03-15T12:40:04 Z pokmui9909 Swap (BOI16_swap) C++17
68 / 100
1000 ms 3644 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int N;
int A[200005];
int D[200005];
ll f(int n, int c){
    int l = n * 2, r = n * 2 + 1;
    vector<int> ret, t;
    if(l > N && r > N){
        return n;
    } else if(r > N){
        if(A[l] > c) return n;
        else return l;
    } else if(c < A[l] && c < A[r]){
        return n;
    } else if(A[l] < c && A[l] < A[r]){
        return f(l, c);
    } else if(A[r] < c && A[r] < A[l]){
        ll k = min(c, A[l]);
        ll p = f(l, k), q = f(r, k);
        if(p < q){
            if(k == c) return p;
            else return f(r, c);
        } else {
            if(k == c) return q;
            else return f(l, c);
        }
    }
    return -1;
}
int num = 0;

int main(){
    cin.tie(0) -> sync_with_stdio(false);

    fill(A, A + 200005, 300005);

    cin >> N;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
    }
    for(int i = 1; i <= N; i++){
        int l = i * 2, r = i * 2 + 1;
        if(l > N) continue;
        if(A[i] < A[l] && A[i] < A[r]){
            continue;
        } else if(A[l] < A[i] && A[l] < A[r]){
            swap(A[i], A[l]);
        } else {
            ll k = min(A[i], A[l]), t = max(A[i], A[l]);
            ll p = f(l, k), q = f(r, k);
            A[i] = A[r];
            if(p < q){
                A[l] = k, A[r] = t;
            } else {
                A[l] = t, A[r] = k;
            }
        }
    }
    for(int i = 1; i <= N; i++){
        cout << A[i] << ' ';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1112 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1112 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1112 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1112 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1112 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1112 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1112 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 9 ms 1608 KB Output is correct
17 Correct 10 ms 1656 KB Output is correct
18 Correct 10 ms 1612 KB Output is correct
19 Correct 149 ms 1628 KB Output is correct
20 Correct 142 ms 1764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1112 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1112 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 9 ms 1608 KB Output is correct
17 Correct 10 ms 1656 KB Output is correct
18 Correct 10 ms 1612 KB Output is correct
19 Correct 149 ms 1628 KB Output is correct
20 Correct 142 ms 1764 KB Output is correct
21 Correct 34 ms 3624 KB Output is correct
22 Correct 34 ms 3632 KB Output is correct
23 Correct 36 ms 3644 KB Output is correct
24 Execution timed out 1083 ms 2240 KB Time limit exceeded
25 Halted 0 ms 0 KB -