Submission #967144

#TimeUsernameProblemLanguageResultExecution timeMemory
967144LukapZagonetka (COI18_zagonetka)C++14
27 / 100
69 ms1232 KiB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 107;

int n;
int niz[MAXN];
vector<int> ind, v, rod[MAXN], djeca[MAXN];
vector<pair<int, int> > pravila;
int preb[MAXN], bio[MAXN], ispis[MAXN];

bool cmp (int a, int b) {
    return niz[a] < niz[b];
}

bool dobro (int x) {
    bio[x] = 1;
    if (preb[x]) return false;

    for (auto nx: rod[x]) {
        if (!bio[nx]) {
            if (!dobro (nx)) return false;
        }
    }
    return true;
}

bool pitaj (int x, int y) {
    int novi_niz[MAXN];

    for (int i = 0; i < n; i++) novi_niz[i] = niz[i];

    for (int i = 0; i < n; i++) preb[i] = 0;
    for (int i = 0; i < n; i++) bio[i] = 0;

    preb[ind[x]] = 1;
    for (int i = x + 1; i < y; i++) {
        if (!dobro (ind[i])) preb[ind[i]] = 1;
    }
    if (!dobro (ind[y])) return true;

    v.clear ();
    for (int i = x; i <= y; i++) {
        if (!preb[ind[i]]) v.push_back (i);
    }
    for (int i = x; i <= y; i++) {
        if (preb[ind[i]]) v.push_back (i);
    }


    for (int i = x; i <= y; i++) novi_niz[ind[v[i - x]]] = i + 1;

    cout << "query ";
    for (int i = 0; i < n; i++) cout << novi_niz[i] << ' ';
    cout << endl;
    int a;
    cin >> a;

    if (a) return true;
    else return false;
}

void gore (int x) {
    bio[x] = 1;
    for (auto nx: rod[x]) {
        if (!bio[nx]) gore (nx);
    }

    v.push_back (x);
}

void dole (int x) {
    bio[x] = 1;
    for (auto nx: djeca[x]) {
        if (!bio[nx]) dole (nx);
    }

    v.push_back (x);
}

int main () {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> niz[i];
    for (int i = 0; i < n; i++) ind.push_back (i);
    sort (ind.begin (), ind.end (), cmp);

    for (int i = 1; i < n; i++) {
        for (int j = i - 1; j >= 0; j--) {
            if (!pitaj (j, i)) {
                pravila.push_back ({ind[j], ind[i]});
                rod[ind[i]].push_back (ind[j]);
                djeca[ind[j]].push_back (ind[i]);
            }
        }
    }
    cout << "end" << endl;

    for (int i = 0; i < n; i++) sort (rod[i].begin (), rod[i].end ());
    v.clear ();
    memset (bio, 0, sizeof (bio));
    for (int i = 0; i < n; i++) {
        if (!bio[i]) gore (i);
    }
    for (int i = 0; i < n; i++) ispis[v[i]] = i + 1;
    for (int i = 0; i < n; i++) cout << ispis[i] << ' ';
    cout << endl;



    for (int i = 0; i < n; i++) sort (djeca[i].begin (), djeca[i].end ());
    v.clear ();
    memset (bio, 0, sizeof (bio));
    for (int i = 0; i < n; i++) {
        if (!bio[i]) dole (i);
    }
    for (int  i = 0; i < n; i++) ispis[v[i]] = n - i;
    for (int i = 0; i < n; i++) cout << ispis[i] << ' ';
    cout << endl;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...