답안 #537728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537728 2022-03-15T12:40:40 Z pokmui9909 Swap (BOI16_swap) C++17
68 / 100
1000 ms 2400 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]){
        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] << ' ';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 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 988 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 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 988 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 988 KB Output is correct
7 Correct 1 ms 988 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 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 988 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 988 KB Output is correct
7 Correct 1 ms 988 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1112 KB Output is correct
15 Correct 1 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 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 988 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 988 KB Output is correct
7 Correct 1 ms 988 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1112 KB Output is correct
15 Correct 1 ms 1112 KB Output is correct
16 Correct 10 ms 1408 KB Output is correct
17 Correct 8 ms 1372 KB Output is correct
18 Correct 9 ms 1368 KB Output is correct
19 Correct 154 ms 1352 KB Output is correct
20 Correct 149 ms 1348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 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 988 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 988 KB Output is correct
7 Correct 1 ms 988 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1112 KB Output is correct
15 Correct 1 ms 1112 KB Output is correct
16 Correct 10 ms 1408 KB Output is correct
17 Correct 8 ms 1372 KB Output is correct
18 Correct 9 ms 1368 KB Output is correct
19 Correct 154 ms 1352 KB Output is correct
20 Correct 149 ms 1348 KB Output is correct
21 Correct 35 ms 2356 KB Output is correct
22 Correct 34 ms 2316 KB Output is correct
23 Correct 34 ms 2400 KB Output is correct
24 Execution timed out 1057 ms 1108 KB Time limit exceeded
25 Halted 0 ms 0 KB -