답안 #144736

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144736 2019-08-17T15:40:14 Z SamAnd Zagonetka (COI18_zagonetka) C++17
27 / 100
85 ms 504 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 102;

int n;
int a[N];

int minu[N], maxu[N];

int ans[N][N];
bool qry(int a[])
{
    cout << "query";
    for (int k = 1; k <= n; ++k)
        cout << ' ' << a[k];
    cout << endl;
    int x;
    cin >> x;
    return x;
}

void endf(int i, int j)
{
    if (a[i] < a[j])
    {
        for (int k = 1; k <= n; ++k)
            minu[k] = k;
        int z = n + 1;
        for (int k = 1; k <= n; ++k)
        {
            if (k == i)
            {
                maxu[j] = --z;
                maxu[k] = --z;
                continue;
            }
            if (k == j)
            {
                continue;
            }
            maxu[k] = --z;
        }
    }
    else
    {
        int z = 0;
        for (int k = 1; k <= n; ++k)
        {
            if (k == i)
            {
                minu[j] = ++z;
                minu[k] = ++z;
                continue;
            }
            if (k == j)
            {
                continue;
            }
            minu[k] = ++z;
        }
        for (int k = 1; k <= n; ++k)
            maxu[k] = n - k + 1;
    }
    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;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    if (n <= 6)
    {
        for (int i = 1; i <= n; ++i)
            minu[i] = maxu[i] = a[i];
        sort(a + 1, a + n + 1);
        do
        {
            if (qry(a))
            {
                for (int i = 1; i <= n; ++i)
                {
                    if (a[i] == minu[i])
                        continue;
                    if (a[i] < minu[i])
                    {
                        for (int j = 1; j <= n; ++j)
                            minu[j] = a[j];
                    }
                    break;
                }
                for (int i = 1; i <= n; ++i)
                {
                    if (a[i] == maxu[i])
                        continue;
                    if (a[i] > maxu[i])
                    {
                        for (int j = 1; j <= n; ++j)
                            maxu[j] = a[j];
                    }
                    break;
                }
            }
        } while (next_permutation(a + 1, a + n + 1));
        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;
    }
    else
    {
        for (int i = 1; i <= n; ++i)
        {
            for (int j = i + 1; j <= n; ++j)
            {
                swap(a[i], a[j]);
                ans[i][j] = qry(a);
                swap(a[i], a[j]);
            }
        }
        for (int ii = 1; ii <= n; ++ii)
        {
            for (int jj = 1; jj <= n; ++jj)
            {
                if (ii == jj)
                    continue;
                bool z = true;
                for (int i = 1; i <= n; ++i)
                {
                    for (int j = i + 1; j <= n; ++j)
                    {
                        swap(a[i], a[j]);
                        if ((a[ii] < a[jj] && ans[i][j] == 0) || (a[ii] > a[jj] && ans[i][j] == 1))
                        {
                            z = false;
                            swap(a[i], a[j]);
                            break;
                        }
                        swap(a[i], a[j]);
                    }
                    if (z == false)
                        break;
                }
                if (z)
                {
                    if (ii > jj)
                        swap(ii, jj);
                    endf(ii, jj);
                    return 0;
                }
            }
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 3 ms 248 KB Output is correct
4 Correct 3 ms 420 KB Output is correct
5 Correct 9 ms 376 KB Output is correct
6 Correct 9 ms 376 KB Output is correct
7 Correct 12 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 328 KB Output is correct
2 Correct 22 ms 396 KB Output is correct
3 Correct 33 ms 400 KB Output is correct
4 Correct 30 ms 404 KB Output is correct
5 Correct 12 ms 248 KB Output is correct
6 Correct 43 ms 448 KB Output is correct
7 Correct 8 ms 248 KB Output is correct
8 Correct 8 ms 320 KB Output is correct
9 Correct 36 ms 336 KB Output is correct
10 Correct 19 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 320 KB Unexpected end of file - token expecte
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 85 ms 468 KB Unexpected end of file - token expecte
2 Halted 0 ms 0 KB -