Submission #933163

# Submission time Handle Problem Language Result Execution time Memory
933163 2024-02-25T07:36:34 Z LucaIlie Swap (BOI16_swap) C++17
0 / 100
1 ms 2396 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2e5;
int v[2 * MAX_N + 2], minn[MAX_N + 1];

int main() {
    int n;

    cin >> n;
    for ( int i = 1; i <= n; i++ )
        cin >> v[i];
    for ( int i = n + 1; i <= 2 * n + 1; i++ )
        v[i] = n + 1;

    for ( int i = 1; i <= n; i++ )
        minn[i] = min( v[i], min( v[2 * i], v[2 * i + 1] ) );

    for ( int i = 1; 2 * i + 1 <= n; i++ ) {
        if ( v[2 * i] == minn[i] )
            swap( v[i], v[2 * i] );
        else if ( v[2 * i + 1] == minn[i] ) {
            if ( min( v[i], v[2 * i] ) < minn[2 * i] ) {
                if ( v[i] < v[2 * i] )
                    swap( v[i], v[2 * i] );
            } else {
                if ( v[2 * i] < v[i] )
                    swap( v[i], v[2 * i] );
            }
            swap( v[i], v[2 * i + 1] );
        }
    }
    if ( v[n / 2] > v[n] )
        swap( v[n / 2], v[n] );

    for ( int i = 1; i <= n; i++ )
        cout << v[i] << " ";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -