Submission #933194

# Submission time Handle Problem Language Result Execution time Memory
933194 2024-02-25T08:54:45 Z LucaIlie Swap (BOI16_swap) C++17
48 / 100
3 ms 4188 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1000;
int v[2 * MAX_N + 2], minn[MAX_N + 1], dp[MAX_N + 1][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 = n; i >= 1; i-- ) {
        for ( int x = 1; x <= n; x++ ) {
            if ( x < v[2 * i] && x < v[2 * i + 1] )
                dp[i][x] = i;
            else if ( v[2 * i] < v[2 * i + 1] )
                dp[i][x] = dp[2 * i][x];
            else {
                if ( x < v[2 * i] )  {
                    if ( dp[2 * i][x] < dp[2 * i + 1][x] )
                        dp[i][x] = dp[2 * i][x];
                    else
                        dp[i][x] = dp[2 * i + 1][x];
                }
                else {
                    if ( dp[2 * i][v[2 * i]] < dp[2 * i + 1][v[2 * i]] )
                        dp[i][x] = dp[2 * i + 1][x];
                    else
                        dp[i][x] = dp[2 * i][x];
                }
            }
        }
    }

    for ( int i = 1; 2 * i + 1 <= n; i++ ) {
        if (  v[2 * i] < v[i] && v[2 * i] < v[2 * i + 1] )
            swap( v[i], v[2 * i] );
        else if ( v[2 * i + 1] < v[i] && v[2 * i + 1] < v[2 * i] ) {
            swap( v[i], v[2 * i + 1] );

            if ( v[2 * i] < v[2 * i + 1] ) {
                if ( dp[2 * i][v[2 * i]] > dp[2 * i + 1][v[2 * i]])
                    swap( v[2 * i], v[2 * i + 1] );
            } else {
                if ( dp[2 * i][v[2 * i + 1]] < dp[2 * i + 1][v[2 * i + 1]])
                    swap( v[2 * 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 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 4184 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 4184 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
16 Runtime error 1 ms 600 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 4184 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
16 Runtime error 1 ms 600 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -