Submission #537734

# Submission time Handle Problem Language Result Execution time Memory
537734 2022-03-15T12:43:38 Z pokmui9909 Swap (BOI16_swap) C++17
68 / 100
1000 ms 2388 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int N;
int A[200005];
int D[200005];
int 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]){
        int k = min(c, A[l]);
        int 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 {
            int k = min(A[i], A[l]), t = max(A[i], A[l]);
            int 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 980 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 980 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 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 980 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 1108 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 1092 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 980 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 1108 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 1092 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 10 ms 1364 KB Output is correct
17 Correct 9 ms 1364 KB Output is correct
18 Correct 9 ms 1364 KB Output is correct
19 Correct 158 ms 1348 KB Output is correct
20 Correct 141 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 980 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 1108 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 1092 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 10 ms 1364 KB Output is correct
17 Correct 9 ms 1364 KB Output is correct
18 Correct 9 ms 1364 KB Output is correct
19 Correct 158 ms 1348 KB Output is correct
20 Correct 141 ms 1356 KB Output is correct
21 Correct 36 ms 2388 KB Output is correct
22 Correct 36 ms 2324 KB Output is correct
23 Correct 36 ms 2384 KB Output is correct
24 Execution timed out 1096 ms 1108 KB Time limit exceeded
25 Halted 0 ms 0 KB -