Submission #144572

# Submission time Handle Problem Language Result Execution time Memory
144572 2019-08-17T08:37:55 Z SamAnd Zagonetka (COI18_zagonetka) C++17
0 / 100
67 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 102;

int n;
int a[N];

int b[N][N];

int minu[N], maxu[N];

bool stg(int a[], int i)
{
    for (int j = 1; j <= n; ++j)
    {
        if (b[i][j])
        {
            if (b[i][j] == -1 && a[i] > a[j])
                return false;
            if (b[i][j] == 1 && a[i] < a[j])
                return false;
        }
    }
    return true;
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 1; i <= n; ++i)
    {
        for (int j = i + 1; j <= n; ++j)
        {
            swap(a[i], a[j]);
            cout << "query";
            for (int k = 1; k <= n; ++k)
                cout << ' ' << a[k];
            cout << endl;
            swap(a[i], a[j]);
            int x;
            cin >> x;
            if (x == 0)
            {
                if (a[i] < a[j])
                {
                    b[i][j] = -1;
                    b[j][i] = 1;
                }
                if (a[i] > a[j])
                {
                    b[i][j] = 1;
                    b[j][i] = -1;
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i)
        minu[i] = a[i];
    while (1)
    {
        bool z = false;
        for (int i = 1; i <= n; ++i)
        {
            for (int j = i + 1; j <= n; ++j)
            {
                if (minu[i] > minu[j])
                {
                    swap(minu[i], minu[j]);
                    if (stg(minu, i) && stg(minu, j))
                    {
                        z = true;
                        continue;
                    }
                    swap(minu[i], minu[j]);
                }
            }
        }
        if (!z)
            break;
    }
    for (int i = 1; i <= n; ++i)
        maxu[i] = a[i];
    while (1)
    {
        bool z = false;
        for (int i = 1; i <= n; ++i)
        {
            for (int j = i + 1; j <= n; ++j)
            {
                if (maxu[i] < maxu[j])
                {
                    swap(maxu[i], maxu[j]);
                    if (stg(maxu, i) && stg(maxu, j))
                    {
                        z = true;
                        continue;
                    }
                    swap(maxu[i], maxu[j]);
                }
            }
        }
        if (!z)
            break;
    }
    cout << "end" << endl;
    for (int i = 1; i <= n; ++i)
        cout << minu[i] << ' ';
    cout << endl;
    for (int i = 1; i <= n; ++i)
        cout << maxu[i] << ' ';
    cout << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 2 ms 252 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 67 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -