Submission #240825

# Submission time Handle Problem Language Result Execution time Memory
240825 2020-06-21T09:00:22 Z kartel Zagonetka (COI18_zagonetka) C++14
27 / 100
86 ms 504 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +200500
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e9)
#define el '\n'
#define pii pair <int, int>
#define err ld(1e-9)
#define last(x) x.back()
#define all(x) (x).begin(), (x).end()
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

vector <int> q, ans[2], p;
int i, n, fst, sd;
bool mrk[N];

bool check(vector <int> &q)
{
    int ch;

    cout << "query";
    for (auto x : q) cout << " " << x;
    cout << endl;

//    ch = (q[fst - 1] < q[sd - 1]);
    cin >> ch;
    return bool(ch);
}

void lower(vector <int> &q)
{
    int i = 0;
    while (i < n && q[i] == ans[0][i]) i++;

    if (i == n || q[i] < ans[0][i]) ans[0] = q;
}

void upper(vector <int> &q)
{
    int i = 0;
    while (i < n && q[i] == ans[1][i]) i++;

    if (i == n || q[i] > ans[1][i]) ans[1] = q;
}

void rec(int k)
{
    if (k == n)
    {
        if (check(q))
        {
            lower(q);
            upper(q);
        }
        return;
    }

    for (int i = 1; i <= n; i++)
        if (!mrk[i])
    {
        mrk[i] = 1;
        q.pb(i);

        rec(k + 1);

        q.pop_back();
        mrk[i] = 0;
    }
}

ifstream in;

int main()
{
    srand(time(0));
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

//    in.open("input.txt");

//    in("input.txt");
//    out("output.txt");

    cin >> n;
    p.resize(n);

    for (i = 0; i < n; i++) cin >> p[i];
//    in >> fst >> fst >> sd;

    ans[0].resize(n);
    ans[1].resize(n);

    i = 0;
    for (i = 0; i < n; i++) ans[0][i] = n - i, ans[1][i] = i + 1;

    if (n <= 6)
        rec(0);
    else
    {
        int kl[705] {0};
        q.resize(n);
        pair <int, int> cond;
        set <pair <int, int> > se;

        for (i = 0; i < n; i++)
           for (int j = i + 1; j < n; j++)
           if (i != j)
        {
            swap(p[i], p[j]);

            if (!check(p))
                    kl[i]++, kl[j]++;

            swap(p[i], p[j]);
        }

        for (i = 0; i < n; i++) se.insert({kl[i], i});

        cond.F = (*se.rbegin()).S;
        se.erase(--se.end());

        while (sz(se))
        {
            cond.S = (*se.rbegin()).S;
            se.erase(--se.end());

            for (i = 0; i < n; i++) q[i] = i + 1;

            if (p[cond.F] > p[cond.S]) swap(cond.F, cond.S);

            if (cond.F > cond.S)
            {
                vector <int> vc;

                reverse(all(q));
                ans[1] = q;
                reverse(all(q));


                for (i = cond.S + 1; i <= cond.F; i++) vc.pb(q[i]);
                vc.pb(q[cond.S]);

                for (i = cond.S; i <= cond.F; i++) q[i] = vc[i - cond.S];
                if (!check(q) || !check(ans[1])) continue;
                ans[0] = q;
                break;
            }
            else
            {
                vector <int> vc;

                ans[0] = q;
                reverse(all(q));


                for (i = cond.F + 1; i <= cond.S; i++) vc.pb(q[i]);
                vc.pb(q[cond.F]);

                for (i = cond.F; i <= cond.S; i++) q[i] = vc[i - cond.F];
                if (!check(q) || !check(ans[0])) continue;
                ans[1] = q;
                break;
            }
        }
    }

    cout << "end" << endl;
    for (auto x : ans[0]) cout << x << " ";
    cout << endl;
    for (auto x : ans[1]) cout << x << " ";
    cout << endl;
}

//2 1
//3 4

//7
//3 2 1 [4 5] 7 6
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 14 ms 384 KB Output is correct
6 Correct 11 ms 384 KB Output is correct
7 Correct 14 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 504 KB Output is correct
2 Correct 28 ms 384 KB Output is correct
3 Correct 38 ms 384 KB Output is correct
4 Correct 41 ms 396 KB Output is correct
5 Correct 15 ms 388 KB Output is correct
6 Correct 36 ms 384 KB Output is correct
7 Correct 10 ms 384 KB Output is correct
8 Correct 10 ms 384 KB Output is correct
9 Correct 30 ms 384 KB Output is correct
10 Correct 22 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -