답안 #933170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933170 2024-02-25T07:57:50 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[2 * i], v[2 * i + 1] );

    for ( int i = 1; 2 * i + 1 <= n; i++ ) {
        if ( v[i] < minn[i] )
            continue;

        if ( v[2 * i] == minn[i] )
            swap( v[i], v[2 * i] );
        else if ( v[2 * i + 1] == minn[i] ) {
            if ( v[i] < v[2 * i] ) {
                if ( v[i] < minn[2 * i] || v[i] > minn[2 * i + 1] )
                    swap( v[i], v[2 * i] );
            } else {
                if ( v[2 * i] > minn[2 * i] && v[2 * i] < minn[2 * i + 1] )
                    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -