답안 #199039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199039 2020-01-28T18:09:38 Z stefdasca Swap (BOI16_swap) C++14
0 / 100
5 ms 424 KB
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

// #define fisier 1

using namespace std;

typedef long long ll;

int n, v[200002];
int mn(int a, int b)
{
    int va = n+1;
    if(a > n)
        va = min(va, n+1);
    else
        va = min(va, v[a]);
    if(b > n)
        va = min(va, n+1);
    else
        va = min(va, v[b]);
    return va;
}
int main()
{

    #ifdef fisier
        ifstream f("input.in");
        ofstream g("output.out");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    v[n+1] = n+1;
    for(int i = 1; i + i <= n; ++i)
    {
        if(v[i] < v[i+i] && v[i] < v[i+i+1])
            continue;
        if(v[i+i] < v[i] && v[i] < v[i+i+1])
            swap(v[i], v[i+i]);
        else
            if(v[i+i+1] < v[i] && v[i] < v[i+i])
            {
                if(mn(i*4, i*4+1) > v[i] || (mn(i*4, i*4+1) < v[i] && mn((i+i+1)*2, (i+i+1)*2+1) < v[i+i]))
                    swap(v[i], v[i+i]);
                swap(v[i+i+1], v[i]);
            }
            else
                if(v[i+i] < v[i+i+1] && v[i+i+1] < v[i])
                    swap(v[i], v[i+i]);
                else
                    if(v[i+i+1] < v[i+i] && v[i+i] < v[i])
                    {
                        if(mn(i*4, i*4+1) < v[i+i] && mn((i+i+1)*2, (i+i+1)*2+1) > v[i+i])
                            swap(v[i], v[i+i]);
                        swap(v[i+i+1], v[i]);
                    }
        //for(int j = 1; j <= n; ++j)
        //    cout << v[j] << " ";
        //cout << '\n';
    }
    for(int i = 1; i <= n; ++i)
        cout << v[i] << " ";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 424 KB Output is correct
4 Incorrect 5 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 424 KB Output is correct
4 Incorrect 5 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 424 KB Output is correct
4 Incorrect 5 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 424 KB Output is correct
4 Incorrect 5 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 424 KB Output is correct
4 Incorrect 5 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -